<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/OBJECTTABLE">OBJECTTABLE</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >*teiid_script* <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >teiid_script is a simple scripting expression language that allows access to passing and special variables as well as any non-void 0-argument methods on <span class="diff-changed-words">objects<span class="diff-added-chars"style="background-color: #dfd;"> and indexed values on arrays/lists</span>.</span>  A teiid_script expression begins by referencing the passing or special variable.  Then any number of <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">.method</span> <span class="diff-added-words"style="background-color: #dfd;">&#39;.&#39;</span> accessors may be chained to evaluate the expression to a different value.  Methods may be accessed by their property names, for example foo rather than getFoo.  If the object both a {{getFoo()}} and {{foo()}} method, then the accessor foo references {{foo()}} and getFoo should be used to call the getter. <span class="diff-added-words"style="background-color: #dfd;"> An array or list index may be accessed using a 1-based positive integral value - using the same &#39;.&#39; accessor syntax.  The same logic as the system function array_get is used meaning that null will be returned rather than exception if the index is out of bounds.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >teiid_script is effectively dynamically typed as typing is performed at runtime.  If a accessor does not exist on the object or if the method is not accessible, then an exception will be raised. <span class="diff-added-words"style="background-color: #dfd;"> If at any point in the accessor chain evaluates to a null value, then null will be returned.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Examples <br> <br>* To get the VDB description string: {code}teiid_context.session.vdb.description{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* To get the first character of the VDB description string: {code}teiid_context.session.vdb.description.toCharArray.1{code} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The OBJECTTABLE function processes an object input to produce tabular output. The function itself defines what columns it projects. The OBJECTTABLE function is implicitly a nested table and may be correlated to preceding FROM clause entries.</p>

<p>Usage:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
OBJECTTABLE([LANGUAGE lang] rowScript [PASSING val AS name ...] COLUMNS colName colType colScript [DEFAULT defaultExpr] ...) AS id</pre>
</div></div>

<p>Parameters</p>

<ul>
        <li>lang - an optional string literal that is the case sensitive language name of the scripts to be processed.  The script engine must be available via a JSR-223 ScriptEngineManager lookup.  In some instances this may mean making additional modules available to your vdb, which can be done via the same process as adding modules/libraries <a href="/author/display/TEIID/Support+for+User-Defined+Functions+%28Non-Pushdown%29" title="Support for User-Defined Functions (Non-Pushdown)">for UDFs</a>.  If a LANGUAGE is not specified, the default of 'teiid_script' (see below) will be used.</li>
        <li>name - an identifier that will bind the val expression value into the script context.</li>
        <li>rowScript is a string literal specifying the script to create the row values.<br/>
for each non-null item the Iterator produces the columns will be evaluated.</li>
        <li>colName/colType are the id/data type of the column, which can optionally be defaulted with the DEFAULT clause expression defaultExpr.</li>
        <li>colScript is a string literal specifying the script that evaluates to the column value.</li>
</ul>


<p>Syntax Rules:</p>

<ul>
        <li>The columns names must be not contain duplicates.</li>
        <li>Teiid will place several special variables in the script execution context. The CommandContext is available as teiid_context. Additionally the colScripts may access teiid_row and teiid_row_number.&nbsp; teiid_row is the current row object produced by the row script.&nbsp; teiid_row_number is the current 1-based row number.</li>
        <li>rowScript is evaluated to an Iterator.  If the results is already an Iterator, it is used directly.  If the evaluation result is an Iteratable, then an Iterator will be obtained.  Any other Object will be treated as an Iterator of a single item).  In all cases null row values will be skipped.</li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>While there is no restriction what can be used as a PASSING variable names you should choose names that can be referenced as identifiers in the target language.</td></tr></table></div>

<p>Examples</p>

<ul>
        <li>Accessing special variables:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">SELECT x.* FROM OBJECTTABLE('teiid_context' COLUMNS "user" string 'teiid_row.userName', row_number integer 'teiid_row_number') AS x</pre>
</div></div>
<p>The result would be a row with two columns containing the user name and 1 respectively.</p></li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Due to their mostly unrestricted access to Java functionality, usage of languages other than teiid_script is restricted by default.  A VDB must declare all allowable languages by name in the allowed-languages <a href="/author/display/TEIID/VDB+Definition" title="VDB Definition">VDB property</a> using a comma separated list.&nbsp; The names are case sensitive names and should be separated without whitespace.&nbsp; Without this property it is not possible to use OBJECTTABLE even from within view definitions that are not subject to normal permission checks.</td></tr></table></div>

<p>Data roles are also secured with <a href="/author/display/TEIID/XML+Definition" title="XML Definition">Data Roles</a> using the <a href="/author/display/TEIID/Permissions" title="Permissions">language permission</a>.</p>

<p><b>teiid_script</b></p>

<p>teiid_script is a simple scripting expression language that allows access to passing and special variables as well as any non-void 0-argument methods on objects and indexed values on arrays/lists.  A teiid_script expression begins by referencing the passing or special variable.  Then any number of '.' accessors may be chained to evaluate the expression to a different value.  Methods may be accessed by their property names, for example foo rather than getFoo.  If the object both a <tt>getFoo()</tt> and <tt>foo()</tt> method, then the accessor foo references <tt>foo()</tt> and getFoo should be used to call the getter.  An array or list index may be accessed using a 1-based positive integral value - using the same '.' accessor syntax.  The same logic as the system function array_get is used meaning that null will be returned rather than exception if the index is out of bounds.</p>

<p>teiid_script is effectively dynamically typed as typing is performed at runtime.  If a accessor does not exist on the object or if the method is not accessible, then an exception will be raised.  If at any point in the accessor chain evaluates to a null value, then null will be returned.</p>

<p>Examples</p>

<ul>
        <li>To get the VDB description string: <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">teiid_context.session.vdb.description</pre>
</div></div></li>
        <li>To get the first character of the VDB description string: <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">teiid_context.session.vdb.description.toCharArray.1</pre>
</div></div></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/OBJECTTABLE">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=53379645&revisedVersion=10&originalVersion=9">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/OBJECTTABLE?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>