1 grid.select
Release 2017.3
Tag available since version 2017.3.
grid.select tag allow to execute a query in a multiple databases and returns a single result set with the rows that satisfy the specified search criteria.
<grid.select
name='name'
timeout='timeout'
>
<arguments> *
</grid.select>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Grid name where the query will be executed. | |||
Atimeout | integer | The timeout before cancel the executed query for each database. If it is not specified timeout applied is getted from the definition on database connection group. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Varguments | The arguments allowed in this context are the arguments for tag select. |
Returns | |
---|---|
Type | Description |
JDBCGridSelectResult | Returns a memory resultset with the rows that satisfy the specified search criteria on each database of the grid. The result includes two additional columns that are the database where the query was executed and error messages if exists. |
The returned JDBCGridSelectResult contains an extra column
_node
with the data source foreach row.
It can also be used to get additional information like result accuracy, exceptions, etc.
Example
Copy
<xsql-script> <body> <set name='rs'> <grid.select name='grid1' timeout='30'> <select> <columns>tabname, nrows, npused</columns> <from table='systables' /> <where>tabname LIKE 'capuntes%'</where> </select> </grid.select> </set> <!-- Print resultset data --> <println> <rs /> </println> </body> </xsql-script>
+--------+-----------+----------+--------------+
|tabname |nrows |npused |_node |
|varchar |float |float |char |
|visible |visible |visible |visible |
+--------+-----------+----------+--------------+
|capuntes|4557443.000|955229.000|demo_cons |
|capuntes| 442028.000| 89265.000|demo_industria|
|capuntes| 7889.000| 1604.000|demo_sports |
+--------+-----------+----------+--------------+
Example
A sample using grid tag library.
Copy
<xsql-script> <body> <set name='gr'> <grid.select name='gridtpch_test' timeout='30' temp='true'> <select> <columns>SUM(l_quantity) l_quantity, MAX(l_discount) l_discount</columns> <from table='lineitem' /> </select> </grid.select> </set> <if> <expr> <!-- Check if result has at least data from one node --> <grid.result.hasData> <gr /> </grid.result.hasData> </expr> <then> <println>=============================================</println> <println>Print full resultset obtained from data nodes</println> <println>=============================================</println> <println> <grid.result.toResultSet> <gr /> </grid.result.toResultSet> </println> <!-- Obtain temp table name and execute coordinator agreggate SQL Statement --> <!-- to get final result --> <set name='m_temptabname'> <grid.result.getTempTable> <gr /> </grid.result.getTempTable> </set> <println>=============================================</println> <println>Generated temp table <m_temptabname /></println> <println>=============================================</println> <println>Aggregate Final Results</println> <println>=============================================</println> <println> <sql.toResultSet> <select> <columns> SUM(l_quantity) l_quantity, MAX(l_discount) l_discount</columns> <from table="${m_temptabname}" /> </select> </sql.toResultSet> </println> <!-- Print resultset accuracy. Should be 1.0 if all nodes are working --> <println>=============================================</println> <println>Accuracy: <grid.result.getAccuracy><gr /></grid.result.getAccuracy></println> <println>=============================================</println> <println><string /></println> <println>=============================================</println> <println>Show node statistics</println> <println>=============================================</println> <println> <grid.result.getStatistics> <gr /> </grid.result.getStatistics> </println> <!-- Print any exception on node if present --> <if> <expr> <grid.result.hasExceptions> <gr /> </grid.result.hasExceptions> </expr> <then> <println> <grid.result.getExceptions> <gr /> </grid.result.getExceptions> </println> </then> </if> </then> <else> <println>=============================================</println> <println>No data found. Show exceptions</println> <println>=============================================</println> <println> <grid.result.getExceptions><gr /></grid.result.getExceptions> </println> </else> </if> </body> </xsql-script>
+--------+-----------+----------+--------------+
|tabname |nrows |npused |_node |
|varchar |float |float |char |
|visible |visible |visible |visible |
+--------+-----------+----------+--------------+
|capuntes|4557443.000|955229.000|demo_cons |
|capuntes| 442028.000| 89265.000|demo_industria|
|capuntes| 7889.000| 1604.000|demo_sports |
+--------+-----------+----------+--------------+
1.0