teiid SVN: r2493 - in branches/7.1.x: build/kits/jboss-container/deploy/teiid and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-26 12:01:31 -0400 (Thu, 26 Aug 2010)
New Revision: 2493
Modified:
branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
Log:
TEIID-1220 changing data role checking to be enabled by default, but to only check against vdbs with data roles
Modified: branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-08-26 15:29:47 UTC (rev 2492)
+++ branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-08-26 16:01:31 UTC (rev 2493)
@@ -91,14 +91,14 @@
<property name="timeSliceInMilli">2000</property>
<!-- Maximum allowed fetch size, set via JDBC. User requested value ignored above this value. (default 20480) -->
<property name="maxRowsFetchSize">20480</property>
- <!-- The max lob chunk size in KB transferred each time when processing blobs, clobs(100KB default) -->
+ <!-- The max lob chunk size in KB transferred each time when processing blobs, clobs (100KB default) -->
<property name="lobChunkSizeInKB">100</property>
<!-- The maximum number of query plans that are cached.
This includes both user plans and internal prepared plans.
Note: this is a memory based cache. (default 512) -->
<property name="preparedPlanCacheMaxCount">512</property>
- <!-- Turn on role checking on resources based on the roles defined in VDB -->
- <property name="useDataRoles" class="java.lang.Boolean">false</property>
+ <!-- Turn on role checking of resources based on the roles defined in VDB (default true) -->
+ <property name="useDataRoles" class="java.lang.Boolean">true</property>
<!-- Long running query threshold, after which a alert can be generated by tooling if configured-->
<property name="queryThresholdInSecs">600</property>
<!-- Maximum rows allowed from a source query. -1 indicates no limit. (default -1)-->
Modified: branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-26 15:29:47 UTC (rev 2492)
+++ branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-26 16:01:31 UTC (rev 2493)
@@ -67,6 +67,7 @@
<h4>from 7.1</h4>
<ul>
+ <li>The default for data role checking is now "true". However only VDBs with data roles will have roles enforced.
<li>The default prepared plan cache size was increased to 512, since it is targeted by internal plans as well.
</ul>
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-26 15:29:47 UTC (rev 2492)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-26 16:01:31 UTC (rev 2493)
@@ -153,7 +153,7 @@
this.workContext = workContext;
this.requestId = workContext.getRequestID(this.requestMsg.getExecutionId());
this.connectorManagerRepo = workContext.getVDB().getAttachment(ConnectorManagerRepository.class);
- this.useEntitlements = useEntitlements;
+ this.useEntitlements = useEntitlements && !workContext.getVDB().getDataPolicies().isEmpty();
this.planCache = planCache;
}
14 years, 4 months
teiid SVN: r2492 - in branches/7.1.x: cache-jbosscache/src/main/java/org/teiid/cache/jboss and 11 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-26 11:29:47 -0400 (Thu, 26 Aug 2010)
New Revision: 2492
Added:
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/results.xml
Removed:
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/cachehint.xml
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/resultset.xml
Modified:
branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ClusterableCacheFactory.java
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml
branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/main.xml
branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java
branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCacheFactory.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-1213 adding procedure result caching
Modified: branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-26 15:29:47 UTC (rev 2492)
@@ -26,6 +26,7 @@
</UL>
<H2><A NAME="Highlights"></A>Highlights</H2>
<UL>
+ <LI><B>Procedure Result Caching</B> - virtual procedure definitions may use a cache hint to cache results in the result set cache.
<LI><B>Improved Plan Caching</B> - plans used by internal materialization and stored procedure plans will be automatically cached in the prepared plan cache. Improvements were also made to reduce the memory footprint of the plans.
<LI><B>Refined Load Balancing and Fail Over</B> - clients can use use the statement "SET NEWINSTANCE TRUE" to allow their connection to select a new server instance. See the Client Developer's Guide for more information.
</UL>
Modified: branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ClusterableCacheFactory.java
===================================================================
--- branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ClusterableCacheFactory.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/ClusterableCacheFactory.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -45,7 +45,7 @@
if (this.delegate == null) {
Object cacheManager = getClusteredCache();
if (cacheManager == null) {
- this.delegate = new DefaultCacheFactory();
+ this.delegate = new DefaultCacheFactory(config);
}
else {
try {
Deleted: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/cachehint.xml
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/cachehint.xml 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/cachehint.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -1,88 +0,0 @@
-<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
-<!ENTITY % CustomDTD SYSTEM "../../../../../../docbook/custom.dtd">
-%CustomDTD;
-]>
-<chapter id="cache-hint">
- <title>Cache Hint</title>
- <para>A cache hint can be used to:</para>
- <itemizedlist>
- <listitem><para>Indicate that a user query is eligible for result set caching.
- </para></listitem>
- <listitem><para>Set the result set query cache entry memory preference or time to live.
- </para></listitem>
- <listitem><para>Set the materialized view memory preference, time to live, or updatablity.
- </para></listitem>
- </itemizedlist>
- <para><synopsis>/*+ cache[([pref_mem] [ttl:n] [updatable])] */</synopsis>
- <itemizedlist>
- <listitem><para><emphasis>pref_mem</emphasis> - if present indicates that the cached results should prefer to remain in memory. They are not however required to be memory only.
- </para></listitem>
- <listitem><para><emphasis>ttl:n</emphasis> - if present n indicates the time to live value in milliseconds.
- </para></listitem>
- <listitem><para><emphasis>updatable</emphasis> - if present indicates that the cached results can be updated.
- </para></listitem>
- </itemizedlist>
- </para>
- <section>
- <title>ResultSet Cache Query</title>
- <para>The most basic form of the cache hint, <code>/*+ cache */</code>, is sufficient to inform the engine that the results of the non-update command should be cached.</para>
- <example>
- <title>PreparedStatement ResultSet Caching</title>
- <programlisting>...
-PreparedStatement ps = connection.prepareStatement("/*+ cache */ select col from t where col2 = ?");
-ps.setInt(1, 5);
-ps.execute();
-...</programlisting>
- <para>While no options are specified with the cache hint, it still informs the engine to use ResultSet caching.</para>
- </example>
- <para>The pref_mem and ttl options may also be used for ResultSet cache queries, however updatable only has an effect on materialized view tables.</para>
- <example>
- <title>Advanced ResultSet Caching</title>
- <programlisting>/*+ cache(pref_mem ttl:60000 */ select col from t</programlisting>
- <para>In this example the memory preference has been enabled and the time to live is set to 60000 milliseconds or 1 minute.
- The ttl for an entry is actually treated as it's maximum age and the entry may be purged sooner if the maximum number of cache entries has been reached.</para>
- </example>
- <para>See the <link linkend="resultset">ResultSet Caching Chapter</link> for more.</para>
- </section>
- <section>
- <title>Materialized Views</title>
- <para>The cache hint, when used in the context of an internal materialized view transformation query, provides the ability to fine tune the materializated table.
- The hint is not used for materialization targeted at an external source. See the <link linkend="resultset">Materialized View Chapter</link> for more on materialized views.</para>
- <para>The pref_mem option also applies to internal materialized views. Internal table index pages already have a memory preference, so the perf_mem option indicates that the data pages should prefer memory as well.</para>
- <section>
- <title>TTL Snapshot Refresh</title>
- <para>When the ttl is specified in the cache hint, a full refresh of the materialized view will be triggered automatically after the specified time interval.
- The refresh is equivalent to <code>CALL SYS.refreshMatView('view name', false)</code>, but performed asynchronously so that user queries do not block on the load.
- </para>
- <section>
- <title>Limitations</title>
- <itemizedlist>
- <listitem><para>The automatic ttl refresh is not intended for complex loading scenarios, as nested materialized views will be used by the refresh query.
- </para></listitem>
- <listitem><para>The automatic ttl refresh is performed lazily, that is it is only trigger by using the table after the ttl has expired.
- For infrequently used tables with long load times, this means that data may be used well past the intended ttl.
- </para></listitem>
- </itemizedlist>
- </section>
- </section>
- <section>
- <title>Updatable</title>
- <para>When the updatable option is specified, the materialized view may be targeted by the system function <code>refreshMatViewRow</code>.
- The refreshMatViewRow function updates a single row of an internal materialized with the supplied key value.
- The refresh query does use nested caches, so this refresh method should be used with caution.
- </para>
- <para>When the updatable option is not specified, accessing the materialized view table is more efficient because modifications do not need to be considered.
- Therefore, only specify the updatable option if row based incremental updates are needed. Even when performing row updates, full snapshot refreshes may be needed to ensure consistency.</para>
- </section>
- </section>
- <section>
- <title>Limitations</title>
- <itemizedlist>
- <listitem><para>The form of the query hint must be matched exactly for the hint to have affect.
- For a user query if the hint is not specified correctly, e.g. /*+ cach(pref_mem) */, it will not be used by the engine nor will
- there be an informational log. As a workaround, the query plan may be checked though (see the Client Developers Guide) to see if the user command
- in the plan has retained the proper hint.
- </para></listitem>
- </itemizedlist>
- </section>
-</chapter>
\ No newline at end of file
Copied: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml (from rev 2478, branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/cachehint.xml)
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml (rev 0)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -0,0 +1,60 @@
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!ENTITY % CustomDTD SYSTEM "../../../../../../docbook/custom.dtd">
+%CustomDTD;
+]>
+<chapter id="cache-hint-options">
+ <title>Hints and Options</title>
+ <section id="cache-hint">
+ <title>Cache Hint</title>
+ <para>A query cache hint can be used to:</para>
+ <itemizedlist>
+ <listitem><para>Indicate that a user query is eligible for result set caching and set the cache entry memory preference or time to live.
+ </para></listitem>
+ <listitem><para>Set the materialized view memory preference, time to live, or updatablity.
+ </para></listitem>
+ <listitem><para>Indicate that a virtual procedure should be cachable and set the cache entry memory preference or time to live.
+ </para></listitem>
+ </itemizedlist>
+ <para><synopsis>/*+ cache[([pref_mem] [ttl:n] [updatable])] */ sql ...</synopsis>
+ <itemizedlist>
+ <listitem><para>The cache hint should appear at the beginning of the SQL. It will not have any affect on INSERT/UPDATE/DELETE statements or virtual update procedure definitions.</para></listitem>
+ <listitem><para><emphasis>pref_mem</emphasis> - if present indicates that the cached results should prefer to remain in memory. They are not however required to be memory only.
+ </para></listitem>
+ <listitem><para><emphasis>ttl:n</emphasis> - if present n indicates the time to live value in milliseconds.
+ </para></listitem>
+ <listitem><para><emphasis>updatable</emphasis> - if present indicates that the cached results can be updated. This is currently only applicable to materialized views.
+ </para></listitem>
+ </itemizedlist>
+ </para>
+ <section>
+ <title>Limitations</title>
+ <itemizedlist>
+ <listitem><para>The form of the query hint must be matched exactly for the hint to have affect.
+ For a user query if the hint is not specified correctly, e.g. <code>/*+ cach(pref_mem) */</code>, it will not be used by the engine nor will
+ there be an informational log. As a workaround, the query plan may be checked though (see the Client Developers Guide) to see if the user command
+ in the plan has retained the proper hint.
+ </para></listitem>
+ </itemizedlist>
+ </section>
+ </section>
+ <section id="nocache">
+ <title>OPTION NOCACHE</title>
+ <para>Individual queries may override the use of cached results by
+ specifying <code>OPTION NOCACHE</code> on the query. 0 or more fully qualified view or procedure names may be specified to exclude using their cached results.
+ If no names are specified, cached results will not be used transitively.
+ </para>
+ <example>
+ <title>Full NOCACHE</title>
+ <programlisting>SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE</programlisting>
+ <para>No cached results will be used at all.</para>
+ </example>
+ <example>
+ <title>Specific NOCACHE</title>
+ <programlisting>SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3</programlisting>
+ <para>Only the vg1 and vg3 caches will be skipped, vg2 or any cached results nested under vg1 and vg3 will be used.</para>
+ </example>
+ <para><code>OPTION NOCACHE</code> may be specified in procedure or view definitions. In that way, transformations can
+ specify to always use real-time data obtained directly from sources.
+ </para>
+ </section>
+</chapter>
\ No newline at end of file
Property changes on: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/matviews.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -27,35 +27,14 @@
</listitem>
<listitem>
<para>User ability to override use of materialized view cache for
- specific queries through OPTION NO CACHE</para>
+ specific queries through <code>OPTION NOCACHE</code></para>
</listitem>
</itemizedlist>
</section>
<section>
<title>User Interaction</title>
- <para>When client applications issue queries against a Relational
- table or view that has been defined as a materialized view, the
- Teiid query engine automatically routes that query to obtain the
- results from the cache database.</para>
- <para>Individual queries may override the use of materialized views by
- specifying OPTION NOCACHE on the query. This parameter may specify
- one or more virtual groups to override (separated by commas, spaces
- optional). If no virtual groups are specified, materialized views tables will not be used transitively.
- </para>
- <example>
- <title>Full NOCACHE</title>
- <programlisting>SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE</programlisting>
- </example>
- <example>
- <title>Specific NOCACHE</title>
- <programlisting>SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3</programlisting>
- <para>Only the vg1 and vg3 caches will be skipped vg2 or any materialized views nested under vg1 and vg3 will be used.</para>
- </example>
- <para>Option NOCACHE may be specified in virtual
- group transformation queries. In that way, transformations can
- specify to always use real-time data obtained directly from a source.
- The use of caching and non-caching can be mixed in transformation
- definitions, just as with user queries.</para>
+ <para>Similar to cached procedures, materialized view tables are used automatically when a query accesses the corresponding view.
+ Usage of the cached results may be bypassed with an <code>OPTION NOCACHE</code> clause. See the <link linkend="nocache">OPTION NOCACHE</link> section for more on its usage.</para>
</section>
<section>
<title>Materialized View Definition</title>
@@ -77,6 +56,9 @@
</listitem>
</itemizedlist>
</para>
+ <note><para>Materialized view tables are always scoped to the VDB. If a materialized view definition directly or transitively contains a non-deterministic
+ function call, such as random or hasRole, the resulting table will contain only the initially evaluated values. In most instances you should consider
+ nesting a materialized view without the deterministic results that is joined with relevant non-deterministic values in a parent view.</para></note>
</section>
<section>
<title>External Materialization</title>
@@ -112,6 +94,7 @@
<para>Internal materialization creates Teiid temporary tables to hold the materialized table. While these tables are not fully durable, they perform
well in most circumstances and the data is present at each Teiid instance which removes the single point of failure and network overhead of an external database.
Internal materialization also provides more built-in facilities for refreshing and monitoring.</para>
+ <para>The cache hint, when used in the context of an internal materialized view transformation query, provides the ability to fine tune the materializated table. The pref_mem option also applies to internal materialized views. Internal table index pages already have a memory preference, so the perf_mem option indicates that the data pages should prefer memory as well.</para>
<section>
<title>Loading And Refreshing</title>
<para>An internal materialized view table is initially in an invalid state (there is no data). The first user query will trigger an implicit loading of the data.
@@ -128,27 +111,47 @@
subsequent refreshes performed with <code>refreshMatView</code> will use dependent materialized view tables if they exist. Only one load may occur at a time. If a load is already in progress when
the <code>SYS.refreshMatView</code> procedure is called, it will return -1 immediately rather than preempting the current load.
</para>
- <para>The <link linkend="cache-hint">cache hint</link> may be used to automatically trigger a full snapshot refresh after a specified time to live.
- <example>
- <title>Auto-refresh Transformation Query</title>
- <programlisting>/*+ cache(ttl:3600000) */ select t.col, t1.col from t, t1 where t.id = t1.id</programlisting>
- </example>
- </para>
- <para>In advanced use-cases the <link linkend="cache-hint">cache hint</link> may also be used to mark an internal materialized view as updatable.
- An updatable internal materialized view may use the <code>SYS.refreshMatViewRow</code> procedure to update a single row in the materialized table.
- To be updatable the materialized view must have a single column primary key. Composite keys are not yet supported by <code>SYS.refreshMatViewRow</code>.
- <example>
- <title>Updatable Scenario</title>
- <para>Transofrmation Query: <programlisting>/*+ cache(updatable) */ select t.col, t1.col from t, t1 where t.id = t1.id</programlisting></para>
- <para>Update: <programlisting>CALL SYS.updateMatViewRow(viewname=>'schema.matview', key=>5)</programlisting></para>
- <para>Given that the schema.matview defines interger column col as it's primary key, the update will check the live source(s) for the row values.
- If it exists, the materialized view table row will be updated. If it does not exist the correpsonding row will be deleted.</para>
- </example>
- The update query will not use dependent materialized view tables, so care should be taken to ensure that getting a single
- row from this transformation query performs well. This may require the use of depedent join hints.
- When the updatable option is not specified, accessing the materialized view table is more efficient because modifications do not need to be considered.
- Therefore, only specify the updatable option if row based incremental updates are needed. Even when performing row updates, full snapshot refreshes may be needed to ensure consistency.
- </para>
+ <section>
+ <title>TTL Snapshot Refresh</title>
+ <para>The <link linkend="cache-hint">cache hint</link> may be used to automatically trigger a full snapshot refresh after a specified time to live.
+ The refresh is equivalent to <code>CALL SYS.refreshMatView('view name', false)</code>, but performed asynchronously so that user queries do not block on the load.</para>
+ <example>
+ <title>Auto-refresh Transformation Query</title>
+ <programlisting>/*+ cache(ttl:3600000) */ select t.col, t1.col from t, t1 where t.id = t1.id</programlisting>
+ <para>The resulting materialized view will be reloaded every hour (3600000 milliseconds).</para>
+ </example>
+ <section>
+ <title>Limitations</title>
+ <itemizedlist>
+ <listitem><para>The automatic ttl refresh is not intended for complex loading scenarios, as nested materialized views will be used by the refresh query.
+ </para></listitem>
+ <listitem><para>The automatic ttl refresh is performed lazily, that is it is only trigger by using the table after the ttl has expired.
+ For infrequently used tables with long load times, this means that data may be used well past the intended ttl.
+ </para></listitem>
+ </itemizedlist>
+ </section>
+ </section>
+ <section>
+ <title>Updatable</title>
+ <para>In advanced use-cases the <link linkend="cache-hint">cache hint</link> may also be used to mark an internal materialized view as updatable.
+ An updatable internal materialized view may use the <code>SYS.refreshMatViewRow</code> procedure to update a single row in the materialized table.
+ If the source row exists, the materialized view table row will be updated. If the source row does not exist, the correpsonding materialized row will be deleted.
+ To be updatable the materialized view must have a single column primary key. Composite keys are not yet supported by <code>SYS.refreshMatViewRow</code>.
+ <example>
+ <title>Updatable Transformation Query</title>
+ <para>Transofrmation Query: <programlisting>/*+ cache(updatable) */ select t.col, t1.col from t, t1 where t.id = t1.id</programlisting></para>
+ <para>Update SQL: <programlisting>CALL SYS.updateMatViewRow(viewname=>'schema.matview', key=>5)</programlisting></para>
+ <para>Given that the schema.matview defines an interger column col as it's primary key, the update will check the live source(s) for the row values.</para>
+ </example>
+ The update query will not use dependent materialized view tables, so care should be taken to ensure that getting a single
+ row from this transformation query performs well. See the Reference Guide for information on controlling dependent joins, which may be applicable to increasing the performance of retrieving a single row.
+ The refresh query does use nested caches, so this refresh method should be used with caution.
+ </para>
+ <para>
+ When the updatable option is not specified, accessing the materialized view table is more efficient because modifications do not need to be considered.
+ Therefore, only specify the updatable option if row based incremental updates are needed. Even when performing row updates, full snapshot refreshes may be needed to ensure consistency.
+ </para>
+ </section>
</section>
<section>
<title>Limitations</title>
@@ -157,4 +160,4 @@
</itemizedlist>
</section>
</section>
-</chapter>
\ No newline at end of file
+</chapter>
Copied: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/results.xml (from rev 2478, branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/resultset.xml)
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/results.xml (rev 0)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/results.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -0,0 +1,138 @@
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!ENTITY % CustomDTD SYSTEM "../../../../../../docbook/custom.dtd">
+%CustomDTD;
+]>
+<chapter id="results">
+ <title>Results Caching</title>
+ <para>Teiid provides the capability to cache the results of
+ specific user queries and virtual procedure calls. This caching technique
+ can yield significant performance gains if users of the system submit
+ the same queries or execute the same procedures often.</para>
+ <section>
+ <title>Support Summary</title>
+ <itemizedlist>
+ <listitem>
+ <para>Caching of user query results including XML document model results.</para>
+ </listitem>
+ <listitem>
+ <para>Caching of virtual procedure results.</para>
+ </listitem>
+ <listitem>
+ <para>Scoping of results is automatically determined to be VDB/user (replicated) or session level.</para>
+ </listitem>
+ <listitem>
+ <para>Configurable number of cache entries and time to live.</para>
+ </listitem>
+ <listitem>
+ <para>Administrative clearing.</para>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section>
+ <title>User Interaction</title>
+ <section>
+ <title>User Query Cache</title>
+ <para>User query result set caching will cache result sets based on an exact match
+ of the incoming SQL string and PreparedStatement parameter values if present. Caching only applies to SELECT, set query, and stored procedure execution
+ statements; it does not apply to SELECT INTO statements, or INSERT,
+ UPDATE, or DELETE statements.</para>
+ <para>End users or client applications explicitly state whether to use
+ result set caching. This can be done by setting the
+ JDBC ResultSetCacheMode execution property to true (default false) or by adding a <link linkend="cache-hint">cache hint</link> to the query.
+ Note that if either of these mechanisms are used, Teiid must also have result set caching enabled (the default is enabled).</para>
+ <para>The most basic form of the cache hint, <code>/*+ cache */</code>, is sufficient to inform the engine that the results of the non-update command should be cached.</para>
+ <example>
+ <title>PreparedStatement ResultSet Caching</title>
+ <programlisting>...
+PreparedStatement ps = connection.prepareStatement("/*+ cache */ select col from t where col2 = ?");
+ps.setInt(1, 5);
+ps.execute();
+...</programlisting>
+ <para>The results will be cached with the default ttl and use the SQL string and the parameter value as part of the cache key.</para>
+ </example>
+ <para>The pref_mem and ttl options of the cache hint may also be used for result set cache queries.
+ If a cache hint is not specified, then the default time to live of the result set caching configuration will be used.
+ </para>
+ <example>
+ <title>Advanced ResultSet Caching</title>
+ <programlisting>/*+ cache(pref_mem ttl:60000 */ select col from t</programlisting>
+ <para>In this example the memory preference has been enabled and the time to live is set to 60000 milliseconds or 1 minute.
+ The ttl for an entry is actually treated as it's maximum age and the entry may be purged sooner if the maximum number of cache entries has been reached.</para>
+ </example>
+ <note><para>Each query is re-checked for authorization using the current user’s permissions,
+ regardless of whether or not the results have been cached.</para></note>
+ </section>
+ <section>
+ <title>Procedure Result Cache</title>
+ <para>Similar to materialized views, cached virtual procedure results are used automatically when a matching set of parameter values is detected for the same procedure execution.
+ Usage of the cached results may be bypassed with an <code>OPTION NOCACHE</code> clause. See the <link linkend="nocache">OPTION NOCACHE</link> section for more on its usage.</para>
+ </section>
+ </section>
+ <section>
+ <title>Cached Virtual Procedure Definition</title>
+ <para>To indicate that a virtual procedure (only definable by Teiid Designer) should be cached, it's definition should include a <link linkend="cache-hint">cache hint</link>.
+ <example>
+ <title>Procedure Caching</title>
+ <programlisting>/*+ cache */ CREATE VIRTUAL PROCEDURE
+BEGIN
+ ...
+END</programlisting>
+ <para>Results will be cached with the default ttl.</para>
+ </example>
+ The pref_mem and ttl options of the cache hint may also be used for procedure caching.
+ </para>
+ <para>Procedure results cache keys include the input parameter values.
+ To prevent one procedure from filling the cache, at most 256 cache keys may be created per procedure per VDB.</para>
+ <para>A cached procedure will always produce all of its results prior to allowing those results to be consumed and placed in the cache.
+ This differs from normal procedure execution which in some situations allows the returned results to be consumed in a streaming manner.</para>
+ </section>
+ <section>
+ <title>Cache Configuration</title>
+ <para>By default result set caching is enabled with 1024 maximum entries with a maximum entry age of 2 hours.
+ There are actually 2 caches configured with these settings. One cache holds results that are specific to sessions and is local to each Teiid instance.
+ The other cache holds VDB scoped results and can be replicated.
+ See the &jboss-beans; config file or the Console's "Runtime Engine Properties" for tuning the configuration.
+ The user may also override the default maximum entry age via the <link linkend="cache-hint">cache hint</link>.
+ </para>
+ <para>Result set caching is not limited to memory. There is no explicit limit on the size of the results that can be cached.
+ Cached results are primarily stored in the BufferManager and are subject to it's configuration - including the restriction of maximum buffer space.
+ </para>
+ <note><para>While the result data is not held in memory, cache keys - including parameter values - may be held in memory.
+ Thus the cache should not be given an unlimited maximum size.</para></note>
+ </section>
+ <section>
+ <title>Cache Administration</title>
+ <para>The result set cache can be cleared through the AdminAPI using the <code>clearCache</code> method.
+ The expected cache key is "QUERY_SERVICE_RESULT_SET_CACHE".</para>
+ <example>
+ <title>Clearing the ResultSet Cache in AdminShell</title>
+ <programlisting>connectAsAdmin()
+clearCache("QUERY_SERVICE_RESULT_SET_CACHE")
+...</programlisting>
+ </example>
+ <para>See the Admin Guide for more on using the AdminAPI and AdminShell.</para>
+ </section>
+ <section>
+ <title>Limitations</title>
+ <itemizedlist>
+ <listitem>
+ <para>Non-XML document model results, BLOBs, CLOBs, and OBJECT typed values cannot be cached.</para>
+ </listitem>
+ <listitem>
+ <para>XML, BLOB, CLOB, and OBJECT type cannot be used as part of the cache key for prepared statement of procedure cache keys.</para>
+ </listitem>
+ <listitem>
+ <para>The exact SQL string, including the cache hint if present, must match the cached entry for the results to be reused.
+ This allows cache usage to skip parsing and resolving for faster responses.</para>
+ </listitem>
+ <listitem>
+ <para>Result set caching is not transactional. Transactions depend on (and
+ enforce) consistency of data, and cached data is not guaranteed
+ to be consistent with the data store’s data.</para>
+ </listitem>
+ <listitem>
+ <para>Clearing the results cache clears all cache entries for all VDBs.</para>
+ </listitem>
+ </itemizedlist>
+ </section>
+</chapter>
\ No newline at end of file
Property changes on: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/results.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/resultset.xml
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/resultset.xml 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/content/resultset.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -1,93 +0,0 @@
-<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
-<!ENTITY % CustomDTD SYSTEM "../../../../../../docbook/custom.dtd">
-%CustomDTD;
-]>
-<chapter id="resultset">
- <title>Result Set Caching</title>
- <para>Teiid provides the capability to cache the results of
- specific user queries. When the
- exact same user query is submitted to Teiid, the
- cached results will be returned. This caching technique
- can yield significant performance gains if users of the system submit
- the same queries often.</para>
- <para>Result set caching will cache result sets based on an exact match
- of the incoming SQL string and PreparedStatement parameter values if present. Caching only applies to SELECT, set query, and stored procedure execution
- statements; it does not apply to SELECT INTO statements, or INSERT,
- UPDATE, or DELETE statements.</para>
- <section>
- <title>Support Summary</title>
- <itemizedlist>
- <listitem>
- <para>Caching of user query results.</para>
- </listitem>
- <listitem>
- <para>Scoping of results is automatically determined to be either VDB (replicated) or session level.</para>
- </listitem>
- <listitem>
- <para>Caching of XML document model results.</para>
- </listitem>
- <listitem>
- <para>Configurable number of cache entries and time to live.</para>
- </listitem>
- <listitem>
- <para>Administrative clearing.</para>
- </listitem>
- </itemizedlist>
- </section>
- <section>
- <title>User Interaction</title>
- <para>End users or client applications explicitly state whether to use
- result set caching. This can be done by setting the
- JDBC ResultSetCacheMode execution property to true (default false) or by adding a <link linkend="cache-hint">cache hint</link> to the query.
- Note that if either of these mechanisms are used, Teiid must also have result set caching enabled (the default is enabled).</para>
- <para>
- To control the preference of individual results to remain in memory or the time to live see the <link linkend="cache-hint">cache hint</link>.
- If a cache hint is not specified, then the default time to live of the result set caching configuration will be used.
- </para>
- <note><para>Each query is re-checked for authorization using the current user’s permissions,
- regardless of whether or not the results have been cached.</para></note>
- </section>
- <section>
- <title>Cache Configuration</title>
- <para>By default result set caching is enabled with 1024 maximum entries with a maximum entry age of 2 hours.
- There are actually 2 caches configured with these settings. One cache holds results that are specific to sessions and is local to each Teiid instance.
- The other cache holds VDB scoped results and can be replicated.
- See the &jboss-beans; config file or the Console's "Runtime Engine Properties" for tuning the configuration.
- The user may also override the default maximum entry age via the <link linkend="cache-hint">cache hint</link>.</para>
- <para>Result set caching is not limited to memory. There is no explicit limit on the size of the results that can be cached.
- Cached results are primarily stored in the BufferManager and are subject to it's configuration - including the restriction of maximum buffer space.
- </para>
- </section>
- <section>
- <title>Cache Administration</title>
- <para>The result set cache can be cleared through the AdminAPI using the <code>clearCache</code> method.
- The expected cache key is "QUERY_SERVICE_RESULT_SET_CACHE".</para>
- <example>
- <title>Clearing the ResultSet Cache in AdminShell</title>
- <programlisting>connectAsAdmin()
-clearCache("QUERY_SERVICE_RESULT_SET_CACHE")
-...</programlisting>
- </example>
- <para>See the Admin Guide for more on using the AdminAPI and AdminShell.</para>
- </section>
- <section>
- <title>Limitations</title>
- <itemizedlist>
- <listitem>
- <para>Non-XML document model results, BLOBs, and CLOBs cannot be cached.</para>
- </listitem>
- <listitem>
- <para>The exact SQL string, including the cache hint if present, must match the cached entry for the results to be reused.
- This allows cache usage to skip parsing and resolving for faster responses.</para>
- </listitem>
- <listitem>
- <para>Result set caching is not transactional. Transactions depend on (and
- enforce) consistency of data, and cached data is not guaranteed
- to be consistent with the data store’s data.</para>
- </listitem>
- <listitem>
- <para>Clearing the result set cache clears all cache entries for all VDBs.</para>
- </listitem>
- </itemizedlist>
- </section>
-</chapter>
\ No newline at end of file
Modified: branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/main.xml
===================================================================
--- branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/main.xml 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/documentation/caching-guide/src/main/docbook/en-US/main.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -47,8 +47,8 @@
</bookinfo>
<toc />
<xi:include href="content/overview.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="content/resultset.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/results.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/matviews.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/codetable.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="content/matviews.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="content/cachehint.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/hint-option.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</book>
\ No newline at end of file
Modified: branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
===================================================================
--- branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-08-26 15:29:47 UTC (rev 2492)
@@ -1126,9 +1126,10 @@
<para>OPTION NOCACHE</para>
</listitem>
</itemizedlist>
- <para>Previous versions of Teiid accepted the PLANONLY, DEBUG, and SHOWPLAN option arguments. These are no longer accepted in the OPTION clause.
+ <para>All tables specified in the OPTION clause should be fully qualified.</para>
+ <note><para>Previous versions of Teiid accepted the PLANONLY, DEBUG, and SHOWPLAN option arguments. These are no longer accepted in the OPTION clause.
Please see the Client Developers Guide for replacements to those options.
- </para>
+ </para></note>
</section>
</section>
<section id="set_operations">
Modified: branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -139,7 +139,11 @@
if (ttl < 0) {
return Long.MAX_VALUE;
}
- return System.currentTimeMillis() + ttl;
+ long result = System.currentTimeMillis() + ttl;
+ if (result < ttl) {
+ result = Long.MAX_VALUE;
+ }
+ return result;
}
public V put(K key, V value, Long timeToLive) {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCacheFactory.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCacheFactory.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCacheFactory.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -34,8 +34,12 @@
private volatile boolean destroyed = false;
public DefaultCacheFactory() {
- this.cacheRoot = new DefaultCache("Teiid"); //$NON-NLS-1$
+ this(CacheConfiguration.DEFAULT);
}
+
+ public DefaultCacheFactory(CacheConfiguration config) {
+ this.cacheRoot = new DefaultCache("Teiid", config.getMaxEntries(), config.getMaxAgeInSeconds()*1000); //$NON-NLS-1$
+ }
@Override
public void destroy() {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -88,6 +88,10 @@
this.hint = command.getCacheHint();
}
+ public void setHint(CacheHint hint) {
+ this.hint = hint;
+ }
+
public CacheHint getHint() {
return hint;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -339,7 +339,7 @@
request.initialize(requestMsg, bufferManager,
dataTierMgr, transactionService, state.sessionTables,
workContext, this.useEntitlements, this.prepPlanCache);
-
+ request.setResultSetCacheEnabled(this.rsCache != null);
ResultsFuture<ResultsMessage> resultsFuture = new ResultsFuture<ResultsMessage>();
RequestWorkItem workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
logMMCommand(workItem, Event.NEW, null);
@@ -657,7 +657,7 @@
this.processWorkerPool = new ThreadReuseExecutor(DQPConfiguration.PROCESS_PLAN_QUEUE_NAME, config.getMaxThreads());
dataTierMgr = new TempTableDataManager(new DataTierManagerImpl(this,
- this.bufferService), this.bufferManager, this.processWorkerPool);
+ this.bufferService), this.bufferManager, this.processWorkerPool, this.rsCache);
}
public void setBufferService(BufferService service) {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -131,6 +131,7 @@
protected boolean useEntitlements;
private TempTableStore globalTables;
private SessionAwareCache<PreparedPlan> planCache;
+ private boolean resultSetCacheEnabled = true;
void initialize(RequestMessage requestMsg,
BufferManager bufferManager,
@@ -161,6 +162,10 @@
this.metadata = metadata;
this.multiSourceModels = multiSourceModels;
}
+
+ public void setResultSetCacheEnabled(boolean resultSetCacheEnabled) {
+ this.resultSetCacheEnabled = resultSetCacheEnabled;
+ }
/**
* if the metadata has not been supplied via setMetadata, this method will create the appropriate state
@@ -260,6 +265,7 @@
context.setMetadata(this.metadata);
context.setBufferManager(this.bufferManager);
context.setPreparedPlanCache(planCache);
+ context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
}
protected void checkReferences(List<Reference> references) throws QueryValidatorException {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -35,6 +35,7 @@
import org.teiid.cache.DefaultCacheFactory;
import org.teiid.cache.CacheConfiguration.Policy;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.function.metadata.FunctionMethod;
@@ -46,7 +47,7 @@
* This class is used to cache session aware objects
*/
public class SessionAwareCache<T> {
- public static final int DEFAULT_MAX_SIZE_TOTAL = 250;
+ public static final int DEFAULT_MAX_SIZE_TOTAL = 512;
private Cache<CacheID, T> localCache;
private Cache<CacheID, T> distributedCache;
@@ -58,7 +59,7 @@
private BufferManager bufferManager;
public SessionAwareCache(){
- this(new DefaultCacheFactory(), Cache.Type.RESULTSET, new CacheConfiguration(Policy.LRU, 60, DEFAULT_MAX_SIZE_TOTAL));
+ this(DEFAULT_MAX_SIZE_TOTAL);
}
SessionAwareCache(int maxSize){
@@ -188,16 +189,28 @@
this.sessionId = sessionId;
}
+ /**
+ * Set the raw (non-Constant) parameter values.
+ * @param parameters
+ * @return
+ */
public boolean setParameters(List<?> parameters) {
if (parameters != null && !parameters.isEmpty()) {
this.parameters = new ArrayList<Serializable>();
for (Object obj:parameters) {
- if (obj instanceof Serializable && obj instanceof Comparable<?>) {
- this.parameters.add((Serializable)obj);
+ if (obj == null) {
+ this.parameters.add(null);
+ continue;
}
- else{
+ if (!(obj instanceof Serializable)) {
return false;
}
+
+ Class<?> type = DataTypeManager.determineDataTypeClass(obj);
+ if (DataTypeManager.isLOB(type) || type == DataTypeManager.DefaultDataClasses.OBJECT) {
+ return false;
+ }
+ this.parameters.add((Serializable)obj);
}
}
return true;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -483,6 +483,22 @@
}
}
if (c != null) {
+ if (c.getCacheHint() != null) {
+ if (container instanceof StoredProcedure) {
+ boolean noCache = isNoCacheGroup(metadata, ((StoredProcedure) container).getProcedureID(), option);
+ if (!noCache) {
+ if (container.areResultsCachable() && Query.areResultsCachable(container.getProcedureParameters().keySet()) && context.isResultSetCacheEnabled()) {
+ container.getGroup().setGlobalTable(true);
+ container.setCacheHint(c.getCacheHint());
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.procedure_cache_used", container.getGroup()); //$NON-NLS-1$
+ return;
+ }
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.MEDIUM, "SimpleQueryResolver.procedure_cache_not_usable", container.getGroup()); //$NON-NLS-1$
+ } else {
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.procedure_cache_not_used", container.getGroup()); //$NON-NLS-1$
+ }
+ }
+ }
//skip the rewrite here, we'll do that in the optimizer
//so that we know what the determinism level is.
addNestedCommand(sourceNode, container.getGroup(), container, c, false);
@@ -925,14 +941,14 @@
//not use cache
qnode = metadata.getVirtualPlan(metadataID);
//TODO: update the table for defaultMat
- recordMaterializationTableAnnotation(analysisRecord, QueryPlugin.Util.getString("SimpleQueryResolver.materialized_table_not_used", virtualGroup, matTableName)); //$NON-NLS-1$
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.materialized_table_not_used", virtualGroup, matTableName); //$NON-NLS-1$
}else{
qnode = new QueryNode(groupName, null);
Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new AllSymbol()), isImplicitGlobal);
query.setCacheHint(hint);
qnode.setCommand(query);
cacheString = "matview"; //$NON-NLS-1$
- recordMaterializationTableAnnotation(analysisRecord, QueryPlugin.Util.getString("SimpleQueryResolver.Query_was_redirected_to_Mat_table", virtualGroup, matTableName)); //$NON-NLS-1$
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.Query_was_redirected_to_Mat_table", virtualGroup, matTableName); //$NON-NLS-1$
}
} else {
// Not a materialized view - query the primary transformation
@@ -981,13 +997,13 @@
Command c = getCommand(table, metadata.getVirtualPlan(table.getMetadataID()), SQLConstants.Reserved.SELECT, metadata, analysisRecord);
CacheHint hint = c.getCacheHint();
if (hint != null) {
- recordMaterializationTableAnnotation(analysisRecord, QueryPlugin.Util.getString("SimpleQueryResolver.cache_hint_used", table, matTableName, hint)); //$NON-NLS-1$
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.cache_hint_used", table, matTableName, id.getCacheHint()); //$NON-NLS-1$
}
id.setCacheHint(hint);
}
}
} else if (id.getCacheHint() != null) {
- recordMaterializationTableAnnotation(analysisRecord, QueryPlugin.Util.getString("SimpleQueryResolver.cache_hint_used", table, matTableName, id.getCacheHint())); //$NON-NLS-1$
+ recordAnnotation(analysisRecord, Annotation.MATERIALIZED_VIEW, Priority.LOW, "SimpleQueryResolver.cache_hint_used", table, matTableName, id.getCacheHint()); //$NON-NLS-1$
}
return id;
}
@@ -1042,15 +1058,14 @@
return false;
}
- private static void recordMaterializationTableAnnotation(AnalysisRecord analysis,
- String msg) {
- if ( analysis.recordAnnotations() ) {
- Annotation annotation = new Annotation(Annotation.MATERIALIZED_VIEW,
- msg,
- null,
- Priority.LOW);
- analysis.addAnnotation(annotation);
- }
+ private static void recordAnnotation(AnalysisRecord analysis, String type, Priority priority, String msgKey, Object... parts) {
+ if (analysis.recordAnnotations()) {
+ Annotation annotation = new Annotation(type,
+ QueryPlugin.Util.getString(msgKey, parts),
+ null,
+ priority);
+ analysis.addAnnotation(annotation);
+ }
}
}
\ No newline at end of file
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
@@ -36,12 +37,16 @@
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.CoreConstants;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
+import org.teiid.dqp.internal.process.CachedResults;
+import org.teiid.dqp.internal.process.SessionAwareCache;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
@@ -52,6 +57,7 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.parser.ParseInfo;
import org.teiid.query.processor.BatchCollector;
import org.teiid.query.processor.CollectionTupleSource;
import org.teiid.query.processor.ProcessorDataManager;
@@ -65,8 +71,10 @@
import org.teiid.query.sql.lang.Delete;
import org.teiid.query.sql.lang.Drop;
import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.Option;
import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.Update;
import org.teiid.query.sql.navigator.PostOrderNavigator;
@@ -93,7 +101,7 @@
private ProcessorDataManager processorDataManager;
private BufferManager bufferManager;
-
+ private SessionAwareCache<CachedResults> cache;
private Executor executor;
public TempTableDataManager(ProcessorDataManager processorDataManager, BufferManager bufferManager) {
@@ -102,7 +110,7 @@
public void execute(Runnable command) {
command.run();
}
- });
+ }, new SessionAwareCache<CachedResults>());
}
/**
@@ -110,11 +118,13 @@
* and will pass most calls through to transparently. Only when a request is registered for
* a temp group will this proxy do it's thing.
* @param processorDataManager the real ProcessorDataManager that this object is a proxy to
+ * @param cache
*/
- public TempTableDataManager(ProcessorDataManager processorDataManager, BufferManager bufferManager, Executor executor){
+ public TempTableDataManager(ProcessorDataManager processorDataManager, BufferManager bufferManager, Executor executor, SessionAwareCache<CachedResults> cache){
this.processorDataManager = processorDataManager;
this.bufferManager = bufferManager;
this.executor = executor;
+ this.cache = cache;
}
public TupleSource registerRequest(
@@ -141,11 +151,49 @@
return registerQuery(context, contextStore, query);
}
if (command instanceof ProcedureContainer) {
-
- if (command instanceof StoredProcedure && CoreConstants.SYSTEM_MODEL.equals(modelName)) {
- TupleSource result = handleSystemProcedures(context, command);
- if (result != null) {
- return result;
+ if (command instanceof StoredProcedure) {
+ StoredProcedure proc = (StoredProcedure)command;
+ if (CoreConstants.SYSTEM_MODEL.equals(modelName)) {
+ TupleSource result = handleSystemProcedures(context, proc);
+ if (result != null) {
+ return result;
+ }
+ } else if (proc.getGroup().isGlobalTable()) {
+ String fullName = context.getMetadata().getFullName(proc.getProcedureID());
+ LinkedList<Object> vals = new LinkedList<Object>();
+ for (SPParameter param : proc.getInputParameters()) {
+ vals.add(((Constant)param.getExpression()).getValue());
+ }
+ //collapse the hash to single byte for the key to restrict the possible results to 256
+ int hash = vals.hashCode();
+ hash |= (hash >>> 16);
+ hash |= (hash >>> 8);
+ hash &= 0x000000ff;
+ CacheID cid = new CacheID(new ParseInfo(), fullName + hash, context.getVdbName(),
+ context.getVdbVersion(), context.getConnectionID(), context.getUserName());
+ cid.setParameters(vals);
+ CachedResults results = cache.get(cid);
+ if (results != null) {
+ TupleBuffer buffer = results.getResults();
+ return buffer.createIndexedTupleSource();
+ }
+ CacheHint hint = proc.getCacheHint();
+ proc.setCacheHint(null);
+ Option option = new Option();
+ option.setNoCache(true);
+ option.addNoCacheGroup(fullName);
+ proc.setOption(option);
+ int determinismLevel = context.resetDeterminismLevel();
+ QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(proc.toString(), fullName.toUpperCase(), context);
+ qp.setNonBlocking(true);
+ BatchCollector bc = qp.createBatchCollector();
+ TupleBuffer tb = bc.collectTuples();
+ CachedResults cr = new CachedResults();
+ cr.setResults(tb);
+ cr.setHint(hint);
+ cache.put(cid, context.getDeterminismLevel(), cr, hint != null?hint.getTtl():null);
+ context.setDeterminismLevel(determinismLevel);
+ return tb.createIndexedTupleSource();
}
}
@@ -200,14 +248,13 @@
return null;
}
- private TupleSource handleSystemProcedures(CommandContext context, Command command)
+ private TupleSource handleSystemProcedures(CommandContext context, StoredProcedure proc)
throws TeiidComponentException, QueryMetadataException,
QueryProcessingException, QueryResolverException,
QueryValidatorException, TeiidProcessingException,
ExpressionEvaluationException {
QueryMetadataInterface metadata = context.getMetadata();
TempTableStore globalStore = context.getGlobalTableStore();
- StoredProcedure proc = (StoredProcedure)command;
if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEW)) {
Object groupID = validateMatView(metadata, proc);
String matViewName = metadata.getFullName(groupID);
@@ -361,10 +408,11 @@
}
int rowCount = -1;
try {
+ String fullName = metadata.getFullName(group.getMetadataID());
//TODO: order by primary key nulls first - then have an insert ordered optimization
//TODO: use the getCommand logic in RelationalPlanner to reuse commands for this.
String transformation = metadata.getVirtualPlan(group.getMetadataID()).getQuery();
- QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(transformation, group.getCanonicalName(), context);
+ QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(transformation, fullName, context);
qp.setNonBlocking(true);
TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
//TODO: if this insert fails, it's unnecessary to do the undo processing
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -108,6 +108,9 @@
private TempTableStore globalTables;
private SessionAwareCache<PreparedPlan> planCache;
+
+ private boolean resultSetCacheEnabled = true;
+
}
private GlobalState globalState = new GlobalState();
@@ -499,5 +502,13 @@
CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionID(), getUserName());
this.globalState.planCache.put(id, determinismLevel, plan, null);
}
+
+ public boolean isResultSetCacheEnabled() {
+ return globalState.resultSetCacheEnabled;
+ }
+
+ public void setResultSetCacheEnabled(boolean resultSetCacheEnabled) {
+ this.globalState.resultSetCacheEnabled = resultSetCacheEnabled;
+ }
}
Modified: branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-08-26 15:29:47 UTC (rev 2492)
@@ -864,6 +864,9 @@
ResolveVariablesVisitor.reserved_word_for_temporary_used=Cursor names cannot begin with "#" as that indicates the name of a temporary table: {0}.
SimpleQueryResolver.materialized_table_not_used=The query against {0} did not use materialization table {1} due to the use of OPTION NOCACHE.
SimpleQueryResolver.cache_hint_used=Loading materialized view {1} for view {0} using cache hint {2}.
+SimpleQueryResolver.procedure_cache_used=Procedure caching will be used for {0}.
+SimpleQueryResolver.procedure_cache_not_usable=Procedure caching will not be used for {0} since the result set cache is disabled or the results/parameters cannot be cached.
+SimpleQueryResolver.procedure_cache_not_used=Procedure caching will not be used for {0} due to the use of OPTION NOCACHE.
ValidationVisitor.input_variable_data_type_not_match=The expression "{0}" assigned to input variable "{1}" is of type "{2}" which cannot be implicitly converted to the expected type "{3}".
ValidationVisitor.input_variable_can_not_in_function=Input variable "{0}" cannot be an argument of a function in the criteria.
ValidationVisitor.groupby_subquery=Expressions used in a GROUP BY cannot be constant and must not contain subqueries: "{0}".
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -101,5 +101,18 @@
execute("SELECT * from vgroup4 where x is null", Arrays.asList((String)null));
assertEquals(2, hdm.getCommandHistory().size());
}
+
+ @Test public void testProcedureCache() throws Exception {
+ execute("call sp1('one')", Arrays.asList("one"));
+ assertEquals(1, hdm.getCommandHistory().size());
+ execute("call sp1('one')", Arrays.asList("one"));
+ assertEquals(1, hdm.getCommandHistory().size());
+ execute("call sp1('one') option nocache sp.sp1", Arrays.asList("one"));
+ assertEquals(2, hdm.getCommandHistory().size());
+ execute("call sp1(null)");
+ assertEquals(3, hdm.getCommandHistory().size());
+ execute("call sp1(null)");
+ assertEquals(3, hdm.getCommandHistory().size());
+ }
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -257,6 +257,7 @@
for (int i = 0; i < 100; i++) {
try {
id = collector.collectTuples();
+ break;
} catch (BlockedException e) {
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-25 17:56:09 UTC (rev 2491)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-26 15:29:47 UTC (rev 2492)
@@ -358,6 +358,14 @@
createElements(vGroup4,
new String[] { "x" }, //$NON-NLS-1$
new String[] { DataTypeManager.DefaultDataTypes.STRING});
+
+ Schema sp = createVirtualModel("sp", metadataStore); //$NON-NLS-1$
+ ColumnSet<Procedure> rs = createResultSet("sp1.vsprs1", new String[] { "StringKey" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcedureParameter param = createParameter("param1", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$
+ param.setNullType(NullType.Nullable);
+ QueryNode sp1qn = new QueryNode("sp1", "/*+ cache */ CREATE VIRTUAL PROCEDURE BEGIN SELECT x as StringKey from matsrc where x = param1; END"); //$NON-NLS-1$ //$NON-NLS-2$
+ Procedure vsp5 = createVirtualProcedure("sp1", sp, Arrays.asList(param), sp1qn); //$NON-NLS-1$
+ vsp5.setResultSet(rs);
return createTransformationMetadata(metadataStore, "");
}
14 years, 4 months
teiid SVN: r2491 - in branches/7.1.x: build/kits/jboss-container/deploy/teiid and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-25 13:56:09 -0400 (Wed, 25 Aug 2010)
New Revision: 2491
Modified:
branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SelectNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java
Log:
TEIID-1225 reducing the footprint of plans and updating the releasenotes
Modified: branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml 2010-08-25 17:56:09 UTC (rev 2491)
@@ -93,8 +93,10 @@
<property name="maxRowsFetchSize">20480</property>
<!-- The max lob chunk size in KB transferred each time when processing blobs, clobs(100KB default) -->
<property name="lobChunkSizeInKB">100</property>
- <!-- The maximum number of query plans that are cached. Note: this is a memory based cache. (default 250) -->
- <property name="preparedPlanCacheMaxCount">250</property>
+ <!-- The maximum number of query plans that are cached.
+ This includes both user plans and internal prepared plans.
+ Note: this is a memory based cache. (default 512) -->
+ <property name="preparedPlanCacheMaxCount">512</property>
<!-- Turn on role checking on resources based on the roles defined in VDB -->
<property name="useDataRoles" class="java.lang.Boolean">false</property>
<!-- Long running query threshold, after which a alert can be generated by tooling if configured-->
Modified: branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-08-25 17:56:09 UTC (rev 2491)
@@ -26,6 +26,7 @@
</UL>
<H2><A NAME="Highlights"></A>Highlights</H2>
<UL>
+ <LI><B>Improved Plan Caching</B> - plans used by internal materialization and stored procedure plans will be automatically cached in the prepared plan cache. Improvements were also made to reduce the memory footprint of the plans.
<LI><B>Refined Load Balancing and Fail Over</B> - clients can use use the statement "SET NEWINSTANCE TRUE" to allow their connection to select a new server instance. See the Client Developer's Guide for more information.
</UL>
@@ -62,6 +63,12 @@
<h2><a name="Configuration">Configuration Issues</a></h2>
See the See the <a href="teiid-docs/teiid_admin_guide.pdf">Admin Guide</a> for more on configuration and installation.
+
+<h4>from 7.1</h4>
+<ul>
+ <li>The default prepared plan cache size was increased to 512, since it is targeted by internal plans as well.
+</ul>
+
<h4>from 7.0</h4>
<ul>
<li>The property to enable data roles in teiid-jboss-beans.xml has changed from useEntitlements to useDataRoles.
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -58,6 +58,10 @@
private boolean returnedRows = false;
private Command nextCommand;
+ protected AccessNode() {
+ super();
+ }
+
public AccessNode(int nodeID) {
super(nodeID);
}
@@ -218,7 +222,7 @@
}
public Object clone(){
- AccessNode clonedNode = new AccessNode(super.getID());
+ AccessNode clonedNode = new AccessNode();
this.copy(this, clonedNode);
return clonedNode;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -45,6 +45,10 @@
private boolean isOpen;
private boolean needsProcessing;
+ protected PlanExecutionNode() {
+ super();
+ }
+
public PlanExecutionNode(int nodeID) {
super(nodeID);
}
@@ -154,7 +158,7 @@
}
public Object clone(){
- PlanExecutionNode clonedNode = new PlanExecutionNode(super.getID());
+ PlanExecutionNode clonedNode = new PlanExecutionNode();
copy(this, clonedNode);
return clonedNode;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectIntoNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -72,6 +72,10 @@
private TupleBatch currentBatch;
private TupleSource tupleSource;
+
+ protected ProjectIntoNode() {
+ super();
+ }
public ProjectIntoNode(int nodeID) {
super(nodeID);
@@ -244,7 +248,7 @@
}
public Object clone(){
- ProjectIntoNode clonedNode = new ProjectIntoNode(super.getID());
+ ProjectIntoNode clonedNode = new ProjectIntoNode();
super.copy(this, clonedNode);
clonedNode.intoGroup = intoGroup;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/ProjectNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -62,6 +62,10 @@
// Saved state when blocked on evaluating a row - must be reset
private TupleBatch currentBatch;
private int currentRow = 1;
+
+ protected ProjectNode() {
+ super();
+ }
public ProjectNode(int nodeID) {
super(nodeID);
@@ -224,7 +228,7 @@
}
public Object clone(){
- ProjectNode clonedNode = new ProjectNode(super.getID());
+ ProjectNode clonedNode = new ProjectNode();
this.copy(this, clonedNode);
return clonedNode;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -50,88 +50,102 @@
public abstract class RelationalNode implements Cloneable, BatchProducer {
+
+ static class NodeData {
+ int nodeID;
+ List elements;
+ Number estimateNodeCardinality;
+ Number setSizeEstimate;
+ Number depAccessEstimate;
+ Number estimateDepJoinCost;
+ Number estimateJoinCost;
+ }
- // External context and state
- private CommandContext context;
- private BufferManager bufferManager;
- private ProcessorDataManager dataMgr;
-
- // Node state
- private int nodeID;
- private List elements;
- private int batchSize;
- private RelationalNodeStatistics nodeStatistics;
+ static class ProcessingState {
+ CommandContext context;
+ BufferManager bufferManager;
+ ProcessorDataManager dataMgr;
+ int batchSize;
+ RelationalNodeStatistics nodeStatistics;
+ int beginBatch = 1;
+ List batchRows;
+ boolean lastBatch;
+ boolean closed;
+
+ void reset() {
+ this.beginBatch = 1;
+ this.batchRows = null;
+ this.lastBatch = false;
+ this.closed = false;
+ }
+ }
- // For collecting result batches
- private int beginBatch = 1;
- private List batchRows;
- private boolean lastBatch = false;
-
+ private ProcessingState processingState;
+ private NodeData data;
/** The parent of this node, null if root. */
private RelationalNode parent;
/** Child nodes, usually just 1 or 2 */
private RelationalNode[] children = new RelationalNode[2];
-
- // Cost Estimates
- private Number estimateNodeCardinality;
- private Number setSizeEstimate;
- private Number depAccessEstimate;
- private Number estimateDepJoinCost;
- private Number estimateJoinCost;
-
- private boolean closed = false;
-
+
+ protected RelationalNode() {
+
+ }
+
public RelationalNode(int nodeID) {
- this.nodeID = nodeID;
+ this.data = new NodeData();
+ this.data.nodeID = nodeID;
}
public boolean isLastBatch() {
- return lastBatch;
+ return getProcessingState().lastBatch;
}
public void setContext(CommandContext context) {
- this.context = context;
+ this.getProcessingState().context = context;
}
public void initialize(CommandContext context, BufferManager bufferManager, ProcessorDataManager dataMgr) {
- this.context = context;
- this.bufferManager = bufferManager;
- this.dataMgr = dataMgr;
+ this.getProcessingState().context = context;
+ this.getProcessingState().bufferManager = bufferManager;
+ this.getProcessingState().dataMgr = dataMgr;
if(context.getCollectNodeStatistics()) {
- this.nodeStatistics = new RelationalNodeStatistics();
+ this.getProcessingState().nodeStatistics = new RelationalNodeStatistics();
}
- this.batchSize = bufferManager.getProcessorBatchSize();
+ this.getProcessingState().batchSize = bufferManager.getProcessorBatchSize();
}
public CommandContext getContext() {
- return this.context;
+ return this.getProcessingState().context;
}
public int getID() {
- return this.nodeID;
+ return this.data.nodeID;
}
public void setID(int nodeID) {
- this.nodeID = nodeID;
+ NodeData newData = new NodeData();
+ newData.nodeID = nodeID;
+ newData.elements = this.data.elements;
+ this.data = newData;
}
protected BufferManager getBufferManager() {
- return this.bufferManager;
+ return this.getProcessingState().bufferManager;
}
protected ProcessorDataManager getDataManager() {
- return this.dataMgr;
+ return this.getProcessingState().dataMgr;
}
protected String getConnectionID() {
- return this.context.getConnectionID();
+ return this.getProcessingState().context.getConnectionID();
}
protected int getBatchSize() {
- return this.batchSize;
+ return this.getProcessingState().batchSize;
}
public void reset() {
@@ -142,15 +156,13 @@
break;
}
}
-
- beginBatch = 1;
- batchRows = null;
- lastBatch = false;
- closed = false;
+ if (this.getProcessingState() != null) {
+ this.getProcessingState().reset();
+ }
}
public void setElements(List elements) {
- this.elements = elements;
+ this.data.elements = elements;
}
@Override
@@ -159,7 +171,7 @@
}
public List getElements() {
- return this.elements;
+ return this.data.elements;
}
public RelationalNode getParent() {
@@ -193,38 +205,38 @@
}
protected void addBatchRow(List row) {
- if(this.batchRows == null) {
- this.batchRows = new ArrayList(this.batchSize / 4);
+ if(this.getProcessingState().batchRows == null) {
+ this.getProcessingState().batchRows = new ArrayList(this.getProcessingState().batchSize / 4);
}
- this.batchRows.add(row);
+ this.getProcessingState().batchRows.add(row);
}
protected void terminateBatches() {
- this.lastBatch = true;
+ this.getProcessingState().lastBatch = true;
}
protected boolean isBatchFull() {
- return (this.batchRows != null) && (this.batchRows.size() >= this.batchSize);
+ return (this.getProcessingState().batchRows != null) && (this.getProcessingState().batchRows.size() >= this.getProcessingState().batchSize);
}
protected boolean hasPendingRows() {
- return this.batchRows != null;
+ return this.getProcessingState().batchRows != null;
}
protected TupleBatch pullBatch() {
TupleBatch batch = null;
- if(this.batchRows != null) {
- batch = new TupleBatch(this.beginBatch, this.batchRows);
- beginBatch += this.batchRows.size();
+ if(this.getProcessingState().batchRows != null) {
+ batch = new TupleBatch(this.getProcessingState().beginBatch, this.getProcessingState().batchRows);
+ getProcessingState().beginBatch += this.getProcessingState().batchRows.size();
} else {
- batch = new TupleBatch(this.beginBatch, Collections.EMPTY_LIST);
+ batch = new TupleBatch(this.getProcessingState().beginBatch, Collections.EMPTY_LIST);
}
- batch.setTerminationFlag(this.lastBatch);
+ batch.setTerminationFlag(this.getProcessingState().lastBatch);
// Reset batch state
- this.batchRows = null;
- this.lastBatch = false;
+ this.getProcessingState().batchRows = null;
+ this.getProcessingState().lastBatch = false;
// Return batch
return batch;
@@ -251,22 +263,22 @@
* @since 4.2
*/
public final TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
- boolean recordStats = this.context != null && this.context.getCollectNodeStatistics();
+ boolean recordStats = this.getProcessingState().context != null && this.getProcessingState().context.getCollectNodeStatistics();
try {
while (true) {
//start timer for this batch
- if(recordStats && this.context.getCollectNodeStatistics()) {
- this.nodeStatistics.startBatchTimer();
+ if(recordStats && this.getProcessingState().context.getCollectNodeStatistics()) {
+ this.getProcessingState().nodeStatistics.startBatchTimer();
}
TupleBatch batch = nextBatchDirect();
if (recordStats) {
- if(this.context.getCollectNodeStatistics()) {
+ if(this.getProcessingState().context.getCollectNodeStatistics()) {
// stop timer for this batch (normal)
- this.nodeStatistics.stopBatchTimer();
- this.nodeStatistics.collectCumulativeNodeStats(batch, RelationalNodeStatistics.BATCHCOMPLETE_STOP);
+ this.getProcessingState().nodeStatistics.stopBatchTimer();
+ this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(batch, RelationalNodeStatistics.BATCHCOMPLETE_STOP);
if (batch.getTerminationFlag()) {
- this.nodeStatistics.collectNodeStats(this.getChildren(), this.getClassName());
+ this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren(), this.getClassName());
//this.nodeStatistics.dumpProperties(this.getClassName());
}
}
@@ -283,21 +295,21 @@
}
}
} catch (BlockedException e) {
- if(recordStats && this.context.getCollectNodeStatistics()) {
+ if(recordStats && this.getProcessingState().context.getCollectNodeStatistics()) {
// stop timer for this batch (BlockedException)
- this.nodeStatistics.stopBatchTimer();
- this.nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
+ this.getProcessingState().nodeStatistics.stopBatchTimer();
+ this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
}
throw e;
} catch (QueryProcessor.ExpiredTimeSliceException e) {
- if(recordStats && this.context.getCollectNodeStatistics()) {
- this.nodeStatistics.stopBatchTimer();
+ if(recordStats && this.getProcessingState().context.getCollectNodeStatistics()) {
+ this.getProcessingState().nodeStatistics.stopBatchTimer();
}
throw e;
} catch (TeiidComponentException e) {
// stop timer for this batch (MetaMatrixComponentException)
- if(recordStats && this.context.getCollectNodeStatistics()) {
- this.nodeStatistics.stopBatchTimer();
+ if(recordStats && this.getProcessingState().context.getCollectNodeStatistics()) {
+ this.getProcessingState().nodeStatistics.stopBatchTimer();
}
throw e;
}
@@ -317,7 +329,7 @@
public final void close()
throws TeiidComponentException {
- if (!this.closed) {
+ if (!this.getProcessingState().closed) {
closeDirect();
for(int i=0; i<children.length; i++) {
if(children[i] != null) {
@@ -326,7 +338,7 @@
break;
}
}
- this.closed = true;
+ this.getProcessingState().closed = true;
}
}
@@ -339,7 +351,7 @@
* @return
*/
public boolean isClosed() {
- return this.closed;
+ return this.getProcessingState().closed;
}
/**
@@ -487,9 +499,7 @@
public abstract Object clone();
protected void copy(RelationalNode source, RelationalNode target){
- if(source.elements != null){
- target.elements = new ArrayList(source.elements);
- }
+ target.data = source.data;
target.children = new RelationalNode[source.children.length];
for(int i=0; i<source.children.length; i++) {
@@ -505,9 +515,9 @@
public PlanNode getDescriptionProperties() {
// Default implementation - should be overridden
PlanNode result = new PlanNode(getClassName());
- result.addProperty(PROP_OUTPUT_COLS, AnalysisRecord.getOutputColumnProperties(this.elements));
- if(this.context != null && this.context.getCollectNodeStatistics()) {
- result.addProperty(PROP_NODE_STATS_LIST, this.nodeStatistics.getStatisticsList());
+ result.addProperty(PROP_OUTPUT_COLS, AnalysisRecord.getOutputColumnProperties(this.data.elements));
+ if(this.getProcessingState().context != null && this.getProcessingState().context.getCollectNodeStatistics()) {
+ result.addProperty(PROP_NODE_STATS_LIST, this.getProcessingState().nodeStatistics.getStatisticsList());
}
List<String> costEstimates = this.getCostEstimates();
if(costEstimates != null) {
@@ -526,57 +536,64 @@
* @since 4.2
*/
public RelationalNodeStatistics getNodeStatistics() {
- return this.nodeStatistics;
+ return this.getProcessingState().nodeStatistics;
}
public void setEstimateNodeCardinality(Number estimateNodeCardinality) {
- this.estimateNodeCardinality = estimateNodeCardinality;
+ this.data.estimateNodeCardinality = estimateNodeCardinality;
}
public void setEstimateNodeSetSize(Number setSizeEstimate) {
- this.setSizeEstimate = setSizeEstimate;
+ this.data.setSizeEstimate = setSizeEstimate;
}
public void setEstimateDepAccessCardinality(Number depAccessEstimate) {
- this.depAccessEstimate = depAccessEstimate;
+ this.data.depAccessEstimate = depAccessEstimate;
}
public void setEstimateDepJoinCost(Number estimateDepJoinCost){
- this.estimateDepJoinCost = estimateDepJoinCost;
+ this.data.estimateDepJoinCost = estimateDepJoinCost;
}
public void setEstimateJoinCost(Number estimateJoinCost){
- this.estimateJoinCost = estimateJoinCost;
+ this.data.estimateJoinCost = estimateJoinCost;
}
private List<String> getCostEstimates() {
List<String> costEstimates = new ArrayList<String>();
- if(this.estimateNodeCardinality != null) {
- costEstimates.add("Estimated Node Cardinality: "+ this.estimateNodeCardinality); //$NON-NLS-1$
+ if(this.data.estimateNodeCardinality != null) {
+ costEstimates.add("Estimated Node Cardinality: "+ this.data.estimateNodeCardinality); //$NON-NLS-1$
}
- if(this.setSizeEstimate != null) {
- costEstimates.add("Estimated Independent Node Produced Set Size: "+ this.setSizeEstimate); //$NON-NLS-1$
+ if(this.data.setSizeEstimate != null) {
+ costEstimates.add("Estimated Independent Node Produced Set Size: "+ this.data.setSizeEstimate); //$NON-NLS-1$
}
- if(this.depAccessEstimate != null) {
- costEstimates.add("Estimated Dependent Access Cardinality: "+ this.depAccessEstimate); //$NON-NLS-1$
+ if(this.data.depAccessEstimate != null) {
+ costEstimates.add("Estimated Dependent Access Cardinality: "+ this.data.depAccessEstimate); //$NON-NLS-1$
}
- if(this.estimateDepJoinCost != null) {
- costEstimates.add("Estimated Dependent Join Cost: "+ this.estimateDepJoinCost); //$NON-NLS-1$
+ if(this.data.estimateDepJoinCost != null) {
+ costEstimates.add("Estimated Dependent Join Cost: "+ this.data.estimateDepJoinCost); //$NON-NLS-1$
}
- if(this.estimateJoinCost != null) {
- costEstimates.add("Estimated Join Cost: "+ this.estimateJoinCost); //$NON-NLS-1$
+ if(this.data.estimateJoinCost != null) {
+ costEstimates.add("Estimated Join Cost: "+ this.data.estimateJoinCost); //$NON-NLS-1$
}
if(costEstimates.size() <= 0) {
return null;
}
return costEstimates;
}
-
/**
* @return Returns the estimateNodeCardinality.
*/
public Number getEstimateNodeCardinality() {
- return this.estimateNodeCardinality;
+ return this.data.estimateNodeCardinality;
}
+
+ private ProcessingState getProcessingState() {
+ //construct lazily since not all tests call initialize
+ if (this.processingState == null) {
+ this.processingState = new ProcessingState();
+ }
+ return processingState;
+ }
}
\ No newline at end of file
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SelectNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SelectNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SelectNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -51,6 +51,10 @@
// State if blocked on evaluating a criteria
private TupleBatch currentBatch;
private int currentRow = 1;
+
+ protected SelectNode() {
+ super();
+ }
public SelectNode(int nodeID) {
super(nodeID);
@@ -117,7 +121,7 @@
}
public Object clone(){
- SelectNode clonedNode = new SelectNode(super.getID());
+ SelectNode clonedNode = new SelectNode();
this.copy(this, clonedNode);
return clonedNode;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java 2010-08-25 16:18:52 UTC (rev 2490)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java 2010-08-25 17:56:09 UTC (rev 2491)
@@ -37,6 +37,10 @@
private SubqueryAwareEvaluator evaluator;
+ protected SubqueryAwareRelationalNode() {
+ super();
+ }
+
public SubqueryAwareRelationalNode(int nodeID) {
super(nodeID);
}
14 years, 4 months
teiid SVN: r2490 - in branches/7.1.x/engine/src: main/java/org/teiid/query/optimizer and 17 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-25 12:18:52 -0400 (Wed, 25 Aug 2010)
New Revision: 2490
Added:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/QueryProcessorFactoryImpl.java
Removed:
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
branches/7.1.x/engine/src/main/java/org/teiid/query/parser/QueryParser.java
branches/7.1.x/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Delete.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Insert.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Query.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SPParameter.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SetQuery.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Update.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
branches/7.1.x/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-1226 TEIID-1225 TEIID-1223 TEIID-1222 adding additional plan reuse, fixing the cache hint logic, fixing partially qualified virtual procs
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -338,7 +338,7 @@
ClientState state = this.getClientState(workContext.getSessionId(), true);
request.initialize(requestMsg, bufferManager,
dataTierMgr, transactionService, state.sessionTables,
- workContext, this.useEntitlements);
+ workContext, this.useEntitlements, this.prepPlanCache);
ResultsFuture<ResultsMessage> resultsFuture = new ResultsFuture<ResultsMessage>();
RequestWorkItem workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedPlan.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -30,7 +30,7 @@
import org.teiid.query.sql.symbol.Reference;
-class PreparedPlan{
+public class PreparedPlan{
private ProcessorPlan plan;
private Command command;
private List<Reference> refs;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -146,7 +146,7 @@
// Defect 13751: Clone the plan in its current state (i.e. before processing) so that it can be used for later queries
prepPlan.setPlan(processPlan.clone());
prepPlan.setAnalysisRecord(analysisRecord);
- this.prepPlanCache.put(id, this.context.getDeterminismLevel(), prepPlan);
+ this.prepPlanCache.put(id, this.context.getDeterminismLevel(), prepPlan, userCommand.getCacheHint() != null?userCommand.getCacheHint().getTtl():null);
}
} else {
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Query exist in cache: ", sqlQuery }); //$NON-NLS-1$
Copied: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/QueryProcessorFactoryImpl.java (from rev 2478, branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java)
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/QueryProcessorFactoryImpl.java (rev 0)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/QueryProcessorFactoryImpl.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.parser.ParseInfo;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.util.VariableContext;
+import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.AbstractValidationVisitor;
+import org.teiid.query.validator.ValidationVisitor;
+
+public class QueryProcessorFactoryImpl implements QueryProcessor.ProcessorFactory {
+
+ private QueryMetadataInterface metadata;
+ private CapabilitiesFinder finder;
+ private IDGenerator idGenerator;
+ private BufferManager bufferMgr;
+ private ProcessorDataManager dataMgr;
+
+ public QueryProcessorFactoryImpl(BufferManager bufferMgr,
+ ProcessorDataManager dataMgr, CapabilitiesFinder finder,
+ IDGenerator idGenerator, QueryMetadataInterface metadata) {
+ this.bufferMgr = bufferMgr;
+ this.dataMgr = dataMgr;
+ this.finder = finder;
+ this.idGenerator = idGenerator;
+ this.metadata = metadata;
+ }
+
+ @Override
+ public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
+ PreparedPlan pp = commandContext.getPlan(query);
+ CommandContext copy = commandContext.clone();
+ if (recursionGroup != null) {
+ copy.pushCall(recursionGroup);
+ }
+ if (pp == null) {
+ ParseInfo parseInfo = new ParseInfo();
+ Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
+ QueryResolver.resolveCommand(newCommand, metadata);
+
+ List<Reference> references = ReferenceCollectorVisitor.getReferences(newCommand);
+
+ AbstractValidationVisitor visitor = new ValidationVisitor();
+ Request.validateWithVisitor(visitor, metadata, newCommand);
+ int determinismLevel = copy.resetDeterminismLevel();
+ newCommand = QueryRewriter.rewrite(newCommand, metadata, copy);
+ AnalysisRecord record = new AnalysisRecord(false, false);
+ ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, finder, record, copy);
+ pp = new PreparedPlan();
+ pp.setPlan(plan);
+ pp.setReferences(references);
+ pp.setAnalysisRecord(record);
+ pp.setCommand(newCommand);
+ commandContext.putPlan(query, pp, copy.getDeterminismLevel());
+ copy.setDeterminismLevel(determinismLevel);
+ }
+ copy.pushVariableContext(new VariableContext());
+ PreparedStatementRequest.resolveParameterValues(pp.getReferences(), Arrays.asList(params), copy, metadata);
+ return new QueryProcessor(pp.getPlan().clone(), copy, bufferMgr, dataMgr);
+ }
+}
Property changes on: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/QueryProcessorFactoryImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -96,7 +96,7 @@
/**
* Server side representation of the RequestMessage. Knows how to process itself.
*/
-public class Request implements QueryProcessor.ProcessorFactory {
+public class Request {
// init state
protected RequestMessage requestMsg;
@@ -130,6 +130,7 @@
protected boolean returnsUpdateCount;
protected boolean useEntitlements;
private TempTableStore globalTables;
+ private SessionAwareCache<PreparedPlan> planCache;
void initialize(RequestMessage requestMsg,
BufferManager bufferManager,
@@ -137,7 +138,8 @@
TransactionService transactionService,
TempTableStore tempTableStore,
DQPWorkContext workContext,
- boolean useEntitlements) {
+ boolean useEntitlements,
+ SessionAwareCache<PreparedPlan> planCache) {
this.requestMsg = requestMsg;
this.vdbName = workContext.getVdbName();
@@ -151,6 +153,7 @@
this.requestId = workContext.getRequestID(this.requestMsg.getExecutionId());
this.connectorManagerRepo = workContext.getVDB().getAttachment(ConnectorManagerRepository.class);
this.useEntitlements = useEntitlements;
+ this.planCache = planCache;
}
void setMetadata(CapabilitiesFinder capabilitiesFinder, QueryMetadataInterface metadata, Set multiSourceModels) {
@@ -253,9 +256,10 @@
}
});
context.setTempTableStore(tempTableStore);
- context.setQueryProcessorFactory(this);
+ context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(this.bufferManager, this.processorDataManager, this.capabilitiesFinder, idGenerator, metadata));
context.setMetadata(this.metadata);
context.setBufferManager(this.bufferManager);
+ context.setPreparedPlanCache(planCache);
}
protected void checkReferences(List<Reference> references) throws QueryValidatorException {
@@ -449,27 +453,6 @@
}
this.context.setValidateXML(requestMsg.getValidationMode());
}
-
- public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException {
- ParseInfo parseInfo = new ParseInfo();
- Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
- QueryResolver.resolveCommand(newCommand, metadata);
-
- List<Reference> references = ReferenceCollectorVisitor.getReferences(newCommand);
-
- referenceCheck(references);
-
- validateQuery(newCommand);
-
- CommandContext copy = commandContext.clone();
- if (recursionGroup != null) {
- copy.pushCall(recursionGroup);
- }
-
- newCommand = QueryRewriter.rewrite(newCommand, metadata, copy);
- ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, capabilitiesFinder, analysisRecord, copy);
- return new QueryProcessor(plan, copy, bufferManager, processorDataManager);
- }
protected void validateAccess(Command command) throws QueryValidatorException, TeiidComponentException {
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.workContext.getVDB(), this.useEntitlements, this.workContext.getAllowedDataPolicies(), this.workContext.getUserName());
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -336,8 +336,8 @@
SessionAwareCache<CachedResults> rsCache = dqpCore.getRsCache();
ParseInfo pi = Request.createParseInfo(requestMsg);
CacheID cacheId = new CacheID(this.dqpWorkContext, pi, requestMsg.getCommandString());
- cacheId.setParameters(requestMsg.getParameterValues());
- if (rsCache != null) {
+ boolean cachable = cacheId.setParameters(requestMsg.getParameterValues());
+ if (rsCache != null && cachable) {
CachedResults cr = rsCache.get(cacheId);
if (cr != null && (requestMsg.useResultSetCache() || cr.getHint() != null)) {
this.resultsBuffer = cr.getResults();
@@ -351,7 +351,7 @@
}
request.processRequest();
originalCommand = request.userCommand;
- if ((requestMsg.useResultSetCache() || originalCommand.getCacheHint() != null) && rsCache != null && originalCommand.areResultsCachable()) {
+ if (cachable && (requestMsg.useResultSetCache() || originalCommand.getCacheHint() != null) && rsCache != null && originalCommand.areResultsCachable()) {
this.cid = cacheId;
}
processor = request.processor;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -57,7 +57,7 @@
private BufferManager bufferManager;
- SessionAwareCache(){
+ public SessionAwareCache(){
this(new DefaultCacheFactory(), Cache.Type.RESULTSET, new CacheConfiguration(Policy.LRU, 60, DEFAULT_MAX_SIZE_TOTAL));
}
@@ -114,15 +114,7 @@
return cacheHit.get();
}
- public void put(CacheID id, int determinismLevel, T t){
- this.put(id, determinismLevel, t, null);
- }
-
public void put(CacheID id, int determinismLevel, T t, Long ttl){
- if (!id.cachable) {
- return;
- }
-
if (determinismLevel >= FunctionMethod.SESSION_DETERMINISTIC) {
id.setSessionId(id.originalSessionId);
this.localCache.put(id, t, ttl);
@@ -160,7 +152,7 @@
this.distributedCache.clear();
}
- static class CacheID implements Serializable {
+ public static class CacheID implements Serializable {
private static final long serialVersionUID = 8261905111156764744L;
private String sql;
private VDBKey vdbInfo;
@@ -170,39 +162,52 @@
private List<Serializable> parameters;
private String userName;
private String originalUserName;
- private boolean cachable = true;
-
- CacheID(DQPWorkContext context, ParseInfo pi, String sql){
+
+ public CacheID(DQPWorkContext context, ParseInfo pi, String sql){
+ this(pi, sql, context.getVdbName(), context.getVdbVersion(), context.getSessionId(), context.getUserName());
+ }
+
+ public CacheID(ParseInfo pi, String sql, String vdbName, int vdbVersion, String sessionId, String userName){
this.sql = sql;
- this.vdbInfo = new VDBKey(context.getVdbName(), context.getVdbVersion());
+ this.vdbInfo = new VDBKey(vdbName, vdbVersion);
this.pi = pi;
- this.originalSessionId = context.getSessionId();
- this.originalUserName = context.getUserName();
+ this.originalSessionId = sessionId;
+ this.originalUserName = userName;
}
+
+ public String getSessionId() {
+ return sessionId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
private void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
- public void setParameters(List<?> parameters) {
+ public boolean setParameters(List<?> parameters) {
if (parameters != null && !parameters.isEmpty()) {
this.parameters = new ArrayList<Serializable>();
for (Object obj:parameters) {
- if (obj instanceof Serializable) {
+ if (obj instanceof Serializable && obj instanceof Comparable<?>) {
this.parameters.add((Serializable)obj);
}
else{
- this.cachable = false;
+ return false;
}
}
}
+ return true;
}
public String getSql() {
return sql;
}
- public void setUserName(String name) {
+ void setUserName(String name) {
this.userName = name;
}
@@ -214,7 +219,7 @@
return false;
}
CacheID that = (CacheID)obj;
- return this.pi.equals(that.pi) && this.vdbInfo.equals(that.vdbInfo) && this.sql.equals(that.sql)
+ return EquivalenceUtil.areEqual(this.pi, that.pi) && this.vdbInfo.equals(that.vdbInfo) && this.sql.equals(that.sql)
&& EquivalenceUtil.areEqual(this.userName, that.userName)
&& EquivalenceUtil.areEqual(this.sessionId, that.sessionId)
&& EquivalenceUtil.areEqual(this.parameters, that.parameters);
@@ -228,6 +233,7 @@
public String toString() {
return "Cache Entry<" + originalSessionId + "="+ originalUserName + "> params:" + parameters + " sql:" + sql; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
+
}
//for testing purpose
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,8 +22,6 @@
package org.teiid.query.optimizer;
-import java.util.Map;
-
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
@@ -48,9 +46,6 @@
import org.teiid.query.processor.proc.WhileInstruction;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.DynamicCommand;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.TranslatableProcedureContainer;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
@@ -92,7 +87,7 @@
analysisRecord.println("PROCEDURE COMMAND: " + procCommand); //$NON-NLS-1$
}
- Assertion.isInstanceOf(procCommand, CreateUpdateProcedureCommand.class, "Wrong command type"); //$NON-NLS-1$
+ CreateUpdateProcedureCommand cupc = Assertion.isInstanceOf(procCommand, CreateUpdateProcedureCommand.class, "Wrong command type"); //$NON-NLS-1$
if(debug) {
analysisRecord.println("OPTIMIZING SUB-COMMANDS: "); //$NON-NLS-1$
@@ -104,35 +99,20 @@
}
}
- Block block = ((CreateUpdateProcedureCommand) procCommand).getBlock();
+ Block block = cupc.getBlock();
- Program programBlock = planBlock(((CreateUpdateProcedureCommand)procCommand), block, metadata, debug, idGenerator, capFinder, analysisRecord, context);
+ Program programBlock = planBlock(cupc, block, metadata, debug, idGenerator, capFinder, analysisRecord, context);
if(debug) {
analysisRecord.println("\n####################################################"); //$NON-NLS-1$
}
-
+
// create plan from program and initialized environment
ProcedurePlan plan = new ProcedurePlan(programBlock);
- // propagate procedure parameters to the plan to allow runtime type checking
- ProcedureContainer container = (ProcedureContainer)((CreateUpdateProcedureCommand) procCommand).getUserCommand();
+ plan.setUpdateProcedure(cupc.isUpdateProcedure());
+ plan.setOutputElements(cupc.getProjectedSymbols());
- if (container != null) {
- if (container instanceof StoredProcedure) {
- plan.setRequiresTransaction(container.getUpdateCount() > 0);
- }
- Map params = container.getProcedureParameters();
- plan.setParams(params);
- plan.setMetadata(metadata);
- if (container instanceof TranslatableProcedureContainer) {
- plan.setImplicitParams(((TranslatableProcedureContainer)container).getImplicitParams());
- }
- }
-
- plan.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
- plan.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
-
if(debug) {
analysisRecord.println("####################################################"); //$NON-NLS-1$
analysisRecord.println("PROCEDURE PLAN :"+plan); //$NON-NLS-1$
@@ -148,8 +128,8 @@
* @param block The <code>Block</code> to be planned
* @param metadata Metadata used during planning
* @param childNodes list of CommandTreeNode objects that contain the ProcessorPlans of the child nodes of this procedure
- * @param debug Boolean detemining if procedure plan needs to be printed for debug purposes
- * @param analysisRecord TODO
+ * @param debug Boolean determining if procedure plan needs to be printed for debug purposes
+ * @param analysisRecord
* @return A Program resulting in the block planning
* @throws QueryPlannerException if invalid statement is encountered in the block
* @throws QueryMetadataException if there is an error accessing metadata
@@ -183,14 +163,14 @@
/**
* <p> Plan a {@link Statement} object, depending on the type of the statement construct the appropriate
* {@link ProgramInstruction} return it to added to a {@link Program}. If the statement references a
- * <code>Command</code>, it looks up the child CommandTreeNodes to get approproiate child's ProcessrPlan
+ * <code>Command</code>, it looks up the child CommandTreeNodes to get appropriate child's ProcessrPlan
* and uses it for constructing the necessary instruction.</p>
* @param statement The statement to be planned
* @param metadata Metadata used during planning
* @param childNodes list of CommandTreeNode objects that contain the ProcessorPlans of the child nodes of this procedure
- * @param debug Boolean detemining if procedure plan needs to be printed for debug purposes
- * @param analysisRecord TODO
- * @return An array containing index of the next child to be accessesd and the ProgramInstruction resulting
+ * @param debug Boolean determining if procedure plan needs to be printed for debug purposes
+ * @param analysisRecord
+ * @return An array containing index of the next child to be accessed and the ProgramInstruction resulting
* in the statement planning
* @throws QueryPlannerException if invalid statement is encountered
* @throws QueryMetadataException if there is an error accessing metadata
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,15 +22,18 @@
package org.teiid.query.optimizer;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.id.IDGenerator;
import org.teiid.core.id.IntegerIDFactory;
+import org.teiid.dqp.internal.process.PreparedPlan;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempCapabilitiesFinder;
@@ -40,20 +43,23 @@
import org.teiid.query.optimizer.relational.RelationalPlanner;
import org.teiid.query.optimizer.xml.XMLPlanner;
import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.proc.ProcedurePlan;
import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.TranslatableProcedureContainer;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.util.CommandContext;
/**
* <p>This Class produces a ProcessorPlan object (a plan for query execution) from a
* user's command and a source of metadata.</p>
- *
- * <p>The user's Command object may in fact be a tree of commands and subcommands.
- * This component is architected to defer to the proper
- * {@link CommandPlanner CommandPlanner} implementation to plan each Command in the
- * tree.</p>
*/
public class QueryOptimizer {
@@ -65,7 +71,7 @@
private QueryOptimizer() {}
public static ProcessorPlan optimizePlan(Command command, QueryMetadataInterface metadata, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
- throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
+ throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
if (analysisRecord == null) {
analysisRecord = new AnalysisRecord(false, false);
@@ -98,7 +104,37 @@
ProcessorPlan result = null;
if (command.getType() == Command.TYPE_UPDATE_PROCEDURE){
- result = PROCEDURE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
+ CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)command;
+ if (cupc.isUpdateProcedure()) {
+ result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
+ } else {
+ String fullName = metadata.getFullName(cupc.getVirtualGroup().getMetadataID());
+ PreparedPlan pp = context.getPlan(fullName);
+ if (pp == null) {
+ int determinismLevel = context.resetDeterminismLevel();
+ ProcessorPlan plan = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
+ //note that this is not a full prepared plan. It is not usable by user queries.
+ pp = new PreparedPlan();
+ pp.setPlan(plan);
+ context.putPlan(fullName, pp, context.getDeterminismLevel());
+ context.setDeterminismLevel(determinismLevel);
+ }
+ result = pp.getPlan().clone();
+ }
+ // propagate procedure parameters to the plan to allow runtime type checking
+ ProcedureContainer container = (ProcedureContainer)cupc.getUserCommand();
+ ProcedurePlan plan = (ProcedurePlan)result;
+ if (container != null) {
+ LinkedHashMap<ElementSymbol, Expression> params = container.getProcedureParameters();
+ if (container instanceof StoredProcedure) {
+ plan.setRequiresTransaction(container.getUpdateCount() > 0);
+ }
+ plan.setParams(params);
+ plan.setMetadata(metadata);
+ if (container instanceof TranslatableProcedureContainer) {
+ plan.setImplicitParams(((TranslatableProcedureContainer)container).getImplicitParams());
+ }
+ }
} else if (command.getType() == Command.TYPE_BATCHED_UPDATE){
result = BATCHED_UPDATE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
} else {
@@ -124,5 +160,20 @@
return result;
}
+
+ private static ProcessorPlan planProcedure(Command command,
+ QueryMetadataInterface metadata, IDGenerator idGenerator,
+ CapabilitiesFinder capFinder, AnalysisRecord analysisRecord,
+ CommandContext context) throws TeiidComponentException,
+ QueryPlannerException, QueryMetadataException {
+ ProcessorPlan result;
+ try {
+ command = QueryRewriter.rewrite(command, metadata, context);
+ } catch (TeiidProcessingException e) {
+ throw new QueryPlannerException(e, e.getMessage());
+ }
+ result = PROCEDURE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
+ return result;
+ }
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -44,8 +44,6 @@
import org.teiid.core.id.IDGenerator;
import org.teiid.dqp.internal.process.Request;
import org.teiid.language.SQLConstants;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.execution.QueryExecPlugin;
@@ -485,8 +483,9 @@
}
}
if (c != null) {
- c = QueryRewriter.rewrite(c, metadata, context);
- addNestedCommand(sourceNode, container.getGroup(), container, c, false);
+ //skip the rewrite here, we'll do that in the optimizer
+ //so that we know what the determinism level is.
+ addNestedCommand(sourceNode, container.getGroup(), container, c, false);
}
}
@@ -1034,15 +1033,10 @@
//only OPTION NOCACHE, no group specified
return true;
}
+ String fullName = metadata.getFullName(metadataID);
for (String groupName : option.getNoCacheGroups()) {
- try {
- Object noCacheGroupID = metadata.getGroupID(groupName);
- if(metadataID.equals(noCacheGroupID)){
- return true;
- }
- } catch (QueryMetadataException e) {
- //log that an unknown groups was used in the no cache
- LogManager.logWarning(LogConstants.CTX_QUERY_RESOLVER, e, QueryPlugin.Util.getString("SimpleQueryResolver.unknown_group_in_nocache", groupName)); //$NON-NLS-1$
+ if(groupName.equalsIgnoreCase(fullName)){
+ return true;
}
}
return false;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -107,7 +107,7 @@
}
// lookup mapping node for the user command
- GroupSymbol group = (GroupSymbol)xmlQuery.getFrom().getGroups().iterator().next();
+ GroupSymbol group = xmlQuery.getFrom().getGroups().iterator().next();
MappingDocument doc = (MappingDocument)metadata.getMappingNode(group.getMetadataID());
doc = (MappingDocument)doc.clone();
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -106,39 +106,23 @@
throw new QueryParserException(QueryPlugin.Util.getString("QueryParser.emptysql")); //$NON-NLS-1$
}
- try {
- Command result = parseCommandWithParser(sql, parseInfo);
- if (parseInfo.cacheHint != null) {
- result.setCacheHint(parseInfo.cacheHint);
- }
- return result;
- } catch (QueryParserException e) {
- if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
- throw new QueryParserException(e, QueryPlugin.Util.getString("QueryParser.xqueryCompilation", sql)); //$NON-NLS-1$
- }
- throw e;
- }
- }
-
- /**
- * Parse the String sql into a Command using the MetaMatrix parser.
- * @param sql to parse
- * @return parsed Command
- * @throws QueryParserException
- */
- private Command parseCommandWithParser(String sql, ParseInfo parseInfo) throws QueryParserException {
- Command result = null;
+ Command result = null;
try{
result = getSqlParser(sql).command(parseInfo);
-
+ result.setCacheHint(SQLParserUtil.getQueryCacheOption(sql));
} catch(ParseException pe) {
+ if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
+ throw new QueryParserException(pe, QueryPlugin.Util.getString("QueryParser.xqueryCompilation", sql)); //$NON-NLS-1$
+ }
throw convertParserException(pe);
-
} catch(TokenMgrError tme) {
+ if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
+ throw new QueryParserException(tme, QueryPlugin.Util.getString("QueryParser.xqueryCompilation", sql)); //$NON-NLS-1$
+ }
handleTokenMgrError(tme);
}
- return result;
- }
+ return result;
+ }
/**
* Takes a SQL string representing an SQL criteria (i.e. just the WHERE
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -189,25 +189,25 @@
return hint;
}
- private static Pattern CACHE_HINT = Pattern.compile("\\s*cache(\\(\\s*(pref_mem)?\\s*(ttl:\\d{1,19})?\\s*(updatable)?[^)]*\\))?.*", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern CACHE_HINT = Pattern.compile("/\\*\\+?\\s*cache(\\(\\s*(pref_mem)?\\s*(ttl:\\d{1,19})?\\s*(updatable)?[^\\)]*\\))?[^\\*]*\\*\\/.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); //$NON-NLS-1$
- void setQueryCacheOption(Token t, ParseInfo p) {
- String hint = getComment(t);
-
- Matcher match = CACHE_HINT.matcher(hint);
+ static CacheHint getQueryCacheOption(String query) {
+ Matcher match = CACHE_HINT.matcher(query);
if (match.matches()) {
- p.cacheHint = new CacheHint();
+ CacheHint hint = new CacheHint();
if (match.group(2) !=null) {
- p.cacheHint.setPrefersMemory(true);
+ hint.setPrefersMemory(true);
}
String ttl = match.group(3);
if (ttl != null) {
- p.cacheHint.setTtl(Long.valueOf(ttl.substring(4)));
+ hint.setTtl(Long.valueOf(ttl.substring(4)));
}
if (match.group(4) != null) {
- p.cacheHint.setUpdatable(true);
+ hint.setUpdatable(true);
}
+ return hint;
}
+ return null;
}
/**
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -54,7 +54,7 @@
private static ExpiredTimeSliceException EXPIRED_TIME_SLICE = new ExpiredTimeSliceException();
public interface ProcessorFactory {
- QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException;
+ QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException;
}
private CommandContext context;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -69,10 +70,10 @@
*/
public class ProcedurePlan extends ProcessorPlan {
- public static class CursorState {
- private QueryProcessor processor;
- private IndexedTupleSource ts;
- private List<?> currentRow;
+ private static class CursorState {
+ QueryProcessor processor;
+ IndexedTupleSource ts;
+ List<?> currentRow;
}
private Program originalProgram;
@@ -91,7 +92,7 @@
private int beginBatch = 1;
private List batchRows;
private boolean lastBatch = false;
- private Map<ElementSymbol, Expression> params;
+ private LinkedHashMap<ElementSymbol, Expression> params;
private Map<ElementSymbol, Reference> implicitParams;
private QueryMetadataInterface metadata;
@@ -191,7 +192,7 @@
if (value == null && !metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
throw new QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam", expr)); //$NON-NLS-1$
}
- context.setValue(param, value);
+ setParameterValue(param, context, value);
}
}
if (this.implicitParams != null) {
@@ -207,6 +208,11 @@
this.evaluatedParams = true;
}
+ protected void setParameterValue(ElementSymbol param,
+ VariableContext context, Object value) {
+ context.setValue(param, value);
+ }
+
/**
* @see ProcessorPlan#nextBatch()
*/
@@ -378,7 +384,7 @@
this.metadata = metadata;
}
- public void setParams( Map<ElementSymbol, Expression> params ) {
+ public void setParams( LinkedHashMap<ElementSymbol, Expression> params ) {
this.params = params;
}
@@ -539,7 +545,6 @@
}
}
-
/**
* Get the schema from the tuple source that
* represents the columns in a result set
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -45,7 +45,6 @@
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.resolver.ProcedureContainerResolver;
import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.resolver.VariableResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.lang.Command;
@@ -63,7 +62,7 @@
/**
*/
-public class ExecResolver extends ProcedureContainerResolver implements VariableResolver {
+public class ExecResolver extends ProcedureContainerResolver {
/**
* @see org.teiid.query.resolver.CommandResolver#findCommandMetadata(org.teiid.query.sql.lang.Command,
@@ -217,7 +216,7 @@
// Create temporary metadata that defines a group based on either the stored proc
// name or the stored query name - this will be used later during planning
- String procName = storedProcedureCommand.getProcedureName();
+ String procName = metadata.getFullName(storedProcedureCommand.getProcedureID());
GroupContext context = new GroupContext();
@@ -291,29 +290,7 @@
QueryResolverException {
//Do nothing
}
-
- /**
- * Collect input expressions from a procedure and map them to the parameters they came from
- * @param command Procedure to collect input expressions from
- * @return Map of param name (full upper case) to Expression
- */
- public Map getVariableValues(Command command, QueryMetadataInterface metadata) {
- StoredProcedure proc = (StoredProcedure)command;
- List oldParams = proc.getInputParameters();
- Map inputMap = new HashMap();
-
- Iterator oldParamIter = oldParams.iterator();
- while(oldParamIter.hasNext()) {
- SPParameter param = (SPParameter) oldParamIter.next();
- String paramName = proc.getParamFullName(param).toUpperCase();
- Expression expr = param.getExpression();
- inputMap.put(paramName, expr);
- }
-
- return inputMap;
- }
-
/**
* @see org.teiid.query.resolver.ProcedureContainerResolver#getPlan(org.teiid.query.metadata.QueryMetadataInterface, org.teiid.query.sql.symbol.GroupSymbol)
*/
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -24,10 +24,13 @@
import java.io.Serializable;
+import org.teiid.core.util.EquivalenceUtil;
import org.teiid.query.sql.visitor.SQLStringVisitor;
public class CacheHint implements Serializable {
+ private static final long serialVersionUID = -4119606289701982511L;
+
public static final String PREF_MEM = "pref_mem"; //$NON-NLS-1$
public static final String TTL = "ttl:"; //$NON-NLS-1$
public static final String UPDATABLE = "updatable"; //$NON-NLS-1$
@@ -75,5 +78,19 @@
public void setUpdatable(boolean updatable) {
this.updatable = updatable;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof CacheHint)) {
+ return false;
+ }
+ CacheHint other = (CacheHint)obj;
+ return this.prefersMemory == other.prefersMemory
+ && EquivalenceUtil.areEqual(this.ttl, other.ttl)
+ && this.updatable == other.updatable;
+ }
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -32,6 +32,7 @@
import java.util.Map;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.EquivalenceUtil;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -334,4 +335,9 @@
public String toString() {
return SQLStringVisitor.getSQLString(this);
}
+
+ protected boolean sameOptionAndHint(Command cmd) {
+ return EquivalenceUtil.areEqual(this.cacheHint, cmd.cacheHint) &&
+ EquivalenceUtil.areEqual(this.option, cmd.option);
+ }
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Delete.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Delete.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Delete.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,13 +22,14 @@
package org.teiid.query.sql.lang;
-import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -167,8 +168,8 @@
* @see org.teiid.query.sql.lang.ProcedureContainer#getParameters()
* @since 5.0
*/
- public Map getProcedureParameters() {
- return Collections.EMPTY_MAP;
+ public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
+ return new LinkedHashMap<ElementSymbol, Expression>();
}
/**
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Insert.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Insert.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Insert.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -23,11 +23,10 @@
package org.teiid.query.sql.lang;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.util.EquivalenceUtil;
@@ -50,11 +49,8 @@
/** Identifies the group to be udpdated. */
private GroupSymbol group;
- /** list of column variables, null = all columns */
- private List variables = new LinkedList();
-
- /** List of Expressions */
- private List values = new LinkedList();
+ private List<ElementSymbol> variables = new LinkedList<ElementSymbol>();
+ private List<Expression> values = new LinkedList<Expression>();
private QueryCommand queryExpression;
@@ -234,14 +230,13 @@
* @see org.teiid.query.sql.lang.ProcedureContainer#getParameters()
* @since 5.0
*/
- public Map getProcedureParameters() {
+ public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
int iSize = getVariables().size();
- HashMap map = new HashMap();
+ LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
for (int j = 0; j < iSize; j++) {
- ElementSymbol symbol = (ElementSymbol)((ElementSymbol)variables.get( j )).clone();
- symbol = (ElementSymbol)((ElementSymbol)variables.get( j )).clone();
+ ElementSymbol symbol = (ElementSymbol)variables.get( j ).clone();
symbol.setName(ProcedureReservedWords.INPUTS + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
map.put(symbol, values.get( j ) );
} // for
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/ProcedureContainer.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,8 +22,10 @@
package org.teiid.query.sql.lang;
-import java.util.Map;
+import java.util.LinkedHashMap;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -59,5 +61,5 @@
this.updateCount = updateCount;
}
- public abstract Map getProcedureParameters();
+ public abstract LinkedHashMap<ElementSymbol, Expression> getProcedureParameters();
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Query.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Query.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Query.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -23,6 +23,7 @@
package org.teiid.query.sql.lang;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -373,12 +374,10 @@
* @return True if equal
*/
public boolean equals(Object obj) {
- // Quick same object test
if(this == obj) {
return true;
}
- // Quick fail tests
if(!(obj instanceof Query)) {
return false;
}
@@ -392,8 +391,8 @@
EquivalenceUtil.areEqual(getHaving(), other.getHaving()) &&
EquivalenceUtil.areEqual(getOrderBy(), other.getOrderBy()) &&
EquivalenceUtil.areEqual(getLimit(), other.getLimit()) &&
- EquivalenceUtil.areEqual(getOption(), other.getOption()) &&
- getIsXML() == other.getIsXML();
+ getIsXML() == other.getIsXML() &&
+ sameOptionAndHint(other);
}
/**
@@ -426,9 +425,8 @@
return areResultsCachable(projectedSymbols);
}
- static boolean areResultsCachable(List projectedSymbols) {
- for(int i=0; i<projectedSymbols.size(); i++){
- SingleElementSymbol projectedSymbol = (SingleElementSymbol)projectedSymbols.get(i);
+ public static boolean areResultsCachable(Collection<? extends SingleElementSymbol> projectedSymbols) {
+ for (SingleElementSymbol projectedSymbol : projectedSymbols) {
if(DataTypeManager.isLOB(projectedSymbol.getType()) || projectedSymbol.getType() == DataTypeManager.DefaultDataClasses.OBJECT) {
return false;
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SPParameter.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SPParameter.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SPParameter.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -29,10 +29,8 @@
import java.util.List;
import org.teiid.client.metadata.ParameterInfo;
-import org.teiid.core.TeiidException;
-import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.EquivalenceUtil;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.eval.Evaluator;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.util.ErrorMessageKeys;
@@ -303,7 +301,7 @@
return true;
}
- if(obj == null || !(obj instanceof SPParameter)){
+ if(!(obj instanceof SPParameter)){
return false;
}
@@ -314,11 +312,7 @@
}
// If indexes match, check associated IDs if existent
- if (this.getMetadataID() != null && other.getMetadataID() != null) {
- return this.getMetadataID().equals(other.getMetadataID());
- }
-
- return true;
+ return EquivalenceUtil.areEqual(this.expression, other.expression);
}
/**
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SetQuery.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SetQuery.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/SetQuery.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -213,7 +213,7 @@
EquivalenceUtil.areEqual(this.rightQuery, other.rightQuery) &&
EquivalenceUtil.areEqual(getOrderBy(), other.getOrderBy()) &&
EquivalenceUtil.areEqual(getLimit(), other.getLimit()) &&
- EquivalenceUtil.areEqual(getOption(), other.getOption());
+ sameOptionAndHint(other);
}
/**
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -35,6 +36,7 @@
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.util.ErrorMessageKeys;
@@ -300,7 +302,7 @@
*/
@Override
public int hashCode() {
- return this.toString().hashCode();
+ return this.getGroup().hashCode();
}
public boolean equals(Object obj) {
@@ -314,7 +316,11 @@
return false;
}
- return this.toString().equals(obj.toString());
+ StoredProcedure other = (StoredProcedure)obj;
+
+ return sameOptionAndHint(other) &&
+ this.getGroup().equals(other.getGroup()) &&
+ this.mapOfParameters.equals(other.mapOfParameters);
}
public void clearParameters(){
@@ -407,9 +413,9 @@
* @see org.teiid.query.sql.lang.ProcedureContainer#getProcedureParameters()
* @since 5.0
*/
- public Map getProcedureParameters() {
+ public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
- HashMap map = new HashMap();
+ LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
for (Iterator iter = this.getInputParameters().iterator(); iter.hasNext();) {
SPParameter element = (SPParameter)iter.next();
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Update.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Update.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/Update.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,10 +22,9 @@
package org.teiid.query.sql.lang;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
@@ -259,14 +258,13 @@
* @see org.teiid.query.sql.lang.ProcedureContainer#getProcedureParameters()
* @since 5.0
*/
- public Map getProcedureParameters() {
+ public LinkedHashMap<ElementSymbol, Expression> getProcedureParameters() {
- HashMap map = new HashMap();
+ LinkedHashMap<ElementSymbol, Expression> map = new LinkedHashMap<ElementSymbol, Expression>();
for (Iterator iter = getChangeList().getClauses().iterator(); iter.hasNext();) {
SetClause setClause = (SetClause)iter.next();
ElementSymbol symbol = (ElementSymbol)(setClause.getSymbol()).clone();
- symbol = (ElementSymbol)(setClause.getSymbol()).clone();
symbol.setName(ProcedureReservedWords.INPUTS + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
map.put( symbol, setClause.getValue() );
} // for
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -32,6 +32,7 @@
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -185,9 +186,11 @@
if(! (obj instanceof CreateUpdateProcedureCommand)) {
return false;
}
+
+ CreateUpdateProcedureCommand other = (CreateUpdateProcedureCommand)obj;
// Compare the block
- return EquivalenceUtil.areEqual(getBlock(), ((CreateUpdateProcedureCommand)obj).getBlock());
+ return sameOptionAndHint(other) && EquivalenceUtil.areEqual(getBlock(), other.getBlock());
}
/**
@@ -279,7 +282,7 @@
if(isUpdateProcedure()){
return false;
}
- return true;
+ return Query.areResultsCachable(getProjectedSymbols());
}
public GroupSymbol getVirtualGroup() {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -248,8 +248,8 @@
Constant key = (Constant)proc.getParameter(2).getExpression();
LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryExecPlugin.Util.getString("TempTableDataManager.row_refresh", matViewName, key)); //$NON-NLS-1$
String queryString = Reserved.SELECT + " * " + Reserved.FROM + ' ' + matViewName + ' ' + Reserved.WHERE + ' ' + //$NON-NLS-1$
- metadata.getFullName(ids.iterator().next()) + '=' + key.toString() + ' ' + Reserved.OPTION + ' ' + Reserved.NOCACHE;
- QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(queryString, matViewName.toUpperCase(), context);
+ metadata.getFullName(ids.iterator().next()) + " = ?" + ' ' + Reserved.OPTION + ' ' + Reserved.NOCACHE; //$NON-NLS-1$
+ QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(queryString, matViewName.toUpperCase(), context, key.getValue());
qp.setNonBlocking(true);
TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
tempTable = globalStore.getOrCreateTempTable(matTableName, new Query(), bufferManager, false);
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -33,11 +33,16 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.ArgCheck;
+import org.teiid.dqp.internal.process.PreparedPlan;
+import org.teiid.dqp.internal.process.SessionAwareCache;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.query.QueryPlugin;
import org.teiid.query.eval.SecurityFunctionEvaluator;
import org.teiid.query.execution.QueryExecPlugin;
+import org.teiid.query.function.metadata.FunctionMethod;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.relational.PlanToProcessConverter;
+import org.teiid.query.parser.ParseInfo;
import org.teiid.query.processor.QueryProcessor;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -67,7 +72,7 @@
private Serializable commandPayload;
- private String vdbName;
+ private String vdbName = ""; //$NON-NLS-1$
private int vdbVersion;
@@ -101,6 +106,8 @@
private BufferManager bufferManager;
private TempTableStore globalTables;
+
+ private SessionAwareCache<PreparedPlan> planCache;
}
private GlobalState globalState = new GlobalState();
@@ -136,13 +143,23 @@
}
- public CommandContext() {
+ public CommandContext() {
}
+ private CommandContext(GlobalState state) {
+ this.globalState = state;
+ }
+
public int getDeterminismLevel() {
return globalState.determinismLevel;
}
+ public int resetDeterminismLevel() {
+ int result = globalState.determinismLevel;
+ globalState.determinismLevel = 0;
+ return result;
+ }
+
public void setDeterminismLevel(int level) {
globalState.determinismLevel = Math.max(globalState.determinismLevel, level);
}
@@ -163,8 +180,7 @@
}
public CommandContext clone() {
- CommandContext clone = new CommandContext();
- clone.globalState = this.globalState;
+ CommandContext clone = new CommandContext(this.globalState);
clone.variableContext = this.variableContext;
clone.tempTableStore = this.tempTableStore;
if (this.recursionStack != null) {
@@ -454,5 +470,34 @@
public void setNonBlocking(boolean nonBlocking) {
this.nonBlocking = nonBlocking;
}
+
+ public void setPreparedPlanCache(SessionAwareCache<PreparedPlan> cache) {
+ this.globalState.planCache = cache;
+ }
+
+ public PreparedPlan getPlan(String key) {
+ if (this.globalState.planCache == null) {
+ return null;
+ }
+ CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionID(), getUserName());
+ PreparedPlan pp = this.globalState.planCache.get(id);
+ if (pp != null) {
+ if (id.getSessionId() != null) {
+ setDeterminismLevel(FunctionMethod.USER_DETERMINISTIC);
+ } else if (id.getUserName() != null) {
+ setDeterminismLevel(FunctionMethod.SESSION_DETERMINISTIC);
+ }
+ return pp;
+ }
+ return null;
+ }
+
+ public void putPlan(String key, PreparedPlan plan, int determinismLevel) {
+ if (this.globalState.planCache == null) {
+ return;
+ }
+ CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionID(), getUserName());
+ this.globalState.planCache.put(id, determinismLevel, plan, null);
+ }
}
Modified: branches/7.1.x/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- branches/7.1.x/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-25 16:18:52 UTC (rev 2490)
@@ -1171,17 +1171,10 @@
StoredProcedure storedProcedure = new StoredProcedure();
String procName = null;
Option option = null;
- Token execToken = null;
}
{
(
- (
- (execToken = <EXEC> { setQueryCacheOption(execToken, info); })
- |
- (execToken = <EXECUTE> { setQueryCacheOption(execToken, info); })
- |
- (execToken = <CALL> { setQueryCacheOption(execToken, info); })
- )
+ (<EXEC> | <EXECUTE> | <CALL>)
procName = id()
{
storedProcedure.setProcedureName(procName);
@@ -1594,13 +1587,9 @@
SelectSymbol symbol = null;
Select select = new Select();
info.aggregatesAllowed = true;
- Token selectToken = null;
}
{
- selectToken = <SELECT>
- {
- setQueryCacheOption(selectToken, info);
- }
+ <SELECT>
[<ALL> | (<DISTINCT> {isDistinct=true;})]
(<STAR>
{
Deleted: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -1,75 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.process;
-
-import org.teiid.common.buffer.BufferManager;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.id.IDGenerator;
-import org.teiid.query.analysis.AnalysisRecord;
-import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.optimizer.QueryOptimizer;
-import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
-import org.teiid.query.parser.QueryParser;
-import org.teiid.query.processor.ProcessorDataManager;
-import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.QueryProcessor;
-import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.rewriter.QueryRewriter;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.util.CommandContext;
-
-
-
-public class SimpleQueryProcessorFactory implements QueryProcessor.ProcessorFactory {
-
- private QueryMetadataInterface metadata;
- private CapabilitiesFinder finder;
- private IDGenerator idGenerator;
- private BufferManager bufferMgr;
- private ProcessorDataManager dataMgr;
-
- public SimpleQueryProcessorFactory(BufferManager bufferMgr,
- ProcessorDataManager dataMgr, CapabilitiesFinder finder,
- IDGenerator idGenerator, QueryMetadataInterface metadata) {
- this.bufferMgr = bufferMgr;
- this.dataMgr = dataMgr;
- this.finder = finder;
- this.idGenerator = idGenerator;
- this.metadata = metadata;
- }
-
- @Override
- public QueryProcessor createQueryProcessor(String sql, String recursionGroup, CommandContext commandContext)
- throws TeiidProcessingException, TeiidComponentException {
- Command command = QueryParser.getQueryParser().parseCommand(sql);
- QueryResolver.resolveCommand(command, metadata);
- command = QueryRewriter.rewrite(command, metadata, commandContext);
- ProcessorPlan plan = QueryOptimizer.optimizePlan(command, metadata,
- idGenerator, finder, AnalysisRecord.createNonRecordingRecord(),
- commandContext);
-
- CommandContext copy = commandContext.clone();
- return new QueryProcessor(plan, copy, bufferMgr, dataMgr);
- }
-}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -94,7 +94,7 @@
context.setProcessorID(requestID);
context.setVdbName("test"); //$NON-NLS-1$
context.setVdbVersion(1);
- context.setQueryProcessorFactory(new SimpleQueryProcessorFactory(bs.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata));
+ context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bs.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata));
workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext);
request = new AtomicRequestMessage(original, workContext, nodeId);
Modified: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -245,7 +245,7 @@
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
- serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, false);
+ serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, false, prepPlanCache);
serverRequest.setMetadata(capFinder, metadata, null);
serverRequest.processRequest();
Modified: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -80,7 +80,7 @@
RequestMessage message = new RequestMessage();
DQPWorkContext workContext = FakeMetadataFactory.buildWorkContext(metadata, FakeMetadataFactory.example1VDB());
- request.initialize(message, null, null,new FakeTransactionService(),null, workContext, false);
+ request.initialize(message, null, null,new FakeTransactionService(),null, workContext, false, null);
request.initMetadata();
request.validateAccess(command);
}
@@ -134,7 +134,7 @@
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
request.initialize(message, Mockito.mock(BufferManager.class),
- new FakeDataManager(), new FakeTransactionService(), null, workContext, false);
+ new FakeDataManager(), new FakeTransactionService(), null, workContext, false, null);
request.processRequest();
return request;
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -22,12 +22,16 @@
package org.teiid.query.optimizer.proc;
+import java.util.Collections;
+
+import org.junit.Test;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.optimizer.QueryOptimizer;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.parser.QueryParser;
@@ -35,31 +39,19 @@
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.unittest.FakeMetadataFactory;
import org.teiid.query.unittest.FakeMetadataObject;
import org.teiid.query.validator.Validator;
import org.teiid.query.validator.ValidatorFailure;
import org.teiid.query.validator.ValidatorReport;
-import junit.framework.TestCase;
+@SuppressWarnings("nls")
+public class TestProcedurePlanner {
-
-public class TestProcedurePlanner extends TestCase {
-
- /**
- * Constructor for TestGenerateCanonical.
- * @param arg0
- */
- public TestProcedurePlanner(String arg0) {
- super(arg0);
- }
-
// ################ getReplacementClause tests ###################
- private ProcessorPlan helpPlanProcedure(String procedure, String procedureType) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
- return helpPlanProcedure(null, procedure, procedureType);
- }
-
private ProcessorPlan helpPlanProcedure(String userQuery,
String procedure,
String procedureType) throws TeiidComponentException,
@@ -68,6 +60,13 @@
QueryParser parser = QueryParser.getQueryParser();
Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
+
+ if (userCommand instanceof CreateUpdateProcedureCommand) {
+ GroupSymbol gs = new GroupSymbol("proc");
+ gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
+ ((CreateUpdateProcedureCommand)userCommand).setVirtualGroup(gs);
+ }
+
QueryResolver.resolveCommand(userCommand, metadata);
ValidatorReport report = Validator.validate(userCommand, metadata);
@@ -92,7 +91,7 @@
// TESTS
// =============================================================================
- public void testCreateUpdateProcedure1() throws Exception {
+ @Test public void testCreateUpdateProcedure1() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Declare String var1;\n"; //$NON-NLS-1$
@@ -110,7 +109,7 @@
}
// special variable CHANGING used with declared variable
- public void testCreateUpdateProcedure2() throws Exception {
+ @Test public void testCreateUpdateProcedure2() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -129,7 +128,7 @@
}
// special variable CHANGING and INPUT used in conpound criteria
- public void testCreateUpdateProcedure3() throws Exception {
+ @Test public void testCreateUpdateProcedure3() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -148,7 +147,7 @@
}
// special variable CHANGING and INPUT used in conpound criteria, with declared variables
- public void testCreateUpdateProcedure4() throws Exception {
+ @Test public void testCreateUpdateProcedure4() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -167,7 +166,7 @@
}
// virtual group elements used in procedure(HAS CRITERIA)
- public void testCreateUpdateProcedure5() throws Exception {
+ @Test public void testCreateUpdateProcedure5() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -182,7 +181,7 @@
}
// virtual group elements used in procedure in if statement(HAS CRITERIA)
- public void testCreateUpdateProcedure6() throws Exception {
+ @Test public void testCreateUpdateProcedure6() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -200,7 +199,7 @@
}
// testing rows updated incremented, Input and assignment statements
- public void testCreateUpdateProcedure7() throws Exception {
+ @Test public void testCreateUpdateProcedure7() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$
@@ -215,42 +214,42 @@
}
// testing select into with virtual group in from clause
- public void testCreateVirtualProcedure1() throws Exception {
+ @Test public void testCreateVirtualProcedure1() throws Exception {
String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1 INTO #temptable FROM vm1.g1;\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1 FROM #temptable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- helpPlanProcedure(procedure,
+ helpPlanProcedure(null, procedure,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
// testing select into with function in select clause
- public void testCreateVirtualProcedure2() throws Exception {
+ @Test public void testCreateVirtualProcedure2() throws Exception {
String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, convert(e2, string) INTO #temptable FROM vm1.g1;\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1 FROM #temptable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- helpPlanProcedure(procedure,
+ helpPlanProcedure(null, procedure,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
// testing select into with function in select clause
- public void testCreateVirtualProcedure3() throws Exception {
+ @Test public void testCreateVirtualProcedure3() throws Exception {
String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1, convert(e2, string) as a1 INTO #temptable FROM vm1.g1;\n"; //$NON-NLS-1$
procedure = procedure + "SELECT e1 FROM #temptable;\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- helpPlanProcedure(procedure,
+ helpPlanProcedure(null, procedure,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
- public void testCase4504() throws Exception {
+ @Test public void testCase4504() throws Exception {
String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "SELECT y INTO #temptable FROM (select x.e1 as y from (select convert(pm1.g1.e1, date) e1 from pm1.g1) x) z;\n"; //$NON-NLS-1$
@@ -260,7 +259,7 @@
procedure = procedure + "END\n"; //$NON-NLS-1$
procedure = procedure + "END\n"; //$NON-NLS-1$
- helpPlanProcedure(procedure,
+ helpPlanProcedure(null, procedure,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -43,11 +43,14 @@
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.Option;
import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetQuery;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryFromClause;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
@@ -64,6 +67,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
+@SuppressWarnings("nls")
public class TestOptionsAndHints {
/*+* Select a From db.g1 MAKENOTDEP, db.g2 MAKENOTDEP WHERE a = b */
@@ -1074,9 +1078,55 @@
UnaryFromClause ufc = new UnaryFromClause();
from.addClause(ufc);
ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
- query.setFrom(from);
- query.setCacheHint(new CacheHint());
+ query.setFrom(from);
+ CacheHint hint = new CacheHint();
+ hint.setPrefersMemory(true);
+ hint.setTtl(Long.valueOf(2000));
+ query.setCacheHint(hint);
TestParser.helpTest(sql, "/*+ cache(pref_mem ttl:2000) */ SELECT * FROM t1", query); //$NON-NLS-1$
}
+ @Test public void testCacheHintUnion() {
+ String sql = "/*+ cache( pref_mem) */ SELECT * FROM t1 union select * from t2"; //$NON-NLS-1$
+
+ Query query = new Query();
+ Select select = new Select();
+ select.addSymbol(new AllSymbol());
+ query.setSelect(select);
+ From from = new From();
+ UnaryFromClause ufc = new UnaryFromClause();
+ from.addClause(ufc);
+ ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
+ query.setFrom(from);
+
+ Query query1 = new Query();
+ select = new Select();
+ select.addSymbol(new AllSymbol());
+ query1.setSelect(select);
+ from = new From();
+ ufc = new UnaryFromClause();
+ from.addClause(ufc);
+ ufc.setGroup(new GroupSymbol("t2")); //$NON-NLS-1$
+ query1.setFrom(from);
+
+ SetQuery sq = new SetQuery(Operation.UNION, false, query, query1);
+ CacheHint hint = new CacheHint();
+ hint.setPrefersMemory(true);
+ sq.setCacheHint(hint);
+ TestParser.helpTest(sql, "/*+ cache(pref_mem) */ SELECT * FROM t1 UNION SELECT * FROM t2", sq); //$NON-NLS-1$
+ }
+
+ @Test public void testCacheHintCallableStatement() {
+ String sql = "/*+ cache */ { ? = call proc() }"; //$NON-NLS-1$
+ StoredProcedure sp = new StoredProcedure();
+ SPParameter param = new SPParameter(1, null);
+ param.setParameterType(SPParameter.RETURN_VALUE);
+ sp.setParameter(param);
+ sp.setProcedureName("proc");
+ sp.setCallableStatement(true);
+ CacheHint hint = new CacheHint();
+ sp.setCacheHint(hint);
+ TestParser.helpTest(sql, "/*+ cache */ EXEC proc()", sp); //$NON-NLS-1$
+ }
+
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -23,7 +23,6 @@
package org.teiid.query.processor;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,7 +31,6 @@
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
-import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.util.CommandContext;
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -32,7 +32,7 @@
import org.junit.Test;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.core.TeiidProcessingException;
-import org.teiid.dqp.internal.process.SimpleQueryProcessorFactory;
+import org.teiid.dqp.internal.process.QueryProcessorFactoryImpl;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
@@ -69,7 +69,7 @@
cc.setMetadata(metadata);
CapabilitiesFinder finder = new DefaultCapabilitiesFinder();
previousPlan = TestProcessor.helpGetPlan(TestProcessor.helpParse(sql), metadata, finder, cc);
- cc.setQueryProcessorFactory(new SimpleQueryProcessorFactory(BufferManagerFactory.getStandaloneBufferManager(), dataManager, finder, null, metadata));
+ cc.setQueryProcessorFactory(new QueryProcessorFactoryImpl(BufferManagerFactory.getStandaloneBufferManager(), dataManager, finder, null, metadata));
TestProcessor.doProcess(previousPlan, dataManager, expectedResults, cc);
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -54,7 +54,9 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.XMLType;
-import org.teiid.dqp.internal.process.SimpleQueryProcessorFactory;
+import org.teiid.dqp.internal.process.PreparedPlan;
+import org.teiid.dqp.internal.process.QueryProcessorFactoryImpl;
+import org.teiid.dqp.internal.process.SessionAwareCache;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.function.FunctionTree;
@@ -245,7 +247,7 @@
dataManager = new TempTableDataManager(dataManager, bufferMgr);
}
if (context.getQueryProcessorFactory() == null) {
- context.setQueryProcessorFactory(new SimpleQueryProcessorFactory(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
+ context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
}
TupleBuffer id = null;
try {
@@ -345,6 +347,7 @@
context.setProcessorBatchSize(BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
context.setConnectorBatchSize(BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE);
context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+ context.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>());
return context;
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -48,6 +48,7 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.FakeDataManager;
import org.teiid.query.processor.FakeDataStore;
+import org.teiid.query.processor.HardcodedDataManager;
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.TestProcessor;
@@ -73,7 +74,7 @@
return getProcedurePlan(userQuery, metadata, /*capabilitiesFinder*/null);
}
- public static ProcessorPlan getProcedurePlan(String userQuery, FakeMetadataFacade metadata, CapabilitiesFinder capabilitiesFinder) throws Exception {
+ public static ProcessorPlan getProcedurePlan(String userQuery, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws Exception {
Command userCommand = QueryParser.getQueryParser().parseCommand(userQuery);
QueryResolver.resolveCommand(userCommand, metadata);
ValidatorReport report = Validator.validate(userCommand, metadata);
@@ -2636,5 +2637,16 @@
helpTestProcess(plan, expected, dataMgr, metadata);
}
+ @Test public void testUnambiguousVirtualProc() throws Exception {
+ String userQuery = "EXEC MMSP6('1')"; //$NON-NLS-1$
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+ ProcessorPlan plan = getProcedurePlan(userQuery, metadata, TestOptimizer.getGenericFinder());
+
+ List[] expected = new List[] {
+ Arrays.asList( "1" ),
+ };
+ helpTestProcess(plan, expected, new HardcodedDataManager(), metadata);
+ }
+
private static final boolean DEBUG = false;
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-25 00:56:42 UTC (rev 2489)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-25 16:18:52 UTC (rev 2490)
@@ -250,7 +250,7 @@
ColumnSet<Procedure> vsprs6 = createResultSet("mmspTest1.vsprs1", new String[] { "StringKey" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
ProcedureParameter vsp6p1 = createParameter("p1", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$
- QueryNode vspqn6 = new QueryNode("vsp6", "CREATE VIRTUAL PROCEDURE BEGIN SELECT 1; END"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode vspqn6 = new QueryNode("vsp6", "CREATE VIRTUAL PROCEDURE BEGIN SELECT p1 as StringKey; END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp6 = createVirtualProcedure("MMSP6", mmspTest1, Arrays.asList(vsp6p1), vspqn6); //$NON-NLS-1$
vsp6.setResultSet(vsprs6);
14 years, 4 months
teiid SVN: r2489 - in branches/7.1.x/engine/src/test/java/org/teiid/query: processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-24 20:56:42 -0400 (Tue, 24 Aug 2010)
New Revision: 2489
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1224 fix for uncorrelated subquery evaluation of a stored procedure
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2010-08-24 21:45:14 UTC (rev 2488)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2010-08-25 00:56:42 UTC (rev 2489)
@@ -25,6 +25,8 @@
import static org.teiid.query.optimizer.TestOptimizer.*;
import org.junit.Test;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -735,15 +737,15 @@
/**
* Technically this is not a full push-down, but the subquery will be evaluated prior to pushdown
*/
- @Test public void testCompareSubquery4() {
+ @Test public void testCompareSubquery4() throws TeiidComponentException, TeiidProcessingException {
ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 > (select e1 FROM pm2.g1 where e2 = 13)", example1(), //$NON-NLS-1$
- new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 > (SELECT g_1.e1 FROM pm2.g1 AS g_1 WHERE g_1.e2 = 13)" }); //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 > (SELECT g_0.e1 FROM pm2.g1 AS g_0 WHERE g_0.e2 = 13)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
- @Test public void testScalarSubquery1() {
+ @Test public void testScalarSubquery1() throws TeiidComponentException, TeiidProcessingException {
ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') from pm1.g1", example1(), //$NON-NLS-1$
- new String[] { "SELECT g_0.e1, (SELECT g_1.e1 FROM pm2.g1 AS g_1 WHERE g_1.e1 = 'x') FROM pm1.g1 AS g_0" }); //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1, (SELECT g_0.e1 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'x') FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-24 21:45:14 UTC (rev 2488)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-25 00:56:42 UTC (rev 2489)
@@ -7522,7 +7522,7 @@
ProcessorPlan plan = helpPlan("select pm1.g1.e1 from pm1.g1 where e1 < (select max(vm1.g1.e1) from vm1.g1)", metadata, //$NON-NLS-1$
null, capFinder,
- new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < (SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < (SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
HardcodedDataManager hdm = new HardcodedDataManager();
14 years, 4 months
teiid SVN: r2488 - in branches/7.1.x/engine/src: main/java/org/teiid/query/optimizer/relational/rules and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-24 17:45:14 -0400 (Tue, 24 Aug 2010)
New Revision: 2488
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1224 fix for uncorrelated subquery evaluation of a stored procedure
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-08-24 21:31:16 UTC (rev 2487)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-08-24 21:45:14 UTC (rev 2488)
@@ -309,6 +309,9 @@
}
public void visit(ScalarSubquery obj) {
+ if (obj.shouldEvaluate()) {
+ return;
+ }
visitor.createChildNamingContext(false);
visitNode(obj.getCommand());
visitor.removeChildNamingContext();
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-08-24 21:31:16 UTC (rev 2487)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-08-24 21:45:14 UTC (rev 2488)
@@ -348,7 +348,7 @@
private void replaceCorrelatedReferences(List<SubqueryContainer> containers) {
for (SubqueryContainer container : containers) {
RelationalPlan subqueryPlan = (RelationalPlan)container.getCommand().getProcessorPlan();
- if (subqueryPlan == null) {
+ if (subqueryPlan == null || !(subqueryPlan.getRootNode() instanceof AccessNode)) {
continue;
}
AccessNode child = (AccessNode)subqueryPlan.getRootNode();
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-24 21:31:16 UTC (rev 2487)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-24 21:45:14 UTC (rev 2488)
@@ -7512,7 +7512,7 @@
@Test public void testUncorrelatedScalarSubqueryPushdown() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- FakeMetadataFacade metadata = example1();
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, false);
@@ -7535,6 +7535,32 @@
helpProcess(plan, hdm, expected);
}
+
+ @Test public void testUncorrelatedScalarSubqueryPushdown1() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, false);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan("select pm1.g1.e1 from pm1.g1 where e1 < (select e1 from (EXEC pm1.sq1()) x order by e2 limit 1)", metadata, //$NON-NLS-1$
+ null, capFinder,
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < (SELECT e1 FROM (EXEC pm1.sq1()) AS x ORDER BY e2 LIMIT 1)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+
+ HardcodedDataManager hdm = new HardcodedDataManager();
+ hdm.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < 'z'", new List[] {Arrays.asList("c")});
+ hdm.addData("SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0", new List[] {Arrays.asList("z", 1), Arrays.asList("b", 2)});
+ hdm.setBlockOnce(true);
+ List[] expected = new List[] {
+ Arrays.asList("c"),
+ };
+
+ helpProcess(plan, hdm, expected);
+ }
private static final boolean DEBUG = false;
}
14 years, 4 months
teiid SVN: r2487 - in branches/7.1.x: common-core/src/test/java/org/teiid/core/util and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-24 17:31:16 -0400 (Tue, 24 Aug 2010)
New Revision: 2487
Modified:
branches/7.1.x/common-core/src/main/java/org/teiid/core/util/Assertion.java
branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestAssertion.java
branches/7.1.x/connectors/translator-ws/src/main/java/org/teiid/translator/ws/WSExecutionFactory.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/BatchedUpdateCommand.java
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java
Log:
misc cleanups
Modified: branches/7.1.x/common-core/src/main/java/org/teiid/core/util/Assertion.java
===================================================================
--- branches/7.1.x/common-core/src/main/java/org/teiid/core/util/Assertion.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/common-core/src/main/java/org/teiid/core/util/Assertion.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -22,9 +22,6 @@
package org.teiid.core.util;
-import java.util.Collection;
-import java.util.Map;
-
import org.teiid.core.CorePlugin;
@@ -76,210 +73,6 @@
throw new AssertionError(msg);
}
- // ########################## boolean METHODS ###################################
-
- public static final void isEqual(boolean value1, boolean value2) {
- isEqual(value1,value2,null);
- }
-
- public static final void isEqual(boolean value1, boolean value2, String message) {
- if ( value1 != value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{new Boolean(value1),new Boolean(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNotEqual(boolean value1, boolean value2) {
- isNotEqual(value1,value2,null);
- }
-
- public static final void isNotEqual(boolean value1, boolean value2, String message) {
- if ( value1 == value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotEqual",new Object[]{new Boolean(value1),new Boolean(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- // ########################## int METHODS ###################################
-
- public static final void isEqual(int value1, int value2) {
- isEqual(value1,value2,null);
- }
-
- public static final void isEqual(int value1, int value2, String message) {
- if ( value1 != value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{new Integer(value1),new Integer(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNotEqual(int value1, int value2) {
- isNotEqual(value1,value2,null);
- }
-
- public static final void isNotEqual(int value1, int value2, String message) {
- if ( value1 == value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotEqual",new Object[]{new Integer(value1),new Integer(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNonNegative(int value) {
- isNonNegative(value,null);
- }
-
- public static final void isNonNegative(int value, String message) {
- if ( value < 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNonNegative",new Object[]{new Integer(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNonPositive(int value) {
- isNonPositive(value,null);
- }
-
- public static final void isNonPositive(int value, String message) {
- if ( value > 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNonPositive",new Object[]{new Integer(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNegative(int value) {
- isNegative(value,null);
- }
-
- public static final void isNegative(int value, String message) {
- if ( value >= 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNegative",new Object[]{new Integer(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isPositive(int value) {
- isPositive(value,null);
- }
-
- public static final void isPositive(int value, String message) {
- if ( value <= 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isPositive",new Object[]{new Integer(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- // ########################## long METHODS ###################################
-
- public static final void isEqual(long value1, long value2) {
- isEqual(value1,value2,null);
- }
-
- public static final void isEqual(long value1, long value2, String message) {
- if ( value1 != value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{new Long(value1),new Long(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNotEqual(long value1, long value2) {
- isNotEqual(value1,value2,null);
- }
-
- public static final void isNotEqual(long value1, long value2, String message) {
- if ( value1 == value2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotEqual",new Object[]{new Long(value1),new Long(value2)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNonNegative(long value) {
- isNonNegative(value,null);
- }
-
- public static final void isNonNegative(long value, String message) {
- if ( value < 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNonNegative",new Object[]{new Long(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNonPositive(long value) {
- isNonPositive(value,null);
- }
-
- public static final void isNonPositive(long value, String message) {
- if ( value > 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNonPositive",new Object[]{new Long(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNegative(long value) {
- isNegative(value,null);
- }
-
- public static final void isNegative(long value, String message) {
- if ( value >= 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNegative",new Object[]{new Long(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isPositive(long value) {
- isPositive(value,null);
- }
-
- public static final void isPositive(long value, String message) {
- if ( value <= 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isPositive",new Object[]{new Long(value)}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- // ########################## String METHODS ###################################
-
- public static final void isNotZeroLength(String value) {
- isNotZeroLength(value,null);
- }
-
- public static final void isNotZeroLength(String value, String message) {
- isNotNull(value);
- if ( value.length() == 0 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotZeroLength"); //$NON-NLS-1$
- failed(msg);
- }
- }
-
// ########################## OBJECT METHODS ###################################
public static final void isNull(Object value) {
@@ -308,61 +101,6 @@
}
}
- /**
- * Compares with object1 == object2.
- */
- public static final void isIdentical(Object object1, Object object2) {
- isIdentical(object1,object2,null);
- }
-
- /**
- * Compares with object1 == object2.
- */
- public static final void isIdentical(Object object1, Object object2, String message) {
- if ( object1 != object2 ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isIdentical",new Object[]{object1,object2}); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- /**
- * Compares with object1.equals(object2).
- */
- public static final void isEqual(Object object1, Object object2) {
- isEqual(object1,object2,null);
- }
-
- /**
- * Compares with object1.equals(object2).
- */
- public static final void isEqual(Object object1, Object object2, String message) {
- if(object1 == null) {
- if ( object2 != null ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{object1,object2}); //$NON-NLS-1$
- failed(msg);
- }
- // else both are null
- } else {
- if ( object2 == null ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{object1,object2}); //$NON-NLS-1$
- failed(msg);
- }
- // else both are not null
- if ( !object1.equals(object2) ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isEqual",new Object[]{object1,object2}); //$NON-NLS-1$
- failed(msg);
- }
- }
- }
-
/**
* Verifies that the specified value is an instance of the specified class.
* @param value The value to verify
@@ -371,74 +109,17 @@
* @throws ClassCastException If the value is not an instance of the specified class.
* @since 2.1
*/
- public static final Object isInstanceOf(final Object object, final Class expectedClass, final String name) {
+ public static final <T> T isInstanceOf(final Object object, final Class<T> expectedClass, final String name) {
if (object == null) {
return null;
}
- final Class objClass = object.getClass();
+ final Class<?> objClass = object.getClass();
if (!expectedClass.isAssignableFrom(objClass)) {
final Object[] params = new Object[]{name, expectedClass, objClass.getName()};
final String msg = CorePlugin.Util.getString("Assertion.invalidClassMessage",params); //$NON-NLS-1$
throw new ClassCastException(msg);
}
- return object;
+ return expectedClass.cast(object);
}
- // ########################## COLLECTION METHODS ###################################
-
- public static final void isNotEmpty(Collection collection) {
- isNotEmpty(collection,null);
- }
-
- public static final void isNotEmpty(Collection collection, String message) {
- isNotNull(collection);
- if ( collection.isEmpty() ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotEmpty_Collection"); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void isNotEmpty(Map map) {
- isNotEmpty(map,null);
- }
-
- public static final void isNotEmpty(Map map, String message) {
- isNotNull(map);
- if ( map.isEmpty() ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.isNotEmpty_Map"); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void contains(Collection collection, Object value) {
- contains(collection,value,null);
- }
-
- public static final void contains(Collection collection, Object value, String message) {
- isNotNull(collection);
- if ( !collection.contains(value) ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.contains_Collection"); //$NON-NLS-1$
- failed(msg);
- }
- }
-
- public static final void containsKey(Map map, Object key) {
- containsKey(map,key,null);
- }
-
- public static final void containsKey(Map map, Object key, String message) {
- isNotNull(map);
- if ( !map.containsKey(key) ) {
- final String msg = message != null ?
- message :
- CorePlugin.Util.getString("Assertion.contains_Map"); //$NON-NLS-1$
- failed(msg);
- }
- }
}
Modified: branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestAssertion.java
===================================================================
--- branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestAssertion.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestAssertion.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -93,619 +93,6 @@
}
/*
- * Test for void isEqual(boolean, boolean)
- */
- public void testIsEqualbooleanboolean() {
- Assertion.isEqual(true,true);
- Assertion.isEqual(false,false);
-
- try {
- Assertion.isEqual(false,true);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Boolean(false),new Boolean(true)};
- final String msg = CorePlugin.Util.getString("Assertion.isEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(boolean, boolean, String)
- */
- public void testIsEqualbooleanbooleanString() {
- Assertion.isEqual(true,true,TEST_MESSAGE);
- Assertion.isEqual(false,false,TEST_MESSAGE);
-
- try {
- Assertion.isEqual(false,true,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(boolean, boolean)
- */
- public void testIsNotEqualbooleanboolean() {
- Assertion.isNotEqual(false,true);
- Assertion.isNotEqual(true,false);
-
- try {
- Assertion.isNotEqual(false,false);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Boolean(false),new Boolean(false)};
- final String msg = CorePlugin.Util.getString("Assertion.isNotEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(boolean, boolean, String)
- */
- public void testIsNotEqualbooleanbooleanString() {
- Assertion.isNotEqual(false,true,TEST_MESSAGE);
- Assertion.isNotEqual(true,false,TEST_MESSAGE);
-
- try {
- Assertion.isNotEqual(false,false,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(int, int)
- */
- public void testIsEqualintint() {
- Assertion.isEqual(-1,-1);
- Assertion.isEqual(1,1);
- Assertion.isEqual(0,0);
- Assertion.isEqual(10000,10000);
-
- try {
- Assertion.isEqual(1,-1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(1),new Integer(-1)};
- final String msg = CorePlugin.Util.getString("Assertion.isEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(int, int, String)
- */
- public void testIsEqualintintString() {
- Assertion.isEqual(-1,-1,TEST_MESSAGE);
- Assertion.isEqual(1,1,TEST_MESSAGE);
- Assertion.isEqual(0,0,TEST_MESSAGE);
- Assertion.isEqual(10000,10000,TEST_MESSAGE);
-
- try {
- Assertion.isEqual(1,-1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(int, int)
- */
- public void testIsNotEqualintint() {
- Assertion.isNotEqual(-1,-12);
- Assertion.isNotEqual(1,-1);
- Assertion.isNotEqual(0,1);
- Assertion.isNotEqual(10000,-10000);
-
- try {
- Assertion.isNotEqual(1,1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(1),new Integer(1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNotEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(int, int, String)
- */
- public void testIsNotEqualintintString() {
- Assertion.isNotEqual(-1,-12,TEST_MESSAGE);
- Assertion.isNotEqual(1,-1,TEST_MESSAGE);
- Assertion.isNotEqual(0,1,TEST_MESSAGE);
- Assertion.isNotEqual(10000,-10000,TEST_MESSAGE);
-
- try {
- Assertion.isNotEqual(1,1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonNegative(int)
- */
- public void testIsNonNegativeint() {
- Assertion.isNonNegative(1);
- Assertion.isNonNegative(13);
- Assertion.isNonNegative(0);
-
- try {
- Assertion.isNonNegative(-1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(-1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNonNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonNegative(int, String)
- */
- public void testIsNonNegativeintString() {
- Assertion.isNonNegative(1,TEST_MESSAGE);
- Assertion.isNonNegative(13,TEST_MESSAGE);
- Assertion.isNonNegative(0,TEST_MESSAGE);
-
- try {
- Assertion.isNonNegative(-1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonPositive(int)
- */
- public void testIsNonPositiveint() {
- Assertion.isNonPositive(-1);
- Assertion.isNonPositive(0);
- Assertion.isNonPositive(-100);
-
- try {
- Assertion.isNonPositive(1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNonPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonPositive(int, String)
- */
- public void testIsNonPositiveintString() {
- Assertion.isNonPositive(-1,TEST_MESSAGE);
- Assertion.isNonPositive(0,TEST_MESSAGE);
- Assertion.isNonPositive(-100,TEST_MESSAGE);
-
- try {
- Assertion.isNonPositive(1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNegative(int)
- */
- public void testIsNegativeint() {
- Assertion.isNegative(-1);
- Assertion.isNegative(-100);
-
- try {
- Assertion.isNegative(1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- try {
- Assertion.isNegative(0);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(0)};
- final String msg = CorePlugin.Util.getString("Assertion.isNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNegative(int, String)
- */
- public void testIsNegativeintString() {
- Assertion.isNegative(-1,TEST_MESSAGE);
- Assertion.isNegative(-100,TEST_MESSAGE);
-
- try {
- Assertion.isNegative(1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- try {
- Assertion.isNegative(0,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isPositive(int)
- */
- public void testIsPositiveint() {
- Assertion.isPositive(1);
- Assertion.isPositive(100);
-
- try {
- Assertion.isPositive(-1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(-1)};
- final String msg = CorePlugin.Util.getString("Assertion.isPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- try {
- Assertion.isPositive(0);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Integer(0)};
- final String msg = CorePlugin.Util.getString("Assertion.isPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isPositive(int, String)
- */
- public void testIsPositiveintString() {
- Assertion.isPositive(1,TEST_MESSAGE);
- Assertion.isPositive(100,TEST_MESSAGE);
-
- try {
- Assertion.isPositive(-1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- try {
- Assertion.isPositive(0,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(long, long)
- */
- public void testIsEquallonglong() {
- Assertion.isEqual(-1l,-1l);
- Assertion.isEqual(1l,1l);
- Assertion.isEqual(0l,0l);
- Assertion.isEqual(10000l,10000l);
-
- try {
- Assertion.isEqual(1l,-1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(1),new Long(-1)};
- final String msg = CorePlugin.Util.getString("Assertion.isEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(long, long, String)
- */
- public void testIsEquallonglongString() {
- Assertion.isEqual(-1l,-1l,TEST_MESSAGE);
- Assertion.isEqual(1l,1l,TEST_MESSAGE);
- Assertion.isEqual(0l,0l,TEST_MESSAGE);
- Assertion.isEqual(10000l,10000l,TEST_MESSAGE);
-
- try {
- Assertion.isEqual(1l,-1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(long, long)
- */
- public void testIsNotEquallonglong() {
- Assertion.isNotEqual(-1l,-12l);
- Assertion.isNotEqual(1l,12l);
- Assertion.isNotEqual(0l,-20l);
- Assertion.isNotEqual(10000l,-10000l);
-
- try {
- Assertion.isNotEqual(1l,1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(1l),new Long(1l)};
- final String msg = CorePlugin.Util.getString("Assertion.isNotEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotEqual(long, long, String)
- */
- public void testIsNotEquallonglongString() {
- Assertion.isNotEqual(-1l,-12l,TEST_MESSAGE);
- Assertion.isNotEqual(1l,12l,TEST_MESSAGE);
- Assertion.isNotEqual(0l,-20l,TEST_MESSAGE);
- Assertion.isNotEqual(10000l,-10000l,TEST_MESSAGE);
-
- try {
- Assertion.isNotEqual(1l,1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonNegative(long)
- */
- public void testIsNonNegativelong() {
- Assertion.isNonNegative(1l);
- Assertion.isNonNegative(13l);
- Assertion.isNonNegative(0l);
-
- try {
- Assertion.isNonNegative(-1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(-1l)};
- final String msg = CorePlugin.Util.getString("Assertion.isNonNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonNegative(long, String)
- */
- public void testIsNonNegativelongString() {
- Assertion.isNonNegative(1l,TEST_MESSAGE);
- Assertion.isNonNegative(13l,TEST_MESSAGE);
- Assertion.isNonNegative(0l,TEST_MESSAGE);
-
- try {
- Assertion.isNonNegative(-1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonPositive(long)
- */
- public void testIsNonPositivelong() {
- Assertion.isNonPositive(-1l);
- Assertion.isNonPositive(0l);
- Assertion.isNonPositive(-100l);
-
- try {
- Assertion.isNonPositive(1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNonPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNonPositive(long, String)
- */
- public void testIsNonPositivelongString() {
- Assertion.isNonPositive(-1l,TEST_MESSAGE);
- Assertion.isNonPositive(0l,TEST_MESSAGE);
- Assertion.isNonPositive(-100l,TEST_MESSAGE);
-
- try {
- Assertion.isNonPositive(1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNegative(long)
- */
- public void testIsNegativelong() {
- Assertion.isNegative(-1l);
- Assertion.isNegative(-100l);
-
- try {
- Assertion.isNegative(1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(1)};
- final String msg = CorePlugin.Util.getString("Assertion.isNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- try {
- Assertion.isNegative(0l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(0)};
- final String msg = CorePlugin.Util.getString("Assertion.isNegative",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNegative(long, String)
- */
- public void testIsNegativelongString() {
- Assertion.isNegative(-1l,TEST_MESSAGE);
- Assertion.isNegative(-100l,TEST_MESSAGE);
-
- try {
- Assertion.isNegative(1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- try {
- Assertion.isNegative(0l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isPositive(long)
- */
- public void testIsPositivelong() {
- Assertion.isPositive(1l);
- Assertion.isPositive(100l);
-
- try {
- Assertion.isPositive(-1l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(-1)};
- final String msg = CorePlugin.Util.getString("Assertion.isPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- try {
- Assertion.isPositive(0l);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{new Long(0)};
- final String msg = CorePlugin.Util.getString("Assertion.isPositive",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isPositive(long, String)
- */
- public void testIsPositivelongString() {
- Assertion.isPositive(1l,TEST_MESSAGE);
- Assertion.isPositive(100l,TEST_MESSAGE);
-
- try {
- Assertion.isPositive(-1l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- try {
- Assertion.isPositive(0l,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotZeroLength(String)
- */
- public void testIsNotZeroLengthString() {
- Assertion.isNotZeroLength("This is a string"); //$NON-NLS-1$
- Assertion.isNotZeroLength(" "); //$NON-NLS-1$
-
- try {
- Assertion.isNotZeroLength(""); //$NON-NLS-1$
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final String msg = CorePlugin.Util.getString("Assertion.isNotZeroLength"); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- try {
- Assertion.isNotZeroLength(null);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final String msg = CorePlugin.Util.getString("Assertion.isNotNull"); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isNotZeroLength(String, String)
- */
- public void testIsNotZeroLengthStringString() {
- Assertion.isNotZeroLength("This is a string",TEST_MESSAGE); //$NON-NLS-1$
- Assertion.isNotZeroLength(" ",TEST_MESSAGE); //$NON-NLS-1$
-
- try {
- Assertion.isNotZeroLength("",TEST_MESSAGE); //$NON-NLS-1$
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- try {
- Assertion.isNotZeroLength(null,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final String msg = CorePlugin.Util.getString("Assertion.isNotNull"); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
* Test for void isNull(Object)
*/
public void testIsNullObject() {
@@ -767,86 +154,6 @@
}
}
- /*
- * Test for void isIdentical(Object, Object)
- */
- public void testIsIdenticalObjectObject() {
- final String obj1 = ""; //$NON-NLS-1$
- final Integer int1 = new Integer(33);
- Assertion.isIdentical(obj1,obj1);
- Assertion.isIdentical(int1,int1);
-
- try {
- Assertion.isIdentical(int1,obj1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{int1,obj1};
- final String msg = CorePlugin.Util.getString("Assertion.isIdentical",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isIdentical(Object, Object, String)
- */
- public void testIsIdenticalObjectObjectString() {
- final String obj1 = ""; //$NON-NLS-1$
- final Integer int1 = new Integer(33);
- Assertion.isIdentical(obj1,obj1,TEST_MESSAGE);
- Assertion.isIdentical(int1,int1,TEST_MESSAGE);
-
- try {
- Assertion.isIdentical(int1,obj1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(Object, Object)
- */
- public void testIsEqualObjectObject() {
- final String obj1 = ""; //$NON-NLS-1$
- final String obj2 = ""; //$NON-NLS-1$
- final Integer int1 = new Integer(33);
- final Integer int2 = new Integer(33);
- Assertion.isEqual(obj1,obj2);
- Assertion.isEqual(int1,int2);
-
- try {
- Assertion.isEqual(int1,obj1);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- final Object[] params = new Object[]{int1,obj1};
- final String msg = CorePlugin.Util.getString("Assertion.isEqual",params); //$NON-NLS-1$
- assertEquals(msg, e.getMessage());
- }
- }
-
- /*
- * Test for void isEqual(Object, Object, String)
- */
- public void testIsEqualObjectObjectString() {
- final String obj1 = ""; //$NON-NLS-1$
- final String obj2 = ""; //$NON-NLS-1$
- final Integer int1 = new Integer(33);
- final Integer int2 = new Integer(33);
- Assertion.isEqual(obj1,obj2,TEST_MESSAGE);
- Assertion.isEqual(int1,int2,TEST_MESSAGE);
-
- try {
- Assertion.isEqual(int1,obj1,TEST_MESSAGE);
- fail();
- } catch ( AssertionError e ) {
- // expected, but check the message
- assertEquals(TEST_MESSAGE, e.getMessage());
- }
- }
-
public void testIsInstanceOf() {
Assertion.isInstanceOf(new Integer(1),Integer.class,"name"); //$NON-NLS-1$
Assertion.isInstanceOf("asdfasdf",String.class,"name2"); //$NON-NLS-1$ //$NON-NLS-2$
Modified: branches/7.1.x/connectors/translator-ws/src/main/java/org/teiid/translator/ws/WSExecutionFactory.java
===================================================================
--- branches/7.1.x/connectors/translator-ws/src/main/java/org/teiid/translator/ws/WSExecutionFactory.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/connectors/translator-ws/src/main/java/org/teiid/translator/ws/WSExecutionFactory.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -132,7 +132,7 @@
//can be one of string, xml, clob
param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.XML, Type.In, p); //$NON-NLS-1$
- param.setAnnotation("The XML document or root element that represents the request. If the ExecutionFactory is configured in with a DefaultServiceMode or MESSAGE then SOAP request must contain the entire SOAP message."); //$NON-NLS-1$
+ param.setAnnotation("The XML document or root element that represents the request. If the ExecutionFactory is configured in with a DefaultServiceMode of MESSAGE, then the SOAP request must contain the entire SOAP message."); //$NON-NLS-1$
param.setNullType(NullType.Nullable);
param = metadataFactory.addProcedureParameter("endpoint", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p); //$NON-NLS-1$
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -219,15 +219,13 @@
// Create the execution based on mode
final Execution exec = connector.createExecution(this.translatedCommand, this.securityContext, rmd, this.connection);
if (this.translatedCommand instanceof Call) {
- Assertion.isInstanceOf(this.execution, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
- this.execution = (ProcedureExecution)exec;
+ this.execution = Assertion.isInstanceOf(this.execution, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
StoredProcedure proc = (StoredProcedure)command;
if (proc.returnParameters()) {
this.procedureBatchHandler = new ProcedureBatchHandler((Call)this.translatedCommand, (ProcedureExecution)this.execution);
}
} else if (this.translatedCommand instanceof QueryExpression){
- Assertion.isInstanceOf(this.execution, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
- this.execution = (ResultSetExecution)exec;
+ this.execution = Assertion.isInstanceOf(this.execution, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
} else {
Assertion.isInstanceOf(this.execution, UpdateExecution.class, "Update Executions are expected to be UpdateExecutions"); //$NON-NLS-1$
this.execution = new ResultSetExecution() {
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -70,7 +70,6 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.util.ErrorMessageKeys;
@@ -115,7 +114,7 @@
// then in the query transformation, this info is used in evaluating/validating
// has criteria/translate criteria clauses
Command transformCmd = getQueryTransformCmd(virtualGroup, metadata);
- Map symbolMap = SymbolMap.createSymbolMap(virtualGroup, (List<SingleElementSymbol>)transformCmd.getProjectedSymbols(), metadata).asMap();
+ Map symbolMap = SymbolMap.createSymbolMap(virtualGroup, transformCmd.getProjectedSymbols(), metadata).asMap();
procCommand.setSymbolMap(symbolMap);
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/BatchedUpdateCommand.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/BatchedUpdateCommand.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/lang/BatchedUpdateCommand.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -25,14 +25,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
-import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.util.VariableContext;
Modified: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -62,7 +62,7 @@
//No PreparedPlan at the begining
assertNull(cache.get(id));
//create one
- cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, new PreparedPlan());
+ cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, new PreparedPlan(), null);
//should have one now
assertNotNull("Unable to get prepared plan from cache", cache.get(id)); //$NON-NLS-1$
}
@@ -149,7 +149,7 @@
CacheID id = new CacheID(session, pi, dummy.toString());
PreparedPlan pPlan = new PreparedPlan();
- cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, pPlan);
+ cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, pPlan, null);
pPlan.setCommand(dummy);
pPlan.setPlan(new RelationalPlan(new ProjectNode(i)));
AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
Modified: branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java 2010-08-24 00:25:18 UTC (rev 2486)
+++ branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java 2010-08-24 21:31:16 UTC (rev 2487)
@@ -47,7 +47,7 @@
Cachable result = Mockito.mock(Cachable.class);
id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
- cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, result);
+ cache.put(id, FunctionMethod.SESSION_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
@@ -71,7 +71,7 @@
Mockito.stub(result.prepare((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
Mockito.stub(result.restore((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
- cache.put(id, FunctionMethod.USER_DETERMINISTIC, result);
+ cache.put(id, FunctionMethod.USER_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
@@ -97,7 +97,7 @@
Mockito.stub(result.prepare((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
Mockito.stub(result.restore((Cache)anyObject(), (BufferManager)anyObject())).toReturn(true);
- cache.put(id, FunctionMethod.VDB_DETERMINISTIC, result);
+ cache.put(id, FunctionMethod.VDB_DETERMINISTIC, result, null);
// make sure that in the case of session specific; we do not call prepare
// as session is local only call for distributed
14 years, 4 months
teiid SVN: r2486 - in branches/7.1.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-23 20:25:18 -0400 (Mon, 23 Aug 2010)
New Revision: 2486
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1221 fix for reexecution of uncorrelated scalar subqueries.
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-23 19:19:45 UTC (rev 2485)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-24 00:25:18 UTC (rev 2486)
@@ -56,6 +56,7 @@
private TupleSource tupleSource;
private boolean isUpdate = false;
private boolean returnedRows = false;
+ private Command nextCommand;
public AccessNode(int nodeID) {
super(nodeID);
@@ -66,6 +67,7 @@
tupleSource = null;
isUpdate = false;
returnedRows = false;
+ nextCommand = null;
}
public void setCommand(Command command) {
@@ -95,8 +97,9 @@
Command atomicCommand = command;
boolean needProcessing = true;
if(shouldEvaluate) {
- atomicCommand = (Command) command.clone();
+ atomicCommand = nextCommand();
needProcessing = prepareNextCommand(atomicCommand);
+ nextCommand = null;
} else {
needProcessing = RelationalNodeUtil.shouldExecute(atomicCommand, true);
}
@@ -111,6 +114,15 @@
}
}
+ private Command nextCommand() {
+ //it's important to save the next command
+ //to ensure that the subquery ids remain stable
+ if (nextCommand == null) {
+ nextCommand = (Command) command.clone();
+ }
+ return nextCommand;
+ }
+
protected boolean prepareNextCommand(Command atomicCommand) throws TeiidComponentException, TeiidProcessingException {
return prepareCommand(atomicCommand, getEvaluator(Collections.emptyMap()), this.getContext(), this.getContext().getMetadata());
}
@@ -155,11 +167,13 @@
if (processCommandsIndividually() && hasPendingRows()) {
return pullBatch();
}
- Command atomicCommand = (Command)command.clone();
+ Command atomicCommand = nextCommand();
if (prepareNextCommand(atomicCommand)) {
+ nextCommand = null;
registerRequest(atomicCommand);
break;
}
+ nextCommand = null;
}
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-23 19:19:45 UTC (rev 2485)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-24 00:25:18 UTC (rev 2486)
@@ -42,6 +42,7 @@
import org.junit.Test;
import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
@@ -249,9 +250,18 @@
TupleBuffer id = null;
try {
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
- processor.setNonBlocking(true);
+ //processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
- id = collector.collectTuples();
+ for (int i = 0; i < 100; i++) {
+ try {
+ id = collector.collectTuples();
+ } catch (BlockedException e) {
+
+ }
+ }
+ if (id == null) {
+ fail("did not complete processing");
+ }
if ( expectedResults != null ) {
examineResults(expectedResults, bufferMgr, id);
}
@@ -7518,7 +7528,7 @@
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0", new List[] {Arrays.asList("c")});
hdm.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < 'c'", new List[] {Arrays.asList("a")});
-
+ hdm.setBlockOnce(true);
List[] expected = new List[] {
Arrays.asList("a"),
};
14 years, 4 months
teiid SVN: r2485 - in branches/7.1.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-23 15:19:45 -0400 (Mon, 23 Aug 2010)
New Revision: 2485
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
Log:
TEIIDDES-567 updates to SQLStringVisitor logic for Teiid Designer.
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-23 17:53:50 UTC (rev 2484)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-23 19:19:45 UTC (rev 2485)
@@ -24,11 +24,9 @@
import static org.teiid.language.SQLConstants.Reserved.*;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import org.teiid.core.types.DataTypeManager;
@@ -128,8 +126,9 @@
import org.teiid.translator.SourceSystemFunctions;
/**
- * <p>The SQLStringVisitor will visit a set of language objects and return the
- * corresponding SQL string representation. </p>
+ * <p>
+ * The SQLStringVisitor will visit a set of language objects and return the corresponding SQL string representation.
+ * </p>
*/
public class SQLStringVisitor extends LanguageVisitor {
@@ -138,1099 +137,1010 @@
private static final String BEGIN_HINT = "/*+"; //$NON-NLS-1$
private static final String END_HINT = "*/"; //$NON-NLS-1$
private static final char ID_ESCAPE_CHAR = '\"';
-
- private LinkedList<Object> parts = new LinkedList<Object>();
+ protected StringBuilder parts = new StringBuilder();
+
/**
* Helper to quickly get the parser string for an object using the visitor.
+ *
* @param obj Language object
* @return String SQL String for obj
*/
- public static final String getSQLString(LanguageObject obj) {
- if(obj == null) {
- return UNDEFINED;
+ public static final String getSQLString( LanguageObject obj ) {
+ if (obj == null) {
+ return UNDEFINED;
}
- SQLStringVisitor visitor = new SQLStringVisitor();
+ SQLStringVisitor visitor = new SQLStringVisitor();
obj.acceptVisitor(visitor);
- return visitor.getSQLString();
+ return visitor.getSQLString();
}
/**
* Retrieve completed string from the visitor.
+ *
* @return Complete SQL string for the visited nodes
*/
public String getSQLString() {
- StringBuilder output = new StringBuilder();
- getSQLString(this.parts, output);
- return output.toString();
+ return this.parts.toString();
}
-
- public static void getSQLString(List<Object> parts, StringBuilder output) {
- for (Object object : parts) {
- if (object instanceof List) {
- getSQLString((List<Object>)object, output);
- } else {
- output.append(object);
- }
- }
- }
-
- public List<Object> registerNode(LanguageObject obj) {
+
+ protected void visitNode( LanguageObject obj ) {
if (obj == null) {
- return Arrays.asList((Object)UNDEFINED);
+ append(UNDEFINED);
+ return;
}
- SQLStringVisitor visitor = new SQLStringVisitor();
- obj.acceptVisitor(visitor);
- return visitor.parts;
+ obj.acceptVisitor(this);
}
-
- public void replaceStringParts(Object[] parts) {
- for (int i = 0; i < parts.length; i++) {
- this.parts.add(parts[i]);
- }
+
+ protected void append( Object value ) {
+ this.parts.append(value);
}
+ protected void beginClause( @SuppressWarnings("unused") int level ) {
+ append(SPACE);
+ }
+
// ############ Visitor methods for language objects ####################
- public void visit(BetweenCriteria obj) {
- parts.add(registerNode(obj.getExpression()));
- parts.add(SPACE);
-
+ public void visit( BetweenCriteria obj ) {
+ visitNode(obj.getExpression());
+ append(SPACE);
+
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(BETWEEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getLowerExpression()));
+ append(BETWEEN);
+ append(SPACE);
+ visitNode(obj.getLowerExpression());
- parts.add(SPACE);
- parts.add(AND);
- parts.add(SPACE);
- parts.add(registerNode(obj.getUpperExpression()));
+ append(SPACE);
+ append(AND);
+ append(SPACE);
+ visitNode(obj.getUpperExpression());
}
- public void visit(CaseExpression obj) {
- parts.add(CASE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getExpression()) );
- parts.add(SPACE);
+ public void visit( CaseExpression obj ) {
+ append(CASE);
+ append(SPACE);
+ visitNode(obj.getExpression());
+ append(SPACE);
for (int i = 0; i < obj.getWhenCount(); i++) {
- parts.add(WHEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getWhenExpression(i)) );
- parts.add(SPACE);
- parts.add(THEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getThenExpression(i)));
- parts.add(SPACE);
+ append(WHEN);
+ append(SPACE);
+ visitNode(obj.getWhenExpression(i));
+ append(SPACE);
+ append(THEN);
+ append(SPACE);
+ visitNode(obj.getThenExpression(i));
+ append(SPACE);
}
if (obj.getElseExpression() != null) {
- parts.add(ELSE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getElseExpression()));
- parts.add(SPACE);
+ append(ELSE);
+ append(SPACE);
+ visitNode(obj.getElseExpression());
+ append(SPACE);
}
- parts.add(END);
+ append(END);
}
- public void visit(CompareCriteria obj) {
+ public void visit( CompareCriteria obj ) {
Expression leftExpression = obj.getLeftExpression();
- Object leftPart = registerNode(leftExpression);
-
- String operator = obj.getOperatorAsString();
-
+ visitNode(leftExpression);
+ append(SPACE);
+ append(obj.getOperatorAsString());
+ append(SPACE);
Expression rightExpression = obj.getRightExpression();
- Object rightPart = registerNode(rightExpression);
-
- replaceStringParts(new Object[] { leftPart, SPACE, operator, SPACE, rightPart });
+ visitNode(rightExpression);
}
- public void visit(CompoundCriteria obj) {
+ public void visit( CompoundCriteria obj ) {
// Get operator string
int operator = obj.getOperator();
String operatorStr = ""; //$NON-NLS-1$
- if(operator == CompoundCriteria.AND) {
+ if (operator == CompoundCriteria.AND) {
operatorStr = AND;
- } else if(operator == CompoundCriteria.OR) {
+ } else if (operator == CompoundCriteria.OR) {
operatorStr = OR;
}
// Get criteria
- List subCriteria = obj.getCriteria();
+ List<Criteria> subCriteria = obj.getCriteria();
// Build parts
- if(subCriteria.size() == 1) {
+ if (subCriteria.size() == 1) {
// Special case - should really never happen, but we are tolerant
- Criteria firstChild = (Criteria) subCriteria.get(0);
- replaceStringParts(new Object[] { registerNode(firstChild) });
+ Criteria firstChild = subCriteria.get(0);
+ visitNode(firstChild);
} else {
- // Magic formula - suppose you have 2 sub criteria, then the string
- // has parts: (|x|)| |AND| |(|y|)
- // Each sub criteria has 3 parts and each connector has 3 parts
- // Number of connectors = number of sub criteria - 1
- // # parts = 3n + 3c ; c=n-1
- // = 3n + 3(n-1)
- // = 6n - 3
- Object[] parts = new Object[(6*subCriteria.size())-3];
-
// Add first criteria
- Iterator iter = subCriteria.iterator();
- Criteria crit = (Criteria) iter.next();
- parts[0] = "("; //$NON-NLS-1$
- parts[1] = registerNode(crit);
- parts[2] = ")"; //$NON-NLS-1$
+ Iterator<Criteria> iter = subCriteria.iterator();
- // Add rest of the criteria
- for(int i=3; iter.hasNext(); i=i+6) {
- // Add connector
- parts[i] = SPACE;
- parts[i+1] = operatorStr;
- parts[i+2] = SPACE;
-
+ while (iter.hasNext()) {
// Add criteria
- crit = (Criteria) iter.next();
- parts[i+3] = "("; //$NON-NLS-1$
- parts[i+4] = registerNode(crit);
- parts[i+5] = ")"; //$NON-NLS-1$
- }
+ Criteria crit = iter.next();
+ append(Tokens.LPAREN);
+ visitNode(crit);
+ append(Tokens.RPAREN);
- replaceStringParts(parts);
+ if (iter.hasNext()) {
+ // Add connector
+ append(SPACE);
+ append(operatorStr);
+ append(SPACE);
+ }
+ }
}
}
- public void visit(Delete obj) {
- //add delete clause
- parts.add(DELETE);
- parts.add(SPACE);
- //add from clause
- parts.add(FROM);
- parts.add(SPACE);
- parts.add(registerNode(obj.getGroup()));
+ public void visit( Delete obj ) {
+ // add delete clause
+ append(DELETE);
+ append(SPACE);
+ // add from clause
+ append(FROM);
+ append(SPACE);
+ visitNode(obj.getGroup());
- //add where clause
- if(obj.getCriteria() != null) {
- parts.add(SPACE);
- parts.add(WHERE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getCriteria()));
- }
+ // add where clause
+ if (obj.getCriteria() != null) {
+ beginClause(0);
+ visitCriteria(WHERE, obj.getCriteria());
+ }
- // Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }
+ // Option clause
+ if (obj.getOption() != null) {
+ beginClause(0);
+ visitNode(obj.getOption());
+ }
}
-
- public void visit(DependentSetCriteria obj) {
- parts.add(registerNode(obj.getExpression()));
+ public void visit( DependentSetCriteria obj ) {
+ visitNode(obj.getExpression());
+
// operator and beginning of list
- parts.add(SPACE);
+ append(SPACE);
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(IN);
- parts.add(" (<dependent values>)"); //$NON-NLS-1$
+ append(IN);
+ append(" (<dependent values>)"); //$NON-NLS-1$
}
- public void visit(From obj) {
- Object[] parts = null;
- List clauses = obj.getClauses();
- if(clauses.size() == 1) {
- replaceStringParts(new Object[] {
- FROM, SPACE,
- registerNode( (FromClause) clauses.get(0) ) });
- } else if(clauses.size() > 1) {
- parts = new Object[2 + clauses.size() + (clauses.size()-1)];
+ public void visit( From obj ) {
+ append(FROM);
+ beginClause(1);
+ registerNodes(obj.getClauses(), 0);
+ }
- // Add first clause
- parts[0] = FROM;
- parts[1] = SPACE;
- Iterator clauseIter = clauses.iterator();
- parts[2] = registerNode((FromClause) clauseIter.next());
-
- // Add rest of the clauses
- for(int i=3; clauseIter.hasNext(); i=i+2) {
- parts[i] = ", "; //$NON-NLS-1$
- parts[i+1] = registerNode((FromClause) clauseIter.next());
- }
-
- replaceStringParts(parts);
- } else {
- // Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { FROM });
- }
+ public void visit( GroupBy obj ) {
+ append(GROUP);
+ append(SPACE);
+ append(BY);
+ append(SPACE);
+ registerNodes(obj.getSymbols(), 0);
}
- public void visit(GroupBy obj) {
- Object[] parts = null;
- List symbols = obj.getSymbols();
- if(symbols.size() == 1) {
- replaceStringParts(new Object[] {
- GROUP, SPACE, BY, SPACE,
- registerNode( (Expression) symbols.get(0) ) });
- } else if(symbols.size() > 1) {
- parts = new Object[4 + symbols.size() + (symbols.size()-1)];
+ public void visit( Insert obj ) {
+ append(INSERT);
+ append(SPACE);
+ append(INTO);
+ append(SPACE);
+ visitNode(obj.getGroup());
- // Add first clause
- parts[0] = GROUP;
- parts[1] = SPACE;
- parts[2] = BY;
- parts[3] = SPACE;
- Iterator symbolIter = symbols.iterator();
- parts[4] = registerNode((Expression) symbolIter.next());
+ if (!obj.getVariables().isEmpty()) {
+ beginClause(2);
- // Add rest of the clauses
- for(int i=5; symbolIter.hasNext(); i=i+2) {
- parts[i] = ", "; //$NON-NLS-1$
- parts[i+1] = registerNode((Expression) symbolIter.next());
+ // Columns clause
+ List vars = obj.getVariables();
+ if (vars != null) {
+ append("("); //$NON-NLS-1$
+ registerNodes(vars, 0);
+ append(")"); //$NON-NLS-1$
}
-
- replaceStringParts(parts);
- } else {
- // Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { GROUP, SPACE, BY });
}
- }
-
- public void visit(Insert obj) {
- formatBasicInsert(obj);
-
- if ( obj.getQueryExpression() != null ) {
- parts.add(registerNode(obj.getQueryExpression()));
+ beginClause(1);
+ if (obj.getQueryExpression() != null) {
+ visitNode(obj.getQueryExpression());
} else if (obj.getTupleSource() != null) {
- parts.add(VALUES);
- parts.add(" (...)"); //$NON-NLS-1$
- } else {
- parts.add(VALUES);
- parts.add(" ("); //$NON-NLS-1$
- Iterator valueIter = obj.getValues().iterator();
- while(valueIter.hasNext()) {
- Expression valObj = (Expression) valueIter.next();
- parts.add(registerNode(valObj));
- if(valueIter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
- }
- parts.add(")"); //$NON-NLS-1$
+ append(VALUES);
+ append(" (...)"); //$NON-NLS-1$
+ } else if (obj.getValues() != null) {
+ append(VALUES);
+ beginClause(2);
+ append("("); //$NON-NLS-1$
+ registerNodes(obj.getValues(), 0);
+ append(")"); //$NON-NLS-1$
}
-
- // Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }
+
+ // Option clause
+ if (obj.getOption() != null) {
+ beginClause(1);
+ visitNode(obj.getOption());
+ }
}
- public void visit(Create obj) {
- parts.add(CREATE);
- parts.add(SPACE);
- parts.add(LOCAL);
- parts.add(SPACE);
- parts.add(TEMPORARY);
- parts.add(SPACE);
- parts.add(TABLE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getTable()));
- parts.add(SPACE);
+ public void visit( Create obj ) {
+ append(CREATE);
+ append(SPACE);
+ append(LOCAL);
+ append(SPACE);
+ append(TEMPORARY);
+ append(SPACE);
+ append(TABLE);
+ append(SPACE);
+ visitNode(obj.getTable());
+ append(SPACE);
// Columns clause
List<ElementSymbol> columns = obj.getColumns();
- parts.add("("); //$NON-NLS-1$
+ append("("); //$NON-NLS-1$
Iterator<ElementSymbol> iter = columns.iterator();
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
ElementSymbol element = iter.next();
outputShortName(element);
- parts.add(SPACE);
- parts.add(DataTypeManager.getDataTypeName(element.getType()));
- if(iter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
+ append(SPACE);
+ append(DataTypeManager.getDataTypeName(element.getType()));
+ if (iter.hasNext()) {
+ append(", "); //$NON-NLS-1$
}
}
if (!obj.getPrimaryKey().isEmpty()) {
- parts.add(", "); //$NON-NLS-1$
- parts.add(PRIMARY);
- parts.add(" "); //$NON-NLS-1$
- parts.add(NonReserved.KEY);
- parts.add(Tokens.LPAREN);
- iter = obj.getPrimaryKey().iterator();
- while(iter.hasNext()) {
- outputShortName(iter.next());
- if (iter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
- }
- parts.add(Tokens.RPAREN);
- }
- parts.add(")"); //$NON-NLS-1$
- }
-
- public void visit(Drop obj) {
- parts.add(DROP);
- parts.add(SPACE);
- parts.add(TABLE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getTable()));
- }
-
- private void formatBasicInsert(Insert obj) {
- parts.add(INSERT);
- parts.add(SPACE);
- parts.add(INTO);
- parts.add(SPACE);
- parts.add(registerNode(obj.getGroup()));
- parts.add(SPACE);
-
- if (!obj.getVariables().isEmpty()) {
-
- // Columns clause
- List vars = obj.getVariables();
- if(vars != null) {
- parts.add("("); //$NON-NLS-1$
- Iterator iter = vars.iterator();
- while(iter.hasNext()) {
- ElementSymbol element = (ElementSymbol) iter.next();
- parts.add(registerNode(element));
- if(iter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
+ append(", "); //$NON-NLS-1$
+ append(PRIMARY);
+ append(" "); //$NON-NLS-1$
+ append(NonReserved.KEY);
+ append(Tokens.LPAREN);
+ iter = obj.getPrimaryKey().iterator();
+ while (iter.hasNext()) {
+ outputShortName(iter.next());
+ if (iter.hasNext()) {
+ append(", "); //$NON-NLS-1$
}
- parts.add(") "); //$NON-NLS-1$
}
+ append(Tokens.RPAREN);
}
+ append(")"); //$NON-NLS-1$
}
- public void visit(IsNullCriteria obj) {
+ public void visit( Drop obj ) {
+ append(DROP);
+ append(SPACE);
+ append(TABLE);
+ append(SPACE);
+ visitNode(obj.getTable());
+ }
+
+ public void visit( IsNullCriteria obj ) {
Expression expr = obj.getExpression();
- Object exprPart = registerNode(expr);
- parts.add(exprPart);
- parts.add(SPACE);
- parts.add(IS);
- parts.add(SPACE);
+ visitNode(expr);
+ append(SPACE);
+ append(IS);
+ append(SPACE);
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(NULL);
+ append(NULL);
}
- public void visit(JoinPredicate obj) {
+ public void visit( JoinPredicate obj ) {
addOptionComment(obj);
-
- if(obj.hasHint()) {
- parts.add("(");//$NON-NLS-1$
+
+ if (obj.hasHint()) {
+ append("(");//$NON-NLS-1$
}
// left clause
FromClause leftClause = obj.getLeftClause();
- if(leftClause instanceof JoinPredicate && !((JoinPredicate)leftClause).hasHint()) {
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(leftClause));
- parts.add(")"); //$NON-NLS-1$
- } else {
- parts.add(registerNode(leftClause));
- }
+ if (leftClause instanceof JoinPredicate && !((JoinPredicate)leftClause).hasHint()) {
+ append("("); //$NON-NLS-1$
+ visitNode(leftClause);
+ append(")"); //$NON-NLS-1$
+ } else {
+ visitNode(leftClause);
+ }
// join type
- parts.add(SPACE);
- parts.add(registerNode(obj.getJoinType()));
- parts.add(SPACE);
+ append(SPACE);
+ visitNode(obj.getJoinType());
+ append(SPACE);
// right clause
FromClause rightClause = obj.getRightClause();
- if(rightClause instanceof JoinPredicate && !((JoinPredicate)rightClause).hasHint()) {
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(rightClause));
- parts.add(")"); //$NON-NLS-1$
- } else {
- parts.add(registerNode(rightClause));
- }
+ if (rightClause instanceof JoinPredicate && !((JoinPredicate)rightClause).hasHint()) {
+ append("("); //$NON-NLS-1$
+ visitNode(rightClause);
+ append(")"); //$NON-NLS-1$
+ } else {
+ visitNode(rightClause);
+ }
// join criteria
List joinCriteria = obj.getJoinCriteria();
- if(joinCriteria != null && joinCriteria.size() > 0) {
- parts.add(SPACE);
- parts.add(ON);
- parts.add(SPACE);
- Iterator critIter = joinCriteria.iterator();
- while(critIter.hasNext()) {
- Criteria crit = (Criteria) critIter.next();
- if(crit instanceof PredicateCriteria || crit instanceof AtomicCriteria) {
- parts.add(registerNode(crit));
+ if (joinCriteria != null && joinCriteria.size() > 0) {
+ append(SPACE);
+ append(ON);
+ append(SPACE);
+ Iterator critIter = joinCriteria.iterator();
+ while (critIter.hasNext()) {
+ Criteria crit = (Criteria)critIter.next();
+ if (crit instanceof PredicateCriteria || crit instanceof AtomicCriteria) {
+ visitNode(crit);
} else {
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(crit));
- parts.add(")"); //$NON-NLS-1$
+ append("("); //$NON-NLS-1$
+ visitNode(crit);
+ append(")"); //$NON-NLS-1$
}
- if(critIter.hasNext()) {
- parts.add(SPACE);
- parts.add(AND);
- parts.add(SPACE);
- }
- }
- }
+ if (critIter.hasNext()) {
+ append(SPACE);
+ append(AND);
+ append(SPACE);
+ }
+ }
+ }
- if(obj.hasHint()) {
- parts.add(")"); //$NON-NLS-1$
+ if (obj.hasHint()) {
+ append(")"); //$NON-NLS-1$
}
addFromClasueDepOptions(obj);
}
- private void addFromClasueDepOptions(FromClause obj) {
+ private void addFromClasueDepOptions( FromClause obj ) {
if (obj.isMakeDep()) {
- parts.add(SPACE);
- parts.add(Option.MAKEDEP);
+ append(SPACE);
+ append(Option.MAKEDEP);
}
if (obj.isMakeNotDep()) {
- parts.add(SPACE);
- parts.add(Option.MAKENOTDEP);
+ append(SPACE);
+ append(Option.MAKENOTDEP);
}
}
- private void addOptionComment(FromClause obj) {
- if (obj.isOptional()) {
- parts.add(BEGIN_HINT);
- parts.add(SPACE);
- parts.add(Option.OPTIONAL);
- parts.add(SPACE);
- parts.add(END_HINT);
- parts.add(SPACE);
- }
+ private void addOptionComment( FromClause obj ) {
+ if (obj.isOptional()) {
+ append(BEGIN_HINT);
+ append(SPACE);
+ append(Option.OPTIONAL);
+ append(SPACE);
+ append(END_HINT);
+ append(SPACE);
+ }
}
- public void visit(JoinType obj) {
- Object[] parts = null;
- if(obj.equals(JoinType.JOIN_INNER)) {
- parts = new Object[] { INNER, SPACE, JOIN };
- } else if(obj.equals(JoinType.JOIN_CROSS)) {
- parts = new Object[] { CROSS, SPACE, JOIN };
- } else if(obj.equals(JoinType.JOIN_LEFT_OUTER)) {
- parts = new Object[] { LEFT, SPACE, OUTER, SPACE, JOIN };
- } else if(obj.equals(JoinType.JOIN_RIGHT_OUTER)) {
- parts = new Object[] { RIGHT, SPACE, OUTER, SPACE, JOIN };
- } else if(obj.equals(JoinType.JOIN_FULL_OUTER)) {
- parts = new Object[] { FULL, SPACE, OUTER, SPACE, JOIN };
- } else if(obj.equals(JoinType.JOIN_UNION)) {
- parts = new Object[] { UNION, SPACE, JOIN };
+ public void visit( JoinType obj ) {
+ String[] output = null;
+ if (obj.equals(JoinType.JOIN_INNER)) {
+ output = new String[] {INNER, SPACE, JOIN};
+ } else if (obj.equals(JoinType.JOIN_CROSS)) {
+ output = new String[] {CROSS, SPACE, JOIN};
+ } else if (obj.equals(JoinType.JOIN_LEFT_OUTER)) {
+ output = new String[] {LEFT, SPACE, OUTER, SPACE, JOIN};
+ } else if (obj.equals(JoinType.JOIN_RIGHT_OUTER)) {
+ output = new String[] {RIGHT, SPACE, OUTER, SPACE, JOIN};
+ } else if (obj.equals(JoinType.JOIN_FULL_OUTER)) {
+ output = new String[] {FULL, SPACE, OUTER, SPACE, JOIN};
+ } else if (obj.equals(JoinType.JOIN_UNION)) {
+ output = new String[] {UNION, SPACE, JOIN};
} else if (obj.equals(JoinType.JOIN_SEMI)) {
- parts = new Object[] { "SEMI", SPACE, JOIN }; //$NON-NLS-1$
+ output = new String[] {"SEMI", SPACE, JOIN}; //$NON-NLS-1$
} else if (obj.equals(JoinType.JOIN_ANTI_SEMI)) {
- parts = new Object[] { "ANTI SEMI", SPACE, JOIN }; //$NON-NLS-1$
+ output = new String[] {"ANTI SEMI", SPACE, JOIN}; //$NON-NLS-1$
+ } else {
+ throw new AssertionError();
}
-
- replaceStringParts(parts);
+ for (String part : output) {
+ append(part);
+ }
}
- public void visit(MatchCriteria obj) {
- parts.add(registerNode(obj.getLeftExpression()));
+ public void visit( MatchCriteria obj ) {
+ visitNode(obj.getLeftExpression());
- parts.add(SPACE);
+ append(SPACE);
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(LIKE);
- parts.add(SPACE);
+ append(LIKE);
+ append(SPACE);
- parts.add(registerNode(obj.getRightExpression()));
+ visitNode(obj.getRightExpression());
- if(obj.getEscapeChar() != MatchCriteria.NULL_ESCAPE_CHAR) {
- parts.add(SPACE);
- parts.add(ESCAPE);
- parts.add(" '"); //$NON-NLS-1$
- parts.add("" + obj.getEscapeChar()); //$NON-NLS-1$
- parts.add("'"); //$NON-NLS-1$
+ if (obj.getEscapeChar() != MatchCriteria.NULL_ESCAPE_CHAR) {
+ append(SPACE);
+ append(ESCAPE);
+ append(" '"); //$NON-NLS-1$
+ append("" + obj.getEscapeChar()); //$NON-NLS-1$
+ append("'"); //$NON-NLS-1$
}
}
- public void visit(NotCriteria obj) {
- parts.add(NOT);
- parts.add(" ("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCriteria()));
- parts.add(")"); //$NON-NLS-1$
+ public void visit( NotCriteria obj ) {
+ append(NOT);
+ append(" ("); //$NON-NLS-1$
+ visitNode(obj.getCriteria());
+ append(")"); //$NON-NLS-1$
}
- public void visit(Option obj) {
- parts.add(OPTION);
+ public void visit( Option obj ) {
+ append(OPTION);
Collection groups = obj.getDependentGroups();
- if(groups != null && groups.size() > 0) {
- parts.add(" "); //$NON-NLS-1$
- parts.add(MAKEDEP);
- parts.add(" "); //$NON-NLS-1$
+ if (groups != null && groups.size() > 0) {
+ append(" "); //$NON-NLS-1$
+ append(MAKEDEP);
+ append(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
outputDisplayName((String)iter.next());
-
+
if (iter.hasNext()) {
- parts.add(", ");
+ append(", ");
}
}
}
-
+
groups = obj.getNotDependentGroups();
- if(groups != null && groups.size() > 0) {
- parts.add(" "); //$NON-NLS-1$
- parts.add(MAKENOTDEP);
- parts.add(" "); //$NON-NLS-1$
+ if (groups != null && groups.size() > 0) {
+ append(" "); //$NON-NLS-1$
+ append(MAKENOTDEP);
+ append(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
outputDisplayName((String)iter.next());
-
+
if (iter.hasNext()) {
- parts.add(", ");
+ append(", ");
}
}
}
-
+
groups = obj.getNoCacheGroups();
- if(groups != null && groups.size() > 0) {
- parts.add(" "); //$NON-NLS-1$
- parts.add(NOCACHE);
- parts.add(" "); //$NON-NLS-1$
+ if (groups != null && groups.size() > 0) {
+ append(" "); //$NON-NLS-1$
+ append(NOCACHE);
+ append(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
outputDisplayName((String)iter.next());
-
+
if (iter.hasNext()) {
- parts.add(", ");
+ append(", ");
}
}
- }else if(obj.isNoCache()){
- parts.add(" "); //$NON-NLS-1$
- parts.add(NOCACHE);
+ } else if (obj.isNoCache()) {
+ append(" "); //$NON-NLS-1$
+ append(NOCACHE);
}
}
- public void visit(OrderBy obj) {
- parts.add(ORDER);
- parts.add(SPACE);
- parts.add(BY);
- parts.add(SPACE);
- for (Iterator<OrderByItem> iterator = obj.getOrderByItems().iterator(); iterator.hasNext();) {
- OrderByItem item = iterator.next();
- parts.add(registerNode(item));
- if (iterator.hasNext()) {
- parts.add( ", " ); //$NON-NLS-1$
- }
- }
+ public void visit( OrderBy obj ) {
+ append(ORDER);
+ append(SPACE);
+ append(BY);
+ append(SPACE);
+ for (Iterator<OrderByItem> iterator = obj.getOrderByItems().iterator(); iterator.hasNext();) {
+ OrderByItem item = iterator.next();
+ visitNode(item);
+ if (iterator.hasNext()) {
+ append(", "); //$NON-NLS-1$
+ }
+ }
}
-
+
@Override
- public void visit(OrderByItem obj) {
- SingleElementSymbol ses = obj.getSymbol();
- if (ses instanceof AliasSymbol) {
- AliasSymbol as = (AliasSymbol)ses;
- outputDisplayName(as.getOutputName());
- } else {
- parts.add(registerNode(ses));
- }
- if(!obj.isAscending()) {
- parts.add(SPACE);
- parts.add(DESC);
+ public void visit( OrderByItem obj ) {
+ SingleElementSymbol ses = obj.getSymbol();
+ if (ses instanceof AliasSymbol) {
+ AliasSymbol as = (AliasSymbol)ses;
+ outputDisplayName(as.getOutputName());
+ } else {
+ visitNode(ses);
+ }
+ if (!obj.isAscending()) {
+ append(SPACE);
+ append(DESC);
} // Don't print default "ASC"
if (obj.getNullOrdering() != null) {
- parts.add(SPACE);
- parts.add(NonReserved.NULLS);
- parts.add(SPACE);
- parts.add(obj.getNullOrdering().name());
+ append(SPACE);
+ append(NonReserved.NULLS);
+ append(SPACE);
+ append(obj.getNullOrdering().name());
}
}
-
- public void visit(DynamicCommand obj) {
- parts.add(EXECUTE);
- parts.add(SPACE);
- parts.add(STRING);
- parts.add(SPACE);
- parts.add(registerNode(obj.getSql()));
- if(obj.isAsClauseSet()){
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
+ public void visit( DynamicCommand obj ) {
+ append(EXECUTE);
+ append(SPACE);
+ append(STRING);
+ append(SPACE);
+ visitNode(obj.getSql());
+
+ if (obj.isAsClauseSet()) {
+ beginClause(1);
+ append(AS);
+ append(SPACE);
for (int i = 0; i < obj.getAsColumns().size(); i++) {
ElementSymbol symbol = (ElementSymbol)obj.getAsColumns().get(i);
outputShortName(symbol);
- parts.add(SPACE);
- parts.add(DataTypeManager.getDataTypeName(symbol.getType()));
+ append(SPACE);
+ append(DataTypeManager.getDataTypeName(symbol.getType()));
if (i < obj.getAsColumns().size() - 1) {
- parts.add(", "); //$NON-NLS-1$
+ append(", "); //$NON-NLS-1$
}
}
}
- if(obj.getIntoGroup() != null){
- parts.add(SPACE);
- parts.add(INTO);
- parts.add(SPACE);
- parts.add(registerNode(obj.getIntoGroup()));
+ if (obj.getIntoGroup() != null) {
+ beginClause(1);
+ append(INTO);
+ append(SPACE);
+ visitNode(obj.getIntoGroup());
}
- if(obj.getUsing() != null && !obj.getUsing().isEmpty()) {
- parts.add(SPACE);
- parts.add(USING);
- parts.add(SPACE);
- parts.add(registerNode(obj.getUsing()));
+ if (obj.getUsing() != null && !obj.getUsing().isEmpty()) {
+ beginClause(1);
+ append(USING);
+ append(SPACE);
+ visitNode(obj.getUsing());
}
if (obj.getUpdatingModelCount() > 0) {
- parts.add(SPACE);
- parts.add(UPDATE);
- parts.add(SPACE);
+ beginClause(1);
+ append(UPDATE);
+ append(SPACE);
if (obj.getUpdatingModelCount() > 1) {
- parts.add("*"); //$NON-NLS-1$
+ append("*"); //$NON-NLS-1$
} else {
- parts.add("1"); //$NON-NLS-1$
+ append("1"); //$NON-NLS-1$
}
}
}
- public void visit(SetClauseList obj) {
- for (Iterator<SetClause> iterator = obj.getClauses().iterator(); iterator.hasNext();) {
- SetClause clause = iterator.next();
- parts.add(registerNode(clause));
+ public void visit( SetClauseList obj ) {
+ for (Iterator<SetClause> iterator = obj.getClauses().iterator(); iterator.hasNext();) {
+ SetClause clause = iterator.next();
+ visitNode(clause);
if (iterator.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
+ append(", "); //$NON-NLS-1$
}
- }
+ }
}
-
- public void visit(SetClause obj) {
+
+ public void visit( SetClause obj ) {
ElementSymbol symbol = obj.getSymbol();
outputShortName(symbol);
- parts.add(" = "); //$NON-NLS-1$
- parts.add(registerNode(obj.getValue()));
+ append(" = "); //$NON-NLS-1$
+ visitNode(obj.getValue());
}
- public void visit(Query obj) {
- addCacheHint(obj.getCacheHint());
- parts.add(registerNode(obj.getSelect()));
+ public void visit( Query obj ) {
+ addCacheHint(obj.getCacheHint());
+ visitNode(obj.getSelect());
- if(obj.getInto() != null){
- parts.add(SPACE);
- parts.add(INTO);
- parts.add(SPACE);
- parts.add(registerNode(obj.getInto()));
+ if (obj.getInto() != null) {
+ beginClause(1);
+ visitNode(obj.getInto());
}
- if(obj.getFrom() != null){
- parts.add(SPACE);
- parts.add(registerNode(obj.getFrom()));
+ if (obj.getFrom() != null) {
+ beginClause(1);
+ visitNode(obj.getFrom());
}
// Where clause
- if(obj.getCriteria() != null) {
- parts.add(SPACE);
- parts.add(WHERE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getCriteria()));
+ if (obj.getCriteria() != null) {
+ beginClause(1);
+ visitCriteria(WHERE, obj.getCriteria());
}
- // Group by clause
- if(obj.getGroupBy() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getGroupBy()));
+ // Group by clause
+ if (obj.getGroupBy() != null) {
+ beginClause(1);
+ visitNode(obj.getGroupBy());
}
- // Having clause
- if(obj.getHaving() != null) {
- parts.add(SPACE);
- parts.add(HAVING);
- parts.add(SPACE);
- parts.add(registerNode(obj.getHaving()));
- }
+ // Having clause
+ if (obj.getHaving() != null) {
+ beginClause(1);
+ visitCriteria(HAVING, obj.getHaving());
+ }
- // Order by clause
- if(obj.getOrderBy() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOrderBy()));
- }
-
+ // Order by clause
+ if (obj.getOrderBy() != null) {
+ beginClause(1);
+ visitNode(obj.getOrderBy());
+ }
+
if (obj.getLimit() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getLimit()));
+ beginClause(1);
+ visitNode(obj.getLimit());
}
- // Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }
+ // Option clause
+ if (obj.getOption() != null) {
+ beginClause(1);
+ visitNode(obj.getOption());
+ }
}
- public void visit(SearchedCaseExpression obj) {
- parts.add(CASE);
+ protected void visitCriteria( String keyWord,
+ Criteria crit ) {
+ append(keyWord);
+ append(SPACE);
+ visitNode(crit);
+ }
+
+ public void visit( SearchedCaseExpression obj ) {
+ append(CASE);
for (int i = 0; i < obj.getWhenCount(); i++) {
- parts.add(SPACE);
- parts.add(WHEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getWhenCriteria(i)));
- parts.add(SPACE);
- parts.add(THEN);
- parts.add(SPACE);
- parts.add(registerNode(obj.getThenExpression(i)));
+ append(SPACE);
+ append(WHEN);
+ append(SPACE);
+ visitNode(obj.getWhenCriteria(i));
+ append(SPACE);
+ append(THEN);
+ append(SPACE);
+ visitNode(obj.getThenExpression(i));
}
- parts.add(SPACE);
+ append(SPACE);
if (obj.getElseExpression() != null) {
- parts.add(ELSE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getElseExpression()));
- parts.add(SPACE);
+ append(ELSE);
+ append(SPACE);
+ visitNode(obj.getElseExpression());
+ append(SPACE);
}
- parts.add(END);
+ append(END);
}
- public void visit(Select obj) {
- parts.add(SELECT);
- parts.add(SPACE);
+ public void visit( Select obj ) {
+ append(SELECT);
+ if (obj.isDistinct()) {
+ append(SPACE);
+ append(DISTINCT);
+ }
+ beginClause(2);
- if(obj.isDistinct()) {
- parts.add(DISTINCT);
- parts.add(SPACE);
- }
-
- Iterator iter = obj.getSymbols().iterator();
- while( iter.hasNext() ) {
- SelectSymbol symbol = (SelectSymbol) iter.next();
- parts.add(registerNode(symbol));
- if(iter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
+ Iterator iter = obj.getSymbols().iterator();
+ while (iter.hasNext()) {
+ SelectSymbol symbol = (SelectSymbol)iter.next();
+ visitNode(symbol);
+ if (iter.hasNext()) {
+ append(", "); //$NON-NLS-1$
+ }
}
}
- public void visit(SetCriteria obj) {
- // variable
- parts.add(registerNode(obj.getExpression()));
+ public void visit( SetCriteria obj ) {
+ // variable
+ visitNode(obj.getExpression());
- // operator and beginning of list
- parts.add(SPACE);
+ // operator and beginning of list
+ append(SPACE);
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(IN);
- parts.add(" ("); //$NON-NLS-1$
+ append(IN);
+ append(" ("); //$NON-NLS-1$
- // value list
- Collection vals = obj.getValues();
- int size = vals.size();
- if(size == 1) {
- Iterator iter = vals.iterator();
- Expression expr = (Expression) iter.next();
- parts.add( registerNode( expr ) );
- } else if(size > 1) {
- Iterator iter = vals.iterator();
- Expression expr = (Expression) iter.next();
- parts.add( registerNode( expr ) );
- while(iter.hasNext()) {
- expr = (Expression) iter.next();
- parts.add(", "); //$NON-NLS-1$
- parts.add( registerNode( expr ) );
- }
- }
- parts.add(")"); //$NON-NLS-1$
+ // value list
+ Collection vals = obj.getValues();
+ int size = vals.size();
+ if (size == 1) {
+ Iterator iter = vals.iterator();
+ Expression expr = (Expression)iter.next();
+ visitNode(expr);
+ } else if (size > 1) {
+ Iterator iter = vals.iterator();
+ Expression expr = (Expression)iter.next();
+ visitNode(expr);
+ while (iter.hasNext()) {
+ expr = (Expression)iter.next();
+ append(", "); //$NON-NLS-1$
+ visitNode(expr);
+ }
+ }
+ append(")"); //$NON-NLS-1$
}
- public void visit(SetQuery obj) {
- addCacheHint(obj.getCacheHint());
+ public void visit( SetQuery obj ) {
+ addCacheHint(obj.getCacheHint());
QueryCommand query = obj.getLeftQuery();
- if(query instanceof Query) {
- parts.add(registerNode(query));
- } else {
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(query));
- parts.add(")"); //$NON-NLS-1$
- }
+ appendSetQuery(obj, query, false);
- parts.add(SPACE);
- parts.add(obj.getOperation());
- parts.add(SPACE);
+ beginClause(0);
+ append(obj.getOperation());
- if(obj.isAll()) {
- parts.add(ALL);
- parts.add(SPACE);
+ if (obj.isAll()) {
+ append(SPACE);
+ append(ALL);
}
-
+ beginClause(0);
query = obj.getRightQuery();
- if(query instanceof Query) {
- parts.add(registerNode(query));
- } else {
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(query));
- parts.add(")"); //$NON-NLS-1$
+ appendSetQuery(obj, query, true);
+
+ if (obj.getOrderBy() != null) {
+ beginClause(0);
+ visitNode(obj.getOrderBy());
}
- if(obj.getOrderBy() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOrderBy()));
+ if (obj.getLimit() != null) {
+ beginClause(0);
+ visitNode(obj.getLimit());
}
- if(obj.getLimit() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getLimit()));
+ if (obj.getOption() != null) {
+ beginClause(0);
+ visitNode(obj.getOption());
}
+ }
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
+ protected void appendSetQuery( SetQuery parent,
+ QueryCommand obj,
+ boolean right ) {
+ if (right && obj instanceof SetQuery
+ && ((parent.isAll() && !((SetQuery)obj).isAll()) || parent.getOperation() != ((SetQuery)obj).getOperation())) {
+ append(Tokens.LPAREN);
+ visitNode(obj);
+ append(Tokens.RPAREN);
+ } else {
+ visitNode(obj);
}
}
- public void visit(StoredProcedure obj) {
- addCacheHint(obj.getCacheHint());
- //exec clause
- parts.add(EXEC);
- parts.add(SPACE);
- parts.add(obj.getProcedureName());
- parts.add("("); //$NON-NLS-1$
- List params = obj.getInputParameters();
- if(params != null) {
+ public void visit( StoredProcedure obj ) {
+ addCacheHint(obj.getCacheHint());
+ // exec clause
+ append(EXEC);
+ append(SPACE);
+ append(obj.getProcedureName());
+ append("("); //$NON-NLS-1$
+ List params = obj.getInputParameters();
+ if (params != null) {
Iterator iter = params.iterator();
- while(iter.hasNext()) {
- SPParameter param = (SPParameter) iter.next();
-
- if (obj.displayNamedParameters()) {
- parts.add(escapeSinglePart(ElementSymbol.getShortName(param.getParameterSymbol().getOutputName())));
- parts.add(" => "); //$NON-NLS-1$
+ while (iter.hasNext()) {
+ SPParameter param = (SPParameter)iter.next();
+
+ if (obj.displayNamedParameters()) {
+ append(escapeSinglePart(ElementSymbol.getShortName(param.getParameterSymbol().getOutputName())));
+ append(" => "); //$NON-NLS-1$
}
-
- if(param.getExpression() == null) {
- if(param.getName() != null) {
- outputDisplayName(obj.getParamFullName(param));
+
+ if (param.getExpression() == null) {
+ if (param.getName() != null) {
+ outputDisplayName(obj.getParamFullName(param));
} else {
- parts.add("?"); //$NON-NLS-1$
+ append("?"); //$NON-NLS-1$
}
} else {
- boolean addParens = !obj.displayNamedParameters() && param.getExpression() instanceof CompareCriteria;
- if (addParens) {
- parts.add(Tokens.LPAREN);
- }
- parts.add(registerNode(param.getExpression()));
+ boolean addParens = !obj.displayNamedParameters() && param.getExpression() instanceof CompareCriteria;
if (addParens) {
- parts.add(Tokens.RPAREN);
- }
+ append(Tokens.LPAREN);
+ }
+ visitNode(param.getExpression());
+ if (addParens) {
+ append(Tokens.RPAREN);
+ }
}
- if(iter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
+ if (iter.hasNext()) {
+ append(", "); //$NON-NLS-1$
}
}
}
- parts.add(")"); //$NON-NLS-1$
+ append(")"); //$NON-NLS-1$
// Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }else{
- parts.add(""); //$NON-NLS-1$
- }
+ if (obj.getOption() != null) {
+ beginClause(1);
+ visitNode(obj.getOption());
+ }
}
- public void addCacheHint(CacheHint obj) {
- if (obj == null) {
- return;
- }
- parts.add(BEGIN_HINT);
- parts.add(SPACE);
- parts.add(CacheHint.CACHE);
+ public void addCacheHint( CacheHint obj ) {
+ if (obj == null) {
+ return;
+ }
+ append(BEGIN_HINT);
+ append(SPACE);
+ append(CacheHint.CACHE);
boolean addParens = false;
if (obj.getPrefersMemory()) {
- parts.add(Tokens.LPAREN);
- addParens = true;
- parts.add(CacheHint.PREF_MEM);
+ append(Tokens.LPAREN);
+ addParens = true;
+ append(CacheHint.PREF_MEM);
}
if (obj.getTtl() != null) {
- if (!addParens) {
- parts.add(Tokens.LPAREN);
- addParens = true;
- } else {
- parts.add(SPACE);
- }
- parts.add(CacheHint.TTL);
- parts.add(obj.getTtl());
+ if (!addParens) {
+ append(Tokens.LPAREN);
+ addParens = true;
+ } else {
+ append(SPACE);
+ }
+ append(CacheHint.TTL);
+ append(obj.getTtl());
}
if (obj.isUpdatable()) {
- if (!addParens) {
- parts.add(Tokens.LPAREN);
- addParens = true;
- } else {
- parts.add(SPACE);
- }
- parts.add(CacheHint.UPDATABLE);
+ if (!addParens) {
+ append(Tokens.LPAREN);
+ addParens = true;
+ } else {
+ append(SPACE);
+ }
+ append(CacheHint.UPDATABLE);
}
if (addParens) {
- parts.add(Tokens.RPAREN);
+ append(Tokens.RPAREN);
}
- parts.add(SPACE);
- parts.add(END_HINT);
- parts.add(SPACE);
- }
+ append(SPACE);
+ append(END_HINT);
+ beginClause(0);
+ }
- public void visit(SubqueryFromClause obj) {
+ public void visit( SubqueryFromClause obj ) {
addOptionComment(obj);
if (obj.isTable()) {
- parts.add(TABLE);
+ append(TABLE);
}
- parts.add("(");//$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(")");//$NON-NLS-1$
- parts.add(" AS ");//$NON-NLS-1$
- parts.add(obj.getOutputName());
+ append("(");//$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(")");//$NON-NLS-1$
+ append(" AS ");//$NON-NLS-1$
+ append(obj.getOutputName());
addFromClasueDepOptions(obj);
}
- public void visit(SubquerySetCriteria obj) {
+ public void visit( SubquerySetCriteria obj ) {
// variable
- parts.add(registerNode(obj.getExpression()));
+ visitNode(obj.getExpression());
// operator and beginning of list
- parts.add(SPACE);
+ append(SPACE);
if (obj.isNegated()) {
- parts.add(NOT);
- parts.add(SPACE);
+ append(NOT);
+ append(SPACE);
}
- parts.add(IN);
- parts.add(" ("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(")"); //$NON-NLS-1$
+ append(IN);
+ append(" ("); //$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(")"); //$NON-NLS-1$
}
-
- public void visit(UnaryFromClause obj) {
+ public void visit( UnaryFromClause obj ) {
addOptionComment(obj);
- parts.add(registerNode(obj.getGroup()));
+ visitNode(obj.getGroup());
addFromClasueDepOptions(obj);
}
- public void visit(Update obj) {
+ public void visit( Update obj ) {
// Update clause
- parts.add(UPDATE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getGroup()));
- parts.add(SPACE);
-
+ append(UPDATE);
+ append(SPACE);
+ visitNode(obj.getGroup());
+ beginClause(1);
// Set clause
- parts.add(SET);
- parts.add(SPACE);
+ append(SET);
+ beginClause(2);
+ visitNode(obj.getChangeList());
- parts.add(registerNode(obj.getChangeList()));
-
- // Where clause
- if(obj.getCriteria() != null) {
- parts.add(SPACE);
- parts.add(WHERE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getCriteria()));
- }
+ // Where clause
+ if (obj.getCriteria() != null) {
+ beginClause(1);
+ visitCriteria(WHERE, obj.getCriteria());
+ }
- // Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }
+ // Option clause
+ if (obj.getOption() != null) {
+ beginClause(1);
+ visitNode(obj.getOption());
+ }
}
- public void visit(Into obj) {
- parts.add(registerNode(obj.getGroup()));
+ public void visit( Into obj ) {
+ append(INTO);
+ append(SPACE);
+ visitNode(obj.getGroup());
}
// ############ Visitor methods for symbol objects ####################
- public void visit(AggregateSymbol obj) {
- parts.add(obj.getAggregateFunction().name());
- parts.add("("); //$NON-NLS-1$
+ public void visit( AggregateSymbol obj ) {
+ append(obj.getAggregateFunction().name());
+ append("("); //$NON-NLS-1$
- if(obj.isDistinct()) {
- parts.add(DISTINCT);
- parts.add(" "); //$NON-NLS-1$
- }
+ if (obj.isDistinct()) {
+ append(DISTINCT);
+ append(" "); //$NON-NLS-1$
+ }
- if(obj.getExpression() == null) {
- parts.add(Tokens.ALL_COLS);
- } else {
- parts.add(registerNode(obj.getExpression()));
- }
-
- if (obj.getOrderBy() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOrderBy()));
- }
- parts.add(")"); //$NON-NLS-1$
+ if (obj.getExpression() == null) {
+ append(Tokens.ALL_COLS);
+ } else {
+ visitNode(obj.getExpression());
+ }
+
+ if (obj.getOrderBy() != null) {
+ append(SPACE);
+ visitNode(obj.getOrderBy());
+ }
+ append(")"); //$NON-NLS-1$
}
- public void visit(AliasSymbol obj) {
- parts.add(registerNode(obj.getSymbol()));
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- parts.add(escapeSinglePart(obj.getOutputName()));
+ public void visit( AliasSymbol obj ) {
+ visitNode(obj.getSymbol());
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ append(escapeSinglePart(obj.getOutputName()));
}
- public void visit(AllInGroupSymbol obj) {
- parts.add(obj.getName());
+ public void visit( AllInGroupSymbol obj ) {
+ append(obj.getName());
}
- public void visit(AllSymbol obj) {
- parts.add(obj.getName());
+ public void visit( AllSymbol obj ) {
+ append(obj.getName());
}
- public void visit(Constant obj) {
+ public void visit( Constant obj ) {
Class<?> type = obj.getType();
- Object[] constantParts = null;
+ String[] constantParts = null;
if (obj.isMultiValued()) {
- constantParts = new Object[] {"?"}; //$NON-NLS-1$
- } else if(obj.isNull()) {
- if(type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
- constantParts = new Object[] {UNKNOWN};
- } else {
- constantParts = new Object[] {"null"}; //$NON-NLS-1$
- }
- } else {
- if(Number.class.isAssignableFrom(type)) {
- constantParts = new Object[] { obj.getValue().toString() };
- } else if(type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
- constantParts = new Object[] { obj.getValue().equals(Boolean.TRUE) ? TRUE : FALSE};
- } else if(type.equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
- constantParts = new Object[] { "{ts'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
- } else if(type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
- constantParts = new Object[] { "{t'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
- } else if(type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
- constantParts = new Object[] { "{d'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
- }
+ constantParts = new String[] {"?"}; //$NON-NLS-1$
+ } else if (obj.isNull()) {
+ if (type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
+ constantParts = new String[] {UNKNOWN};
+ } else {
+ constantParts = new String[] {"null"}; //$NON-NLS-1$
+ }
+ } else {
+ if (Number.class.isAssignableFrom(type)) {
+ constantParts = new String[] {obj.getValue().toString()};
+ } else if (type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
+ constantParts = new String[] {obj.getValue().equals(Boolean.TRUE) ? TRUE : FALSE};
+ } else if (type.equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
+ constantParts = new String[] {"{ts'", obj.getValue().toString(), "'}"}; //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
+ constantParts = new String[] {"{t'", obj.getValue().toString(), "'}"}; //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
+ constantParts = new String[] {"{d'", obj.getValue().toString(), "'}"}; //$NON-NLS-1$ //$NON-NLS-2$
+ }
if (constantParts == null) {
- String strValue = obj.getValue().toString();
- strValue = escapeStringValue(strValue, "'"); //$NON-NLS-1$
- constantParts = new Object[] { "'", strValue, "'" }; //$NON-NLS-1$ //$NON-NLS-2$
+ String strValue = obj.getValue().toString();
+ strValue = escapeStringValue(strValue, "'"); //$NON-NLS-1$
+ constantParts = new String[] {"'", strValue, "'"}; //$NON-NLS-1$ //$NON-NLS-2$
}
}
- replaceStringParts(constantParts);
+ for (String string : constantParts) {
+ append(string);
+ }
}
- /**
- * Take a string literal and escape it as necessary. By default, this converts ' to ''.
- * @param str String literal value (unquoted), never null
- * @return Escaped string literal value
- */
- static String escapeStringValue(String str, String tick) {
+ /**
+ * Take a string literal and escape it as necessary. By default, this converts ' to ''.
+ *
+ * @param str String literal value (unquoted), never null
+ * @return Escaped string literal value
+ */
+ static String escapeStringValue( String str,
+ String tick ) {
return StringUtil.replaceAll(str, tick, tick + tick);
}
- public void visit(ElementSymbol obj) {
+ public void visit( ElementSymbol obj ) {
if (obj.getDisplayMode().equals(ElementSymbol.DisplayMode.SHORT_OUTPUT_NAME)) {
outputShortName(obj);
return;
@@ -1241,704 +1151,706 @@
}
outputDisplayName(name);
}
-
- private void outputShortName(ElementSymbol obj) {
- outputDisplayName(SingleElementSymbol.getShortName(obj.getOutputName()));
+
+ private void outputShortName( ElementSymbol obj ) {
+ outputDisplayName(SingleElementSymbol.getShortName(obj.getOutputName()));
}
- private void outputDisplayName(String name) {
+ private void outputDisplayName( String name ) {
String[] pathParts = name.split("\\."); //$NON-NLS-1$
for (int i = 0; i < pathParts.length; i++) {
if (i > 0) {
- parts.add(ElementSymbol.SEPARATOR);
+ append(ElementSymbol.SEPARATOR);
}
- parts.add(escapeSinglePart(pathParts[i]));
+ append(escapeSinglePart(pathParts[i]));
}
}
- public void visit(ExpressionSymbol obj) {
- parts.add(registerNode(obj.getExpression()));
+ public void visit( ExpressionSymbol obj ) {
+ visitNode(obj.getExpression());
}
- public void visit(Function obj) {
+ public void visit( Function obj ) {
String name = obj.getName();
Expression[] args = obj.getArgs();
- if(obj.isImplicit()) {
- // Hide this function, which is implicit
- parts.add(registerNode(args[0]));
+ if (obj.isImplicit()) {
+ // Hide this function, which is implicit
+ visitNode(args[0]);
- } else if(name.equalsIgnoreCase(CONVERT) || name.equalsIgnoreCase(CAST)) {
- parts.add(name);
- parts.add("("); //$NON-NLS-1$
+ } else if (name.equalsIgnoreCase(CONVERT) || name.equalsIgnoreCase(CAST)) {
+ append(name);
+ append("("); //$NON-NLS-1$
- if(args != null && args.length > 0) {
- parts.add(registerNode(args[0]));
+ if (args != null && args.length > 0) {
+ visitNode(args[0]);
- if(name.equalsIgnoreCase(CONVERT)) {
- parts.add(", "); //$NON-NLS-1$
- } else {
- parts.add(" "); //$NON-NLS-1$
- parts.add(AS);
- parts.add(" "); //$NON-NLS-1$
- }
+ if (name.equalsIgnoreCase(CONVERT)) {
+ append(", "); //$NON-NLS-1$
+ } else {
+ append(" "); //$NON-NLS-1$
+ append(AS);
+ append(" "); //$NON-NLS-1$
+ }
- if(args.length < 2 || args[1] == null || !(args[1] instanceof Constant)) {
- parts.add(UNDEFINED);
- } else {
- parts.add(((Constant)args[1]).getValue());
- }
- }
- parts.add(")"); //$NON-NLS-1$
+ if (args.length < 2 || args[1] == null || !(args[1] instanceof Constant)) {
+ append(UNDEFINED);
+ } else {
+ append(((Constant)args[1]).getValue());
+ }
+ }
+ append(")"); //$NON-NLS-1$
- } else if(name.equals("+") || name.equals("-") || name.equals("*") || name.equals("/") || name.equals("||")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- parts.add("("); //$NON-NLS-1$
+ } else if (name.equals("+") || name.equals("-") || name.equals("*") || name.equals("/") || name.equals("||")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ append("("); //$NON-NLS-1$
- if(args != null) {
- for(int i=0; i<args.length; i++) {
- parts.add(registerNode(args[i]));
- if(i < (args.length-1)) {
- parts.add(SPACE);
- parts.add(name);
- parts.add(SPACE);
- }
- }
- }
- parts.add(")"); //$NON-NLS-1$
+ if (args != null) {
+ for (int i = 0; i < args.length; i++) {
+ visitNode(args[i]);
+ if (i < (args.length - 1)) {
+ append(SPACE);
+ append(name);
+ append(SPACE);
+ }
+ }
+ }
+ append(")"); //$NON-NLS-1$
- } else if(name.equalsIgnoreCase(NonReserved.TIMESTAMPADD) || name.equalsIgnoreCase(NonReserved.TIMESTAMPDIFF)) {
- parts.add(name);
- parts.add("("); //$NON-NLS-1$
+ } else if (name.equalsIgnoreCase(NonReserved.TIMESTAMPADD) || name.equalsIgnoreCase(NonReserved.TIMESTAMPDIFF)) {
+ append(name);
+ append("("); //$NON-NLS-1$
- if(args != null && args.length > 0) {
- parts.add(((Constant)args[0]).getValue());
+ if (args != null && args.length > 0) {
+ append(((Constant)args[0]).getValue());
registerNodes(args, 1);
}
- parts.add(")"); //$NON-NLS-1$
+ append(")"); //$NON-NLS-1$
- } else if (name.equalsIgnoreCase(SourceSystemFunctions.XMLPI)){
- parts.add(name);
- parts.add("(NAME "); //$NON-NLS-1$
- outputDisplayName((String)((Constant)args[0]).getValue());
- registerNodes(args, 1);
- parts.add(")"); //$NON-NLS-1$
- } else {
- parts.add(name);
- parts.add("("); //$NON-NLS-1$
- registerNodes(args, 0);
- parts.add(")"); //$NON-NLS-1$
- }
+ } else if (name.equalsIgnoreCase(SourceSystemFunctions.XMLPI)) {
+ append(name);
+ append("(NAME "); //$NON-NLS-1$
+ outputDisplayName((String)((Constant)args[0]).getValue());
+ registerNodes(args, 1);
+ append(")"); //$NON-NLS-1$
+ } else {
+ append(name);
+ append("("); //$NON-NLS-1$
+ registerNodes(args, 0);
+ append(")"); //$NON-NLS-1$
+ }
}
-
- private void registerNodes(LanguageObject[] objects, int begin) {
- registerNodes(Arrays.asList(objects), begin);
+
+ private void registerNodes( LanguageObject[] objects,
+ int begin ) {
+ registerNodes(Arrays.asList(objects), begin);
}
-
- private void registerNodes(List<? extends LanguageObject> objects, int begin) {
- for (int i = begin; i < objects.size(); i++) {
- if (i > 0) {
- parts.add(", "); //$NON-NLS-1$
- }
- parts.add(registerNode(objects.get(i)));
- }
+
+ private void registerNodes( List<? extends LanguageObject> objects,
+ int begin ) {
+ for (int i = begin; i < objects.size(); i++) {
+ if (i > 0) {
+ append(", "); //$NON-NLS-1$
+ }
+ visitNode(objects.get(i));
+ }
}
- public void visit(GroupSymbol obj) {
+ public void visit( GroupSymbol obj ) {
String alias = null;
String fullGroup = obj.getOutputName();
- if(obj.getOutputDefinition() != null) {
+ if (obj.getOutputDefinition() != null) {
alias = obj.getOutputName();
fullGroup = obj.getOutputDefinition();
}
-
+
outputDisplayName(fullGroup);
- if(alias != null) {
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- parts.add(escapeSinglePart(alias));
+ if (alias != null) {
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ append(escapeSinglePart(alias));
}
}
- public void visit(Reference obj) {
+ public void visit( Reference obj ) {
if (!obj.isPositional() && obj.getExpression() != null) {
- replaceStringParts(new Object[] { obj.getExpression().toString() });
+ visitNode(obj.getExpression());
} else {
- replaceStringParts(new Object[] { "?" }); //$NON-NLS-1$
+ append("?"); //$NON-NLS-1$
}
}
// ############ Visitor methods for storedprocedure language objects ####################
- public void visit(Block obj) {
- List statements = obj.getStatements();
- if(statements.size() == 1) {
- replaceStringParts(new Object[] { BEGIN, "\n", //$NON-NLS-1$
- registerNode((Statement)obj.getStatements().get(0)), "\n", END}); //$NON-NLS-1$
- } else if(statements.size() > 1) {
- List parts = new ArrayList();
- // Add first clause
- parts.add(BEGIN);
- parts.add("\n"); //$NON-NLS-1$
- Iterator stmtIter = statements.iterator();
- while(stmtIter.hasNext()) {
- // Add each statement
- parts.add(registerNode((Statement) stmtIter.next()));
- parts.add("\n"); //$NON-NLS-1$
- }
- parts.add(END);
- replaceStringParts(parts.toArray());
- } else {
- // Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { BEGIN, "\n", //$NON-NLS-1$
- END });
+ public void visit( Block obj ) {
+ List statements = obj.getStatements();
+ // Add first clause
+ append(BEGIN);
+ append("\n"); //$NON-NLS-1$
+ Iterator stmtIter = statements.iterator();
+ while (stmtIter.hasNext()) {
+ // Add each statement
+ addTabs(1);
+ visitNode((Statement)stmtIter.next());
+ append("\n"); //$NON-NLS-1$
}
+ addTabs(0);
+ append(END);
}
- public void visit(CommandStatement obj) {
- parts.add(registerNode(obj.getCommand()));
- parts.add(";"); //$NON-NLS-1$
+ protected void addTabs( int level ) {
}
- public void visit(CreateUpdateProcedureCommand obj) {
- parts.add(CREATE);
- parts.add(SPACE);
- if(!obj.isUpdateProcedure()){
- parts.add(VIRTUAL);
- parts.add(SPACE);
+ public void visit( CommandStatement obj ) {
+ visitNode(obj.getCommand());
+ append(";"); //$NON-NLS-1$
+ }
+
+ public void visit( CreateUpdateProcedureCommand obj ) {
+ append(CREATE);
+ append(SPACE);
+ if (!obj.isUpdateProcedure()) {
+ append(VIRTUAL);
+ append(SPACE);
}
- parts.add(PROCEDURE);
- parts.add("\n"); //$NON-NLS-1$
- parts.add(registerNode(obj.getBlock()));
+ append(PROCEDURE);
+ append("\n"); //$NON-NLS-1$
+ addTabs(0);
+ visitNode(obj.getBlock());
}
- public void visit(DeclareStatement obj) {
- parts.add(DECLARE);
- parts.add(SPACE);
- parts.add(obj.getVariableType());
- parts.add(SPACE);
+ public void visit( DeclareStatement obj ) {
+ append(DECLARE);
+ append(SPACE);
+ append(obj.getVariableType());
+ append(SPACE);
createAssignment(obj);
}
- /**
+ /**
* @param obj
* @param parts
*/
- private void createAssignment(AssignmentStatement obj) {
- parts.add(registerNode(obj.getVariable()));
- if (obj.getValue() != null) {
- parts.add(" = "); //$NON-NLS-1$
+ private void createAssignment( AssignmentStatement obj ) {
+ visitNode(obj.getVariable());
+ if (obj.getExpression() != null) {
+ append(" = "); //$NON-NLS-1$
addStatementArgument(obj.getExpression());
}
- parts.add(";"); //$NON-NLS-1$
+ append(";"); //$NON-NLS-1$
}
- private void addStatementArgument(Expression expr) {
- if (expr instanceof ScalarSubquery) {
- parts.add(registerNode(((ScalarSubquery)expr).getCommand()));
- } else {
- parts.add(registerNode(expr));
- }
- }
+ private void addStatementArgument( Expression expr ) {
+ if (expr instanceof ScalarSubquery) {
+ visitNode(((ScalarSubquery)expr).getCommand());
+ } else {
+ visitNode(expr);
+ }
+ }
- public void visit(IfStatement obj) {
- parts.add(IF);
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCondition()));
- parts.add(")\n"); //$NON-NLS-1$
- parts.add(registerNode(obj.getIfBlock()));
- if(obj.hasElseBlock()) {
- parts.add("\n"); //$NON-NLS-1$
- parts.add(ELSE);
- parts.add("\n"); //$NON-NLS-1$
- parts.add(registerNode(obj.getElseBlock()));
+ public void visit( IfStatement obj ) {
+ append(IF);
+ append("("); //$NON-NLS-1$
+ visitNode(obj.getCondition());
+ append(")\n"); //$NON-NLS-1$
+ addTabs(0);
+ visitNode(obj.getIfBlock());
+ if (obj.hasElseBlock()) {
+ append("\n"); //$NON-NLS-1$
+ addTabs(0);
+ append(ELSE);
+ append("\n"); //$NON-NLS-1$
+ addTabs(0);
+ visitNode(obj.getElseBlock());
}
}
- public void visit(AssignmentStatement obj) {
+ public void visit( AssignmentStatement obj ) {
createAssignment(obj);
}
- public void visit(HasCriteria obj) {
- parts.add( HAS);
- parts.add(SPACE);
- parts.add(registerNode(obj.getSelector()));
+ public void visit( HasCriteria obj ) {
+ append(HAS);
+ append(SPACE);
+ visitNode(obj.getSelector());
}
- public void visit(TranslateCriteria obj) {
- parts.add(TRANSLATE);
- parts.add(SPACE);
- parts.add(registerNode(obj.getSelector()));
+ public void visit( TranslateCriteria obj ) {
+ append(TRANSLATE);
+ append(SPACE);
+ visitNode(obj.getSelector());
- if(obj.hasTranslations()) {
- parts.add(SPACE);
- parts.add(WITH);
- parts.add(SPACE);
- parts.add("("); //$NON-NLS-1$
- Iterator critIter = obj.getTranslations().iterator();
+ if (obj.hasTranslations()) {
+ append(SPACE);
+ append(WITH);
+ append(SPACE);
+ append("("); //$NON-NLS-1$
+ Iterator critIter = obj.getTranslations().iterator();
- while(critIter.hasNext()) {
- parts.add(registerNode((Criteria)critIter.next()));
- if(critIter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
- if(!critIter.hasNext()) {
- parts.add(")"); //$NON-NLS-1$
- }
- }
+ while (critIter.hasNext()) {
+ visitNode((Criteria)critIter.next());
+ if (critIter.hasNext()) {
+ append(", "); //$NON-NLS-1$
+ }
+ if (!critIter.hasNext()) {
+ append(")"); //$NON-NLS-1$
+ }
+ }
}
}
- public void visit(CriteriaSelector obj) {
+ public void visit( CriteriaSelector obj ) {
int selectorType = obj.getSelectorType();
- switch(selectorType) {
- case CriteriaSelector.COMPARE_EQ:
- parts.add("= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_GE:
- parts.add(">= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_GT:
- parts.add("> "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_LE:
- parts.add("<= "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_LT:
- parts.add("< "); //$NON-NLS-1$
- break;
- case CriteriaSelector.COMPARE_NE:
- parts.add("<> "); //$NON-NLS-1$
- break;
- case CriteriaSelector.IN:
- parts.add(IN);
- parts.add(SPACE);
- break;
- case CriteriaSelector.IS_NULL:
- parts.add(IS);
- parts.add(SPACE);
- parts.add(NULL);
- parts.add(SPACE);
- break;
+ switch (selectorType) {
+ case CriteriaSelector.COMPARE_EQ:
+ append("= "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.COMPARE_GE:
+ append(">= "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.COMPARE_GT:
+ append("> "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.COMPARE_LE:
+ append("<= "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.COMPARE_LT:
+ append("< "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.COMPARE_NE:
+ append("<> "); //$NON-NLS-1$
+ break;
+ case CriteriaSelector.IN:
+ append(IN);
+ append(SPACE);
+ break;
+ case CriteriaSelector.IS_NULL:
+ append(IS);
+ append(SPACE);
+ append(NULL);
+ append(SPACE);
+ break;
case CriteriaSelector.LIKE:
- parts.add(LIKE);
- parts.add(SPACE);
+ append(LIKE);
+ append(SPACE);
break;
case CriteriaSelector.BETWEEN:
- parts.add(BETWEEN);
- parts.add(SPACE);
+ append(BETWEEN);
+ append(SPACE);
break;
}
- parts.add(CRITERIA);
- if(obj.hasElements()) {
- parts.add(SPACE);
- parts.add(ON);
- parts.add(SPACE);
- parts.add("("); //$NON-NLS-1$
+ append(CRITERIA);
+ if (obj.hasElements()) {
+ append(SPACE);
+ append(ON);
+ append(SPACE);
+ append("("); //$NON-NLS-1$
- Iterator elmtIter = obj.getElements().iterator();
- while(elmtIter.hasNext()) {
- parts.add(registerNode((ElementSymbol)elmtIter.next()));
- if(elmtIter.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
- }
- parts.add(")"); //$NON-NLS-1$
- }
+ Iterator elmtIter = obj.getElements().iterator();
+ while (elmtIter.hasNext()) {
+ visitNode((ElementSymbol)elmtIter.next());
+ if (elmtIter.hasNext()) {
+ append(", "); //$NON-NLS-1$
+ }
+ }
+ append(")"); //$NON-NLS-1$
+ }
}
- public void visit(RaiseErrorStatement obj) {
- parts.add(ERROR);
- parts.add(SPACE);
+ public void visit( RaiseErrorStatement obj ) {
+ append(ERROR);
+ append(SPACE);
addStatementArgument(obj.getExpression());
- parts.add(";"); //$NON-NLS-1$
+ append(";"); //$NON-NLS-1$
}
- public void visit(BreakStatement obj) {
- parts.add(BREAK);
- parts.add(";"); //$NON-NLS-1$
+ public void visit( BreakStatement obj ) {
+ append(BREAK);
+ append(";"); //$NON-NLS-1$
}
- public void visit(ContinueStatement obj) {
- parts.add(CONTINUE);
- parts.add(";"); //$NON-NLS-1$
+ public void visit( ContinueStatement obj ) {
+ append(CONTINUE);
+ append(";"); //$NON-NLS-1$
}
- public void visit(LoopStatement obj) {
- parts.add(LOOP);
- parts.add(" "); //$NON-NLS-1$
- parts.add(ON);
- parts.add(" ("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(") "); //$NON-NLS-1$
- parts.add(AS);
- parts.add(" "); //$NON-NLS-1$
- parts.add(obj.getCursorName());
- parts.add("\n"); //$NON-NLS-1$
- parts.add(registerNode(obj.getBlock()));
+ public void visit( LoopStatement obj ) {
+ append(LOOP);
+ append(" "); //$NON-NLS-1$
+ append(ON);
+ append(" ("); //$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(") "); //$NON-NLS-1$
+ append(AS);
+ append(" "); //$NON-NLS-1$
+ append(obj.getCursorName());
+ append("\n"); //$NON-NLS-1$
+ addTabs(0);
+ visitNode(obj.getBlock());
}
- public void visit(WhileStatement obj) {
- parts.add(WHILE);
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCondition()));
- parts.add(")\n"); //$NON-NLS-1$
- parts.add(registerNode(obj.getBlock()));
+ public void visit( WhileStatement obj ) {
+ append(WHILE);
+ append("("); //$NON-NLS-1$
+ visitNode(obj.getCondition());
+ append(")\n"); //$NON-NLS-1$
+ addTabs(0);
+ visitNode(obj.getBlock());
}
- public void visit(ExistsCriteria obj) {
+ public void visit( ExistsCriteria obj ) {
// operator and beginning of list
- parts.add(EXISTS);
- parts.add(" ("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(")"); //$NON-NLS-1$
+ append(EXISTS);
+ append(" ("); //$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(")"); //$NON-NLS-1$
}
- public void visit(SubqueryCompareCriteria obj){
+ public void visit( SubqueryCompareCriteria obj ) {
Expression leftExpression = obj.getLeftExpression();
- parts.add(registerNode(leftExpression));
+ visitNode(leftExpression);
String operator = obj.getOperatorAsString();
String quantifier = obj.getPredicateQuantifierAsString();
// operator and beginning of list
- parts.add(SPACE);
- parts.add(operator);
- parts.add(SPACE);
- parts.add(quantifier);
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(")"); //$NON-NLS-1$
+ append(SPACE);
+ append(operator);
+ append(SPACE);
+ append(quantifier);
+ append("("); //$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(")"); //$NON-NLS-1$
}
- public void visit(ScalarSubquery obj) {
+ public void visit( ScalarSubquery obj ) {
// operator and beginning of list
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(obj.getCommand()));
- parts.add(")"); //$NON-NLS-1$
+ append("("); //$NON-NLS-1$
+ visitNode(obj.getCommand());
+ append(")"); //$NON-NLS-1$
}
-
+
@Override
- public void visit(XMLAttributes obj) {
- parts.add(XMLATTRIBUTES);
- parts.add("("); //$NON-NLS-1$
- registerNodes(obj.getArgs(), 0);
- parts.add(")"); //$NON-NLS-1$
+ public void visit( XMLAttributes obj ) {
+ append(XMLATTRIBUTES);
+ append("("); //$NON-NLS-1$
+ registerNodes(obj.getArgs(), 0);
+ append(")"); //$NON-NLS-1$
}
-
+
@Override
- public void visit(XMLElement obj) {
- parts.add(XMLELEMENT);
- parts.add("(NAME "); //$NON-NLS-1$
- outputDisplayName(obj.getName());
- if (obj.getNamespaces() != null) {
- parts.add(", "); //$NON-NLS-1$
- parts.add(registerNode(obj.getNamespaces()));
- }
- if (obj.getAttributes() != null) {
- parts.add(", "); //$NON-NLS-1$
- parts.add(registerNode(obj.getAttributes()));
- }
- if (!obj.getContent().isEmpty()) {
- parts.add(", "); //$NON-NLS-1$
- }
- registerNodes(obj.getContent(), 0);
- parts.add(")"); //$NON-NLS-1$
+ public void visit( XMLElement obj ) {
+ append(XMLELEMENT);
+ append("(NAME "); //$NON-NLS-1$
+ outputDisplayName(obj.getName());
+ if (obj.getNamespaces() != null) {
+ append(", "); //$NON-NLS-1$
+ visitNode(obj.getNamespaces());
+ }
+ if (obj.getAttributes() != null) {
+ append(", "); //$NON-NLS-1$
+ visitNode(obj.getAttributes());
+ }
+ if (!obj.getContent().isEmpty()) {
+ append(", "); //$NON-NLS-1$
+ }
+ registerNodes(obj.getContent(), 0);
+ append(")"); //$NON-NLS-1$
}
-
+
@Override
- public void visit(XMLForest obj) {
- parts.add(XMLFOREST);
- parts.add("("); //$NON-NLS-1$
- if (obj.getNamespaces() != null) {
- parts.add(registerNode(obj.getNamespaces()));
- parts.add(", "); //$NON-NLS-1$
- }
- registerNodes(obj.getArgs(), 0);
- parts.add(")"); //$NON-NLS-1$
+ public void visit( XMLForest obj ) {
+ append(XMLFOREST);
+ append("("); //$NON-NLS-1$
+ if (obj.getNamespaces() != null) {
+ visitNode(obj.getNamespaces());
+ append(", "); //$NON-NLS-1$
+ }
+ registerNodes(obj.getArgs(), 0);
+ append(")"); //$NON-NLS-1$
}
-
+
@Override
- public void visit(XMLNamespaces obj) {
- parts.add(XMLNAMESPACES);
- parts.add("("); //$NON-NLS-1$
- for (Iterator<NamespaceItem> items = obj.getNamespaceItems().iterator(); items.hasNext();) {
- NamespaceItem item = items.next();
- if (item.getPrefix() == null) {
- if (item.getUri() == null) {
- parts.add("NO DEFAULT"); //$NON-NLS-1$
- } else {
- parts.add("DEFAULT "); //$NON-NLS-1$
- parts.add(registerNode(new Constant(item.getUri())));
- }
- } else {
- parts.add(registerNode(new Constant(item.getUri())));
- parts.add(" AS "); //$NON-NLS-1$
- outputDisplayName(item.getPrefix());
- }
- if (items.hasNext()) {
- parts.add(", "); //$NON-NLS-1$
- }
- }
- parts.add(")"); //$NON-NLS-1$
+ public void visit( XMLNamespaces obj ) {
+ append(XMLNAMESPACES);
+ append("("); //$NON-NLS-1$
+ for (Iterator<NamespaceItem> items = obj.getNamespaceItems().iterator(); items.hasNext();) {
+ NamespaceItem item = items.next();
+ if (item.getPrefix() == null) {
+ if (item.getUri() == null) {
+ append("NO DEFAULT"); //$NON-NLS-1$
+ } else {
+ append("DEFAULT "); //$NON-NLS-1$
+ visitNode(new Constant(item.getUri()));
+ }
+ } else {
+ visitNode(new Constant(item.getUri()));
+ append(" AS "); //$NON-NLS-1$
+ outputDisplayName(item.getPrefix());
+ }
+ if (items.hasNext()) {
+ append(", "); //$NON-NLS-1$
+ }
+ }
+ append(")"); //$NON-NLS-1$
}
-
- public void visit(Limit obj) {
- parts.add(LIMIT);
+
+ public void visit( Limit obj ) {
+ append(LIMIT);
if (obj.getOffset() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOffset()));
- parts.add(","); //$NON-NLS-1$
+ append(SPACE);
+ visitNode(obj.getOffset());
+ append(","); //$NON-NLS-1$
}
- parts.add(SPACE);
- parts.add(registerNode(obj.getRowLimit()));
+ append(SPACE);
+ visitNode(obj.getRowLimit());
}
-
+
@Override
- public void visit(TextTable obj) {
- parts.add("TEXTTABLE("); //$NON-NLS-1$
- parts.add(registerNode(obj.getFile()));
- parts.add(SPACE);
- parts.add(NonReserved.COLUMNS);
-
- for (Iterator<TextColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
- TextColumn col = cols.next();
- parts.add(SPACE);
- outputDisplayName(col.getName());
- parts.add(SPACE);
- parts.add(col.getType());
- if (col.getWidth() != null) {
- parts.add(SPACE);
- parts.add(NonReserved.WIDTH);
- parts.add(SPACE);
- parts.add(col.getWidth());
- }
- if (cols.hasNext()) {
- parts.add(","); //$NON-NLS-1$
- }
- }
- if (obj.getDelimiter() != null) {
- parts.add(SPACE);
- parts.add(NonReserved.DELIMITER);
- parts.add(SPACE);
- parts.add(registerNode(new Constant(obj.getDelimiter())));
- }
- if (obj.getQuote() != null) {
- parts.add(SPACE);
- if (obj.isEscape()) {
- parts.add(ESCAPE);
- } else {
- parts.add(NonReserved.QUOTE);
- }
- parts.add(SPACE);
- parts.add(registerNode(new Constant(obj.getQuote())));
- }
- if (obj.getHeader() != null) {
- parts.add(SPACE);
- parts.add(NonReserved.HEADER);
- if (1 != obj.getHeader()) {
- parts.add(SPACE);
- parts.add(obj.getHeader());
- }
- }
- if (obj.getSkip() != null) {
- parts.add(SPACE);
- parts.add("SKIP"); //$NON-NLS-1$
- parts.add(SPACE);
- parts.add(obj.getSkip());
- }
- parts.add(")");//$NON-NLS-1$
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- outputDisplayName(obj.getName());
+ public void visit( TextTable obj ) {
+ append("TEXTTABLE("); //$NON-NLS-1$
+ visitNode(obj.getFile());
+ append(SPACE);
+ append(NonReserved.COLUMNS);
+
+ for (Iterator<TextColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
+ TextColumn col = cols.next();
+ append(SPACE);
+ outputDisplayName(col.getName());
+ append(SPACE);
+ append(col.getType());
+ if (col.getWidth() != null) {
+ append(SPACE);
+ append(NonReserved.WIDTH);
+ append(SPACE);
+ append(col.getWidth());
+ }
+ if (cols.hasNext()) {
+ append(","); //$NON-NLS-1$
+ }
+ }
+ if (obj.getDelimiter() != null) {
+ append(SPACE);
+ append(NonReserved.DELIMITER);
+ append(SPACE);
+ visitNode(new Constant(obj.getDelimiter()));
+ }
+ if (obj.getQuote() != null) {
+ append(SPACE);
+ if (obj.isEscape()) {
+ append(ESCAPE);
+ } else {
+ append(NonReserved.QUOTE);
+ }
+ append(SPACE);
+ visitNode(new Constant(obj.getQuote()));
+ }
+ if (obj.getHeader() != null) {
+ append(SPACE);
+ append(NonReserved.HEADER);
+ if (1 != obj.getHeader()) {
+ append(SPACE);
+ append(obj.getHeader());
+ }
+ }
+ if (obj.getSkip() != null) {
+ append(SPACE);
+ append("SKIP"); //$NON-NLS-1$
+ append(SPACE);
+ append(obj.getSkip());
+ }
+ append(")");//$NON-NLS-1$
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ outputDisplayName(obj.getName());
}
@Override
- public void visit(XMLTable obj) {
- parts.add("XMLTABLE("); //$NON-NLS-1$
- if (obj.getNamespaces() != null) {
- parts.add(registerNode(obj.getNamespaces()));
- parts.add(","); //$NON-NLS-1$
- parts.add(SPACE);
- }
- parts.add(new Constant(obj.getXquery()));
- if (!obj.getPassing().isEmpty()) {
- parts.add(SPACE);
- parts.add(NonReserved.PASSING);
- parts.add(SPACE);
- registerNodes(obj.getPassing(), 0);
- }
- if (!obj.getColumns().isEmpty()) {
- parts.add(SPACE);
- parts.add(NonReserved.COLUMNS);
- for (Iterator<XMLColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
- XMLColumn col = cols.next();
- parts.add(SPACE);
- outputDisplayName(col.getName());
- parts.add(SPACE);
- if (col.isOrdinal()) {
- parts.add(FOR);
- parts.add(SPACE);
- parts.add(NonReserved.ORDINALITY);
- } else {
- parts.add(col.getType());
- if (col.getDefaultExpression() != null) {
- parts.add(SPACE);
- parts.add(DEFAULT);
- parts.add(SPACE);
- parts.add(registerNode(col.getDefaultExpression()));
- }
- if (col.getPath() != null) {
- parts.add(SPACE);
- parts.add(NonReserved.PATH);
- parts.add(SPACE);
- parts.add(new Constant(col.getPath()));
- }
- }
- if (cols.hasNext()) {
- parts.add(","); //$NON-NLS-1$
- }
- }
- }
- parts.add(")");//$NON-NLS-1$
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- outputDisplayName(obj.getName());
+ public void visit( XMLTable obj ) {
+ append("XMLTABLE("); //$NON-NLS-1$
+ if (obj.getNamespaces() != null) {
+ visitNode(obj.getNamespaces());
+ append(","); //$NON-NLS-1$
+ append(SPACE);
+ }
+ visitNode(new Constant(obj.getXquery()));
+ if (!obj.getPassing().isEmpty()) {
+ append(SPACE);
+ append(NonReserved.PASSING);
+ append(SPACE);
+ registerNodes(obj.getPassing(), 0);
+ }
+ if (!obj.getColumns().isEmpty()) {
+ append(SPACE);
+ append(NonReserved.COLUMNS);
+ for (Iterator<XMLColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
+ XMLColumn col = cols.next();
+ append(SPACE);
+ outputDisplayName(col.getName());
+ append(SPACE);
+ if (col.isOrdinal()) {
+ append(FOR);
+ append(SPACE);
+ append(NonReserved.ORDINALITY);
+ } else {
+ append(col.getType());
+ if (col.getDefaultExpression() != null) {
+ append(SPACE);
+ append(DEFAULT);
+ append(SPACE);
+ visitNode(col.getDefaultExpression());
+ }
+ if (col.getPath() != null) {
+ append(SPACE);
+ append(NonReserved.PATH);
+ append(SPACE);
+ visitNode(new Constant(col.getPath()));
+ }
+ }
+ if (cols.hasNext()) {
+ append(","); //$NON-NLS-1$
+ }
+ }
+ }
+ append(")");//$NON-NLS-1$
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ outputDisplayName(obj.getName());
}
-
+
@Override
- public void visit(XMLQuery obj) {
- parts.add("XMLQUERY("); //$NON-NLS-1$
- if (obj.getNamespaces() != null) {
- parts.add(registerNode(obj.getNamespaces()));
- parts.add(","); //$NON-NLS-1$
- parts.add(SPACE);
- }
- parts.add(new Constant(obj.getXquery()));
- if (!obj.getPassing().isEmpty()) {
- parts.add(SPACE);
- parts.add(NonReserved.PASSING);
- parts.add(SPACE);
- registerNodes(obj.getPassing(), 0);
- }
- if (obj.getEmptyOnEmpty() != null) {
- parts.add(SPACE);
- if (obj.getEmptyOnEmpty()) {
- parts.add(NonReserved.EMPTY);
- } else {
- parts.add(NULL);
- }
- parts.add(SPACE);
- parts.add(ON);
- parts.add(SPACE);
- parts.add(NonReserved.EMPTY);
- }
- parts.add(")");//$NON-NLS-1$
+ public void visit( XMLQuery obj ) {
+ append("XMLQUERY("); //$NON-NLS-1$
+ if (obj.getNamespaces() != null) {
+ visitNode(obj.getNamespaces());
+ append(","); //$NON-NLS-1$
+ append(SPACE);
+ }
+ visitNode(new Constant(obj.getXquery()));
+ if (!obj.getPassing().isEmpty()) {
+ append(SPACE);
+ append(NonReserved.PASSING);
+ append(SPACE);
+ registerNodes(obj.getPassing(), 0);
+ }
+ if (obj.getEmptyOnEmpty() != null) {
+ append(SPACE);
+ if (obj.getEmptyOnEmpty()) {
+ append(NonReserved.EMPTY);
+ } else {
+ append(NULL);
+ }
+ append(SPACE);
+ append(ON);
+ append(SPACE);
+ append(NonReserved.EMPTY);
+ }
+ append(")");//$NON-NLS-1$
}
-
+
@Override
- public void visit(DerivedColumn obj) {
- parts.add(registerNode(obj.getExpression()));
- if (obj.getAlias() != null) {
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- outputDisplayName(obj.getAlias());
- }
+ public void visit( DerivedColumn obj ) {
+ visitNode(obj.getExpression());
+ if (obj.getAlias() != null) {
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ outputDisplayName(obj.getAlias());
+ }
}
-
+
@Override
- public void visit(XMLSerialize obj) {
- parts.add(XMLSERIALIZE);
- parts.add(Tokens.LPAREN);
- if (obj.isDocument() != null) {
- if (obj.isDocument()) {
- parts.add(NonReserved.DOCUMENT);
- } else {
- parts.add(NonReserved.CONTENT);
- }
- parts.add(SPACE);
- }
- parts.add(registerNode(obj.getExpression()));
- if (obj.getTypeString() != null) {
- parts.add(SPACE);
- parts.add(AS);
- parts.add(SPACE);
- parts.add(obj.getTypeString());
- }
- parts.add(Tokens.RPAREN);
+ public void visit( XMLSerialize obj ) {
+ append(XMLSERIALIZE);
+ append(Tokens.LPAREN);
+ if (obj.isDocument() != null) {
+ if (obj.isDocument()) {
+ append(NonReserved.DOCUMENT);
+ } else {
+ append(NonReserved.CONTENT);
+ }
+ append(SPACE);
+ }
+ visitNode(obj.getExpression());
+ if (obj.getTypeString() != null) {
+ append(SPACE);
+ append(AS);
+ append(SPACE);
+ append(obj.getTypeString());
+ }
+ append(Tokens.RPAREN);
}
-
+
@Override
- public void visit(QueryString obj) {
- parts.add(NonReserved.QUERYSTRING);
- parts.add("("); //$NON-NLS-1$
- parts.add(registerNode(obj.getPath()));
- if (!obj.getArgs().isEmpty()) {
- parts.add(","); //$NON-NLS-1$
- parts.add(SPACE);
- registerNodes(obj.getArgs(), 0);
- }
- parts.add(")"); //$NON-NLS-1$
+ public void visit( QueryString obj ) {
+ append(NonReserved.QUERYSTRING);
+ append("("); //$NON-NLS-1$
+ visitNode(obj.getPath());
+ if (!obj.getArgs().isEmpty()) {
+ append(","); //$NON-NLS-1$
+ append(SPACE);
+ registerNodes(obj.getArgs(), 0);
+ }
+ append(")"); //$NON-NLS-1$
}
-
+
@Override
- public void visit(XMLParse obj) {
- parts.add(XMLPARSE);
- parts.add(Tokens.LPAREN);
- if (obj.isDocument()) {
- parts.add(NonReserved.DOCUMENT);
- } else {
- parts.add(NonReserved.CONTENT);
- }
- parts.add(SPACE);
- parts.add(registerNode(obj.getExpression()));
- if (obj.isWellFormed()) {
- parts.add(SPACE);
- parts.add(NonReserved.WELLFORMED);
- }
- parts.add(Tokens.RPAREN);
+ public void visit( XMLParse obj ) {
+ append(XMLPARSE);
+ append(Tokens.LPAREN);
+ if (obj.isDocument()) {
+ append(NonReserved.DOCUMENT);
+ } else {
+ append(NonReserved.CONTENT);
+ }
+ append(SPACE);
+ visitNode(obj.getExpression());
+ if (obj.isWellFormed()) {
+ append(SPACE);
+ append(NonReserved.WELLFORMED);
+ }
+ append(Tokens.RPAREN);
}
-
+
@Override
- public void visit(ExpressionCriteria obj) {
- obj.getExpression().acceptVisitor(this);
+ public void visit( ExpressionCriteria obj ) {
+ visitNode(obj.getExpression());
}
- public static String escapeSinglePart(String part) {
- if(isReservedWord(part)) {
- return ID_ESCAPE_CHAR + part + ID_ESCAPE_CHAR;
- }
- boolean escape = true;
- char start = part.charAt(0);
- if (start == '#' || start == '@' || StringUtil.isLetter(start)) {
- escape = false;
- for (int i = 1; !escape && i < part.length(); i++) {
- char c = part.charAt(i);
- escape = !StringUtil.isLetterOrDigit(c) && c != '_';
- }
- }
- if (escape) {
- return ID_ESCAPE_CHAR + escapeStringValue(part, "\"") + ID_ESCAPE_CHAR; //$NON-NLS-1$
- }
- return part;
+ public static String escapeSinglePart( String part ) {
+ if (isReservedWord(part)) {
+ return ID_ESCAPE_CHAR + part + ID_ESCAPE_CHAR;
+ }
+ boolean escape = true;
+ char start = part.charAt(0);
+ if (start == '#' || start == '@' || StringUtil.isLetter(start)) {
+ escape = false;
+ for (int i = 1; !escape && i < part.length(); i++) {
+ char c = part.charAt(i);
+ escape = !StringUtil.isLetterOrDigit(c) && c != '_';
+ }
+ }
+ if (escape) {
+ return ID_ESCAPE_CHAR + escapeStringValue(part, "\"") + ID_ESCAPE_CHAR; //$NON-NLS-1$
+ }
+ return part;
}
/**
- * Check whether a string is considered a reserved word or not. Subclasses
- * may override to change definition of reserved word.
+ * Check whether a string is considered a reserved word or not. Subclasses may override to change definition of reserved word.
+ *
* @param string String to check
* @return True if reserved word
*/
- static boolean isReservedWord(String string) {
- if(string == null) {
- return false;
- }
- return SQLConstants.isReservedWord(string);
+ static boolean isReservedWord( String string ) {
+ if (string == null) {
+ return false;
+ }
+ return SQLConstants.isReservedWord(string);
}
-
+
}
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-08-23 17:53:50 UTC (rev 2484)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-08-23 19:19:45 UTC (rev 2485)
@@ -4667,7 +4667,7 @@
ProcessorPlan plan = helpPlan(sql,
FakeMetadataFactory.exampleBQTCached(),
null, capFinder,
- new String[] {"(SELECT g_2.intkey AS c_0, 'a' AS c_1 FROM BQT1.SmallA AS g_2 UNION ALL SELECT g_1.IntKey AS c_0, 'b' AS c_1 FROM BQT1.SmallA AS g_1) UNION ALL SELECT g_0.IntKey AS c_0, 'c' AS c_1 FROM BQT1.SmallA AS g_0"}, //$NON-NLS-1$
+ new String[] {"SELECT g_2.intkey AS c_0, 'a' AS c_1 FROM BQT1.SmallA AS g_2 UNION ALL SELECT g_1.IntKey AS c_0, 'b' AS c_1 FROM BQT1.SmallA AS g_1 UNION ALL SELECT g_0.IntKey AS c_0, 'c' AS c_1 FROM BQT1.SmallA AS g_0"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
checkNodeTypes(plan, FULL_PUSHDOWN);
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java 2010-08-23 17:53:50 UTC (rev 2484)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java 2010-08-23 19:19:45 UTC (rev 2485)
@@ -197,7 +197,7 @@
setQuery = new SetQuery(Operation.UNION, false, setQuery, query);
TestParser.helpTest("select c1 from g1 union select c2 from g2 union select c3 from g3", //$NON-NLS-1$
- "(SELECT c1 FROM g1 UNION SELECT c2 FROM g2) UNION SELECT c3 FROM g3", //$NON-NLS-1$
+ "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION SELECT c3 FROM g3", //$NON-NLS-1$
setQuery);
}
@@ -258,7 +258,7 @@
setQuery = new SetQuery(SetQuery.Operation.UNION, false, setQuery, query);
TestParser.helpTest("select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4", //$NON-NLS-1$
- "((SELECT c1 FROM g1 UNION SELECT c2 FROM g2) UNION ALL SELECT c3 FROM g3) UNION SELECT c4 FROM g4", //$NON-NLS-1$
+ "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION ALL SELECT c3 FROM g3 UNION SELECT c4 FROM g4", //$NON-NLS-1$
setQuery);
}
14 years, 4 months