teiid SVN: r3327 - in trunk: api/src/main/java/org/teiid/language/visitor and 36 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-22 12:26:08 -0400 (Fri, 22 Jul 2011)
New Revision: 3327
Added:
trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected
Modified:
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml
trunk/build/kits/jboss-container/teiid-releasenotes.html
trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java
trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java
trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java
trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
trunk/engine/pom.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/NodeConstants.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocumentWrapper.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/NodeWrapper.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/FakeConnector.java
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorWorkItem.java
trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestElementImpl.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java
trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
trunk/pom.xml
trunk/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
Log:
forward merge of 7.4.1
Modified: trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -284,8 +284,7 @@
if(elementID != null) {
elemShortName = getName(elementID);
} else {
- String elementName = obj.getName();
- elemShortName = getShortName(elementName);
+ elemShortName = obj.getName();
}
// Check whether a subclass wants to replace the element name to use in special circumstances
Modified: trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml
===================================================================
--- trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/build/kits/jboss-container/deploy/teiid/teiid-cache-manager-jboss-beans-rename-me.xml 2011-07-22 16:26:08 UTC (rev 3327)
@@ -85,7 +85,7 @@
<!-- Hibernate 2LC can replicate custom types, so we use marshalling -->
<property name="useRegionBasedMarshalling">true</property>
<!-- Must match the value of "useRegionBasedMarshalling" -->
- <property name="inactiveOnStartup">true</property>
+ <property name="inactiveOnStartup">false</property>
<!-- Disable asynchronous RPC marshalling/sending -->
<property name="serializationExecutorPoolSize">0</property>
Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-07-22 16:26:08 UTC (rev 3327)
@@ -34,7 +34,9 @@
<LI><B>Streaming XQuery</B> - in situations where document projection applies if the XMLQUERY/XMLTABLE path expressions meet certain conditions, then the incoming document will not only be projected, but the independent subtrees will be processed without loading the entire document. This allows for nearly arbitrarily large XML documents to be processed. See the Reference for more.
<LI><B>Logging Procedures</B> - added SYSADMIN.isLoggable and SYSADMIN.logMsg to aid in debugging procedure logic.
<LI><B>ANSI OFFSET/FETCH FIRST</B> - instead of the limit clause, a standard OFFSET and/or FETCH FIRST/NEXT clause can be used to limit results.
+ <LI><B>ODBC Cursors</B> - Capability to use "UseDeclareFetch" with ODBC is added. This enables user to read the results in batches, especially useful when dealing with large row count of results.
</UL>
+
<h2><a name="Compatibility">Compatibility Issues</a></h2>
<ul>
<li>TRANSLATE/HAS CRITERIA has been deprecated. An alternative approach to update procedures will be introduced in a subsequent version.
@@ -45,6 +47,8 @@
<h4>from 7.4</h4>
<ul>
<li>OFFSET was added as a keyword.
+ <li>ColumnReference.getName will always return just the element name. Previously it inconsistently returned the qualified and unqualified form depending upon where the ColumnReference appeared.
+ <li>As per JDBC4, ResultSetMetadata.getColumnName will return the unaliased column name if available rather than return the alias. Set useJDBC4ColumnNameAndLabelSemantics to false to use the alias name as the column name.
</ul>
<h4>from 7.3</h4>
Modified: trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCacheFactory.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -59,6 +59,7 @@
if (!this.cacheStore.getCacheStatus().allowInvocations()) {
this.cacheStore.start();
+ this.cacheStore.getRegion(this.cacheStore.getRoot().getFqn(), true).activate();
}
Node cacheRoot = this.cacheStore.getRoot().addChild(Fqn.fromString("Teiid")); //$NON-NLS-1$
@@ -67,6 +68,7 @@
Region cacheRegion = this.cacheStore.getRegion(node.getFqn(), true);
cacheRegion.setEvictionRegionConfig(buildEvictionConfig(node.getFqn(), config));
+ cacheRegion.activate();
JBossCache jc = null;
if (config != null && config.getPolicy().equals(Policy.EXPIRATION)) {
Modified: trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -1433,18 +1433,21 @@
// query string to be submitted to get table metadata info
StringBuffer sqlQuery = new StringBuffer(QUERY_TABLES);
- StringBuffer typesString = new StringBuffer("("); // criteria string for different table types //$NON-NLS-1$
-
if (types != null) {
- // construct the criteria string
- for(int i=0; i < types.length; i++) {
- if (types[i] != null && types[i].length() > 0) {
- if (i > 0) {
- typesString.append(" OR "); //$NON-NLS-1$
- }
- typesString.append(TABLE_TYPE).append(LIKE_ESCAPE);
- }
- }
+ StringBuffer typesString = new StringBuffer("("); // criteria string for different table types //$NON-NLS-1$
+ if (types.length == 0) {
+ typesString.append("1 = 0"); //$NON-NLS-1$
+ } else {
+ // construct the criteria string
+ for(int i=0; i < types.length; i++) {
+ if (types[i] != null && types[i].length() > 0) {
+ if (i > 0) {
+ typesString.append(" OR "); //$NON-NLS-1$
+ }
+ typesString.append(TABLE_TYPE).append(LIKE_ESCAPE);
+ }
+ }
+ }
typesString.append(")"); //$NON-NLS-1$
sqlQuery.append(" AND ").append(typesString.toString()); //$NON-NLS-1$
}
Property changes on: trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java:3281-3325
Modified: trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -58,7 +58,8 @@
ExecutionProperties.PROP_XML_FORMAT,
ExecutionProperties.PROP_XML_VALIDATION,
EmbeddedProfile.USE_CALLING_THREAD,
- ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS)));
+ ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS,
+ ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS)));
public static final Set<String> KNOWN_PROPERTIES = getKnownProperties();
Property changes on: trunk/client/src/main/java/org/teiid/jdbc/JDBCURL.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3149-3217
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/JDBCURL.java:3149-3217,3281-3325
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -39,7 +39,9 @@
public ResultSetMetaDataImpl(MetadataProvider provider, String supportBackwardsCompatibility) {
this.provider = provider;
- this.useJDBC4ColumnNameAndLabelSemantics = (supportBackwardsCompatibility != null && supportBackwardsCompatibility.equalsIgnoreCase("false") ? false : true);
+ if (supportBackwardsCompatibility != null) {
+ this.useJDBC4ColumnNameAndLabelSemantics = Boolean.parseBoolean(supportBackwardsCompatibility);
+ }
}
/**
Property changes on: trunk/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java:3281-3325
Modified: trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -40,8 +40,6 @@
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@@ -538,11 +536,7 @@
});
if (synch) {
try {
- if (queryTimeoutMS > 0) {
- pendingResult.get(queryTimeoutMS, TimeUnit.MILLISECONDS);
- } else {
- pendingResult.get();
- }
+ pendingResult.get();
result.get(); //throw an exception if needed
return result;
} catch (ExecutionException e) {
@@ -552,8 +546,6 @@
throw TeiidSQLException.create(e);
} catch (InterruptedException e) {
timeoutOccurred();
- } catch (TimeoutException e) {
- timeoutOccurred();
}
throw new TeiidSQLException(JDBCPlugin.Util.getString("MMStatement.Timeout_before_complete")); //$NON-NLS-1$
}
@@ -578,7 +570,7 @@
reqMsg.setExecutionId(this.currentRequestID);
ResultsFuture.CompletionListener<ResultsMessage> compeletionListener = null;
- if (queryTimeoutMS > 0 && !synch) {
+ if (queryTimeoutMS > 0) {
final CancelTask c = new QueryTimeoutCancelTask(queryTimeoutMS, this);
cancellationTimer.add(c);
compeletionListener = new ResultsFuture.CompletionListener<ResultsMessage>() {
Property changes on: trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3149-3217,3220-3275
+ /branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java:3149-3217,3220-3275,3281-3325
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -22,7 +22,8 @@
package org.teiid.jdbc;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
import java.sql.SQLException;
import java.util.Properties;
@@ -38,8 +39,6 @@
import org.teiid.client.util.ResultsFuture;
import org.teiid.client.xa.XATransactionException;
import org.teiid.client.xa.XidImpl;
-import org.teiid.jdbc.BaseDataSource;
-import org.teiid.jdbc.ConnectionImpl;
import org.teiid.net.ServerConnection;
@@ -48,13 +47,28 @@
protected static final String STD_DATABASE_NAME = "QT_Ora9DS"; //$NON-NLS-1$
protected static final int STD_DATABASE_VERSION = 1;
- static String serverUrl = "jdbc:metamatrix:QT_Ora9DS@mm://localhost:7001;version=1;user=metamatrixadmin;password=mm"; //$NON-NLS-1$
+ static String serverUrl = "jdbc:teiid:QT_Ora9DS@mm://localhost:7001;version=1;user=metamatrixadmin;password=mm"; //$NON-NLS-1$
public TestConnection(String name) {
super(name);
}
+ static class InnerDriver extends TeiidDriver {
+ String iurl = null;
+ public InnerDriver(String url) {
+ iurl = url;
+ }
+
+ public void parseUrl(Properties props) throws SQLException {
+ super.parseURL(iurl, props);
+ }
+ }
+
public static ConnectionImpl getMMConnection() {
+ return getMMConnection(serverUrl);
+ }
+
+ public static ConnectionImpl getMMConnection(String url) {
ServerConnection mock = mock(ServerConnection.class);
DQP dqp = mock(DQP.class);
try {
@@ -79,13 +93,20 @@
} catch (XATransactionException e) {
throw new RuntimeException(e);
}
+
+ Properties props = new Properties();
+
+ try {
+ new InnerDriver(url).parseUrl(props);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
stub(mock.getService(DQP.class)).toReturn(dqp);
- Properties props = new Properties();
- props.setProperty(BaseDataSource.VDB_NAME, STD_DATABASE_NAME);
- props.setProperty(BaseDataSource.VDB_VERSION, String.valueOf(STD_DATABASE_VERSION));
- props.setProperty(BaseDataSource.USER_NAME, "metamatrixadmin"); //$NON-NLS-1$
- stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1, "metamatrixadmin"), STD_DATABASE_NAME,STD_DATABASE_VERSION , "fake")); //$NON-NLS-1$
- return new ConnectionImpl(mock, props, serverUrl);
+
+ stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1, "admin"), STD_DATABASE_NAME,STD_DATABASE_VERSION , "fake")); //$NON-NLS-1$
+ return new ConnectionImpl(mock, props, url);
}
public void testGetMetaData() throws Exception {
@@ -103,7 +124,7 @@
/** test getUserName() through DriverManager */
public void testGetUserName2() throws Exception {
- assertEquals("Actual userName is not equal to the expected one. ", "metamatrixadmin", getMMConnection().getUserName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Actual userName is not equal to the expected one. ", "admin", getMMConnection().getUserName()); //$NON-NLS-1$ //$NON-NLS-2$
}
/** test isReadOnly default value on Connection */
@@ -129,4 +150,27 @@
// error expected
}
}
+
+ /**
+ * Test the default of the JDBC4 spec semantics is true
+ */
+ public void testDefaultSpec() throws Exception {
+ assertEquals("true",
+ (getMMConnection().getExecutionProperties().getProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS) == null ? "true" : "false"));
+ }
+
+ /**
+ * Test turning off the JDBC 4 semantics
+ */
+ public void testTurnOnSpec() throws Exception {
+ assertEquals("true", getMMConnection(serverUrl + ";useJDBC4ColumnNameAndLabelSemantics=true").getExecutionProperties().getProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
+ }
+
+ /**
+ * Test turning off the JDBC 4 semantics
+ */
+ public void testTurnOffSpec() throws Exception {
+ assertEquals("false", getMMConnection(serverUrl + ";useJDBC4ColumnNameAndLabelSemantics=false").getExecutionProperties().getProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS));
+ }
+
}
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestConnection.java:3281-3325
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -138,7 +138,7 @@
@Test public void testGetPropertyInfo1() throws Exception {
DriverPropertyInfo info[] = drv.getPropertyInfo("jdbc:teiid:vdb@mm://localhost:12345;applicationName=x", null); //$NON-NLS-1$
- assertEquals(20, info.length);
+ assertEquals(21, info.length);
assertEquals(false, info[0].required);
assertEquals("ApplicationName", info[0].name); //$NON-NLS-1$
assertEquals("x", info[0].value); //$NON-NLS-1$
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3149-3217
+ /branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java:3149-3217,3281-3325
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -24,6 +24,8 @@
*/
package org.teiid.translator.jdbc.sqlserver;
+import java.sql.Date;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -203,8 +205,16 @@
}
@Override
+ public String translateLiteralDate(Date dateValue) {
+ if (getDatabaseVersion().compareTo(V_2008) >= 0) {
+ return super.translateLiteralDate(dateValue);
+ }
+ return super.translateLiteralTimestamp(new Timestamp(dateValue.getTime()));
+ }
+
+ @Override
public boolean hasTimeType() {
- return getDatabaseVersion().compareTo(V_2005) >= 0;
+ return getDatabaseVersion().compareTo(V_2008) >= 0;
}
@Override
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -29,13 +29,21 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.teiid.language.ColumnReference;
+import org.teiid.language.Command;
+import org.teiid.language.DerivedColumn;
import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.language.LanguageFactory;
import org.teiid.language.Literal;
+import org.teiid.language.QueryExpression;
+import org.teiid.language.Select;
+import org.teiid.language.SortSpecification;
+import org.teiid.translator.ExecutionContext;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
@@ -107,21 +115,12 @@
convert.addNumericBooleanConversions();
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
- registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstrModifier(this.convert));
+ registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("LN")); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.LCASE, new StringOnlyModifier("LOWER", this.convert)); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.UCASE, new StringOnlyModifier("UPPER", this.convert)); //$NON-NLS-1$
- registerFunctionModifier(SourceSystemFunctions.LENGTH, new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- ArrayList target = new ArrayList();
- target.add("character_length("); //$NON-NLS-1$
- target.addAll(expressionToString(function.getParameters().get(0), convert));
- target.add(")"); //$NON-NLS-1$
- return target;
- }
- });
+ registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("LOWER")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("UPPER")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.LENGTH, new AliasModifier("character_length")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CURDATE, new AliasModifier("CURRENT_DATE")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CURTIME, new AliasModifier("CURRENT_TIME")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractModifier("YEAR")); //$NON-NLS-1$
@@ -143,9 +142,9 @@
registerFunctionModifier(SourceSystemFunctions.LTRIM, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
- ArrayList target = new ArrayList();
+ ArrayList<Object> target = new ArrayList<Object>();
target.add("TRIM(LEADING FROM ");//$NON-NLS-1$
- target.addAll(expressionToString(function.getParameters().get(0), convert));
+ target.add(function.getParameters().get(0));
target.add(")"); //$NON-NLS-1$
return target;
}
@@ -153,9 +152,9 @@
registerFunctionModifier(SourceSystemFunctions.RTRIM, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
- ArrayList target = new ArrayList();
+ ArrayList<Object> target = new ArrayList<Object>();
target.add("TRIM(TRAILING FROM ");//$NON-NLS-1$
- target.addAll(expressionToString(function.getParameters().get(0), convert));
+ target.add(function.getParameters().get(0));
target.add(")"); //$NON-NLS-1$
return target;
}
@@ -216,7 +215,7 @@
@Override
- public List getSupportedFunctions() {
+ public List<String> getSupportedFunctions() {
List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
@@ -317,8 +316,37 @@
}
@Override
- public boolean supportsSetQueryOrderBy() {
- return false;
+ public List<?> translateCommand(Command command, ExecutionContext context) {
+ if (command instanceof QueryExpression) {
+ QueryExpression qe = (QueryExpression)command;
+ //teradata prefers positional ordering
+ if (qe.getOrderBy() != null) {
+ Select select = qe.getProjectedQuery();
+ List<DerivedColumn> derivedColumns = select.getDerivedColumns();
+ Map<String, Integer> positions = new HashMap<String, Integer>();
+ int i = 1;
+ for (DerivedColumn derivedColumn : derivedColumns) {
+ String name = derivedColumn.getAlias();
+ if (name == null && derivedColumn.getExpression() instanceof ColumnReference) {
+ ColumnReference cr = (ColumnReference)derivedColumn.getExpression();
+ name = cr.toString();
+ }
+ positions.put(name, i++);
+ }
+ for (SortSpecification ss : qe.getOrderBy().getSortSpecifications()) {
+ Expression ex = ss.getExpression();
+ if (!(ex instanceof ColumnReference)) {
+ continue;
+ }
+ ColumnReference cr = (ColumnReference)ex;
+ Integer position = positions.get(cr.toString());
+ if (position != null) {
+ ss.setExpression(new Literal(position, TypeFacility.RUNTIME_TYPES.INTEGER));
+ }
+ }
+ }
+ }
+ return super.translateCommand(command, context);
}
public static class LocateModifier extends FunctionModifier {
@@ -330,67 +358,31 @@
@Override
public List<?> translate(Function function) {
- ArrayList target = new ArrayList();
+ ArrayList<Object> target = new ArrayList<Object>();
Expression expr1 = function.getParameters().get(0);
Expression expr2 = function.getParameters().get(1);
if (function.getParameters().size() > 2) {
Expression expr3 = function.getParameters().get(2);
target.add("position("); //$NON-NLS-1$
- target.addAll(expressionToString(expr1, this.convertModifier));
+ target.add(expr1);
target.add( " in "); //$NON-NLS-1$
target.add("substr("); //$NON-NLS-1$
- target.addAll(expressionToString(expr2, this.convertModifier));
+ target.add(expr2);
target.add(","); //$NON-NLS-1$
target.add(expr3);
target.add("))"); //$NON-NLS-1$
}
else {
target.add("position("); //$NON-NLS-1$
- target.addAll(expressionToString(expr1, this.convertModifier));
+ target.add(expr1);
target.add( " in "); //$NON-NLS-1$
- target.addAll(expressionToString(expr2, this.convertModifier));
+ target.add(expr2);
target.add(")"); //$NON-NLS-1$
}
return target;
}
}
- private static List<?> expressionToString(Expression expr, ConvertModifier modifier) {
- Class tgtType = expr.getType();
- if (tgtType.equals(String.class) && ((expr instanceof Literal) || expr instanceof ColumnReference)) {
- return Arrays.asList(expr);
- }
- else if (tgtType.equals(String.class) && (expr instanceof Function)) {
-
- Function func = (Function)expr;
- while(true) {
- Expression arg1 = func.getParameters().get(0);
- if ((arg1 instanceof Function) && ((Function)arg1).getName().equals("convert")) { //$NON-NLS-1$
- func = (Function)arg1;
- }
- else {
- break;
- }
- }
- Expression arg1 = func.getParameters().get(0);
- if (arg1 instanceof ColumnReference) {
- ColumnReference ref = (ColumnReference)func.getParameters().get(0);
- if(Number.class.isAssignableFrom(ref.getType())) {
- ArrayList target = new ArrayList();
- target.add("cast("); //$NON-NLS-1$
- target.add(func.getParameters().get(0));
- target.add(" AS varchar(100))"); //$NON-NLS-1$
- return target;
- }
- else if (String.class.isAssignableFrom(ref.getType())) {
- return Arrays.asList(ref);
- }
- }
- return modifier.translate(func);
- }
- return Arrays.asList("cast(" , expr, " AS varchar(100))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public static class ExtractModifier extends FunctionModifier {
private String type;
public ExtractModifier(String type) {
@@ -413,47 +405,6 @@
}
}
- public static class StringOnlyModifier extends FunctionModifier {
- String funcName;
- ConvertModifier convertModifier;
- public StringOnlyModifier(String name, ConvertModifier converModifier) {
- this.funcName = name;
- this.convertModifier = converModifier;
- }
- @Override
- public List<?> translate(Function function) {
- Expression expr = function.getParameters().get(0);
- ArrayList target = new ArrayList();
- target.add(this.funcName);
- target.add("("); //$NON-NLS-1$
- target.addAll(expressionToString(expr, this.convertModifier));
- target.add(")"); //$NON-NLS-1$
- return target;
- }
- }
-
- public static class SubstrModifier extends FunctionModifier {
- ConvertModifier convertModifier;
- public SubstrModifier(ConvertModifier converModifier) {
- this.convertModifier = converModifier;
- }
- @Override
- public List<?> translate(Function function) {
- Expression expr = function.getParameters().get(0);
- ArrayList target = new ArrayList();
- target.add("substr("); //$NON-NLS-1$
- target.addAll(expressionToString(expr, this.convertModifier));
- target.add(","); //$NON-NLS-1$
- target.add(function.getParameters().get(1));
- if (function.getParameters().size() > 2 ) {
- target.add(","); //$NON-NLS-1$
- target.add(function.getParameters().get(2));
- }
- target.add(")"); //$NON-NLS-1$
- return target;
- }
- }
-
public static class LeftOrRightFunctionModifier extends FunctionModifier {
private LanguageFactory langFactory;
ConvertModifier convertModifier;
@@ -466,11 +417,11 @@
@Override
public List<?> translate(Function function) {
List<Expression> args = function.getParameters();
- ArrayList target = new ArrayList();
+ ArrayList<Object> target = new ArrayList<Object>();
if (function.getName().equalsIgnoreCase("left")) { //$NON-NLS-1$
//substr(string, 1, length)
target.add("substr("); //$NON-NLS-1$
- target.addAll(expressionToString(args.get(0), this.convertModifier));
+ target.add(args.get(0));
target.add(","); //$NON-NLS-1$
target.add(langFactory.createLiteral(Integer.valueOf(1), TypeFacility.RUNTIME_TYPES.INTEGER));
target.add(","); //$NON-NLS-1$
@@ -479,10 +430,10 @@
} else if (function.getName().equalsIgnoreCase("right")) { //$NON-NLS-1$
//substr(case_size, character_length(case_size) -4)
target.add("substr("); //$NON-NLS-1$
- target.addAll(expressionToString(args.get(0), this.convertModifier));
+ target.add(args.get(0));
target.add(",(character_length("); //$NON-NLS-1$
- target.addAll(expressionToString(args.get(0), this.convertModifier));
+ target.add(args.get(0));
target.add(")-"); //$NON-NLS-1$
target.add(args.get(1));
target.add("+1))"); //$NON-NLS-1$ // offset for 1 based index
@@ -491,22 +442,4 @@
}
}
- public static class UpperOrLowerModifier extends FunctionModifier {
- String funcName;
- ConvertModifier convertModifier;
- public UpperOrLowerModifier(String name, ConvertModifier converModifier) {
- this.funcName = name;
- this.convertModifier = converModifier;
- }
- @Override
- public List<?> translate(Function function) {
- Expression expr = function.getParameters().get(0);
- ArrayList target = new ArrayList();
- target.add(this.funcName);
- target.add("("); //$NON-NLS-1$
- target.addAll(expressionToString(expr, this.convertModifier));
- target.add(")"); //$NON-NLS-1$
- return target;
- }
- }
}
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -49,9 +49,13 @@
private static SQLServerExecutionFactory trans = new SQLServerExecutionFactory();
@BeforeClass
- public static void setup() throws TranslatorException {
+ public static void oneTimeSetup() throws TranslatorException {
trans.start();
}
+
+ public void setUp() throws Exception {
+ trans.setDatabaseVersion(SQLServerExecutionFactory.V_2005);
+ }
public String getTestVDB() {
return TranslationHelper.PARTS_VDB;
@@ -143,6 +147,25 @@
output);
}
+ @Test public void testConvertDate() throws Exception {
+ String input = "select stringkey from bqt1.smalla where BQT1.SmallA.DateValue IN (convert('2000-01-12', date), convert('2000-02-02', date))"; //$NON-NLS-1$
+ String output = "SELECT SmallA.StringKey FROM SmallA WHERE SmallA.DateValue IN (CAST('2000-01-12 00:00:00.0' AS DATETIME), CAST('2000-02-02 00:00:00.0' AS DATETIME))"; //$NON-NLS-1$
+
+ helpTestVisitor(getBQTVDB(),
+ input,
+ output);
+ }
+
+ @Test public void testConvertDate2008() throws Exception {
+ trans.setDatabaseVersion(SQLServerExecutionFactory.V_2008);
+ String input = "select stringkey from bqt1.smalla where BQT1.SmallA.DateValue IN (convert('2000-01-12', date), convert('2000-02-02', date))"; //$NON-NLS-1$
+ String output = "SELECT SmallA.StringKey FROM SmallA WHERE SmallA.DateValue IN (CAST('2000-01-12' AS DATE), CAST('2000-02-02' AS DATE))"; //$NON-NLS-1$
+
+ helpTestVisitor(getBQTVDB(),
+ input,
+ output);
+ }
+
@Test public void testUniqueidentifier() throws Exception {
MetadataStore metadataStore = new MetadataStore();
Schema foo = RealMetadataFactory.createPhysicalModel("foo", metadataStore); //$NON-NLS-1$
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -31,6 +31,8 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.cdk.api.TranslationUtility;
+import org.teiid.language.Command;
import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.language.In;
@@ -82,35 +84,61 @@
@Test public void testIntegerToString() throws Exception {
String input = "SELECT lcase(bigdecimalvalue) FROM BQT1.SMALLA";
- String output = "SELECT LOWER(cast(SmallA.BigDecimalValue AS varchar(100))) FROM SmallA";
+ String output = "SELECT LOWER(cast(SmallA.BigDecimalValue AS varchar(4000))) FROM SmallA";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
@Test public void testSubString() throws Exception {
String input = "SELECT intkey FROM BQT1.SmallA WHERE SUBSTRING(BQT1.SmallA.IntKey, 1) = '1' ORDER BY intkey";
- String output = "SELECT SmallA.IntKey FROM SmallA WHERE substr(cast(SmallA.IntKey AS varchar(100)),1) = '1' ORDER BY SmallA.IntKey";
+ String output = "SELECT SmallA.IntKey FROM SmallA WHERE substr(cast(SmallA.IntKey AS varchar(4000)), 1) = '1' ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
@Test public void testSubString2() throws Exception {
String input = "SELECT intkey FROM BQT1.SmallA WHERE SUBSTRING(BQT1.SmallA.IntKey, 1, 2) = '1' ORDER BY intkey";
- String output = "SELECT SmallA.IntKey FROM SmallA WHERE substr(cast(SmallA.IntKey AS varchar(100)),1,2) = '1' ORDER BY SmallA.IntKey";
+ String output = "SELECT SmallA.IntKey FROM SmallA WHERE substr(cast(SmallA.IntKey AS varchar(4000)), 1, 2) = '1' ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
@Test public void testDateToString() throws Exception {
String input = "SELECT intkey, UPPER(timevalue) AS UPPER FROM BQT1.SmallA ORDER BY intkey";
- String output = "SELECT SmallA.IntKey, UPPER(cast(cast(SmallA.TimeValue AS FORMAT 'HH:MI:SS') AS VARCHAR(9))) AS UPPER FROM SmallA ORDER BY SmallA.IntKey";
+ String output = "SELECT SmallA.IntKey, UPPER(cast(cast(SmallA.TimeValue AS FORMAT 'HH:MI:SS') AS VARCHAR(9))) AS UPPER FROM SmallA ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
@Test public void testLocate() throws Exception {
String input = "SELECT INTKEY, BIGDECIMALVALUE FROM BQT1.SmallA WHERE LOCATE('-', BIGDECIMALVALUE) = 1 ORDER BY intkey";
- String output = "SELECT SmallA.IntKey, SmallA.BigDecimalValue FROM SmallA WHERE position('-' in cast(SmallA.BigDecimalValue AS varchar(100))) = 1 ORDER BY SmallA.IntKey";
+ String output = "SELECT SmallA.IntKey, SmallA.BigDecimalValue FROM SmallA WHERE position('-' in cast(SmallA.BigDecimalValue AS varchar(4000))) = 1 ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}
+ @Test public void testPositionalOrderBy() throws Exception {
+ String input = "SELECT INTKEY, BIGDECIMALVALUE FROM BQT1.SmallA ORDER BY intkey";
+ String output = "SELECT g_0.IntKey AS c_0, g_0.BigDecimalValue AS c_1 FROM SmallA AS g_0 ORDER BY 1";
+
+ TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
+ Command command = tu.parseCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
+ }
+ @Test public void testPositionalOrderByUnion() throws Exception {
+ String input = "SELECT a as b, b as a from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by a";
+ String output = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY 2";
+
+ TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
+ Command command = tu.parseCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
+ }
+
+ @Test public void testPositionalOrderByUnion1() throws Exception {
+ String input = "SELECT a as b from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by x.b";
+ String output = "SELECT v_0.c_0 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY v_0.c_1";
+
+ TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
+ Command command = tu.parseCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
+ }
+
@Test public void testByteToString() throws Exception {
helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class), "string", "cast(1 AS varchar(4000))");
}
@@ -194,13 +222,13 @@
@Test public void testRightFunction() throws Exception {
String input = "SELECT INTKEY, FLOATNUM FROM BQT1.SmallA WHERE right(FLOATNUM, 2) <> 0 ORDER BY INTKEY";
- String out = "SELECT SmallA.IntKey, SmallA.FloatNum FROM SmallA WHERE substr(cast(SmallA.FloatNum AS varchar(100)),(character_length(cast(SmallA.FloatNum AS varchar(100)))-2+1)) <> '0' ORDER BY SmallA.IntKey";
+ String out = "SELECT SmallA.IntKey, SmallA.FloatNum FROM SmallA WHERE substr(cast(SmallA.FloatNum AS varchar(4000)),(character_length(cast(SmallA.FloatNum AS varchar(4000)))-2+1)) <> '0' ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
}
@Test public void testLocateFunction() throws Exception {
String input = "SELECT INTKEY, STRINGKEY, SHORTVALUE FROM BQT1.SmallA WHERE (LOCATE(0, STRINGKEY) = 2) OR (LOCATE(2, SHORTVALUE, 4) = 6) ORDER BY intkey";
- String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM SmallA WHERE position('0' in SmallA.StringKey) = 2 OR position('2' in substr(cast(SmallA.ShortValue AS varchar(100)),4)) = 6 ORDER BY SmallA.IntKey";
+ String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM SmallA WHERE position('0' in SmallA.StringKey) = 2 OR position('2' in substr(cast(SmallA.ShortValue AS varchar(4000)),4)) = 6 ORDER BY 1";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out, TRANSLATOR);
}
}
Modified: trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
===================================================================
--- trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-07-22 16:26:08 UTC (rev 3327)
@@ -250,10 +250,9 @@
<code>boolean</code>
</entry>
<entry>
- <para>A change was made in JDBC4 so that when an 'Alias' is used it will
- now be returned as the label. Prior to this, it was returned as
- the name. Setting this property to false will enable
- backwards compatibility when JDBC3 and older support is still required.
+ <para>A change was made in JDBC4 to return unaliased column names as the ResultSetMetadata column name.
+ Prior to this, if a column alias were used it was returned as the column name. Setting this property to false will enable
+ backwards compatibility when JDBC3 and older support is still required. Defaults to true.
</para>
</entry>
</row>
Modified: trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
===================================================================
--- trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-07-22 16:26:08 UTC (rev 3327)
@@ -175,11 +175,7 @@
<code>JDBC4COLUMNNAMEANDLABELSEMANTICS / useJDBC4ColumnNameAndLabelSemantics</code>
</entry>
<entry>
- <para>A change was made in JDBC4 so that when an 'Alias' is used it will.
- now be returned as the label. Prior to this, it was returned as
- the name. Setting this property to false will enable
- backwards compatibility when JDBC3 and older support is still required.
- </para>
+ <para>Same as the connection property.</para>
</entry>
</row>
</tbody>
Modified: trunk/engine/pom.xml
===================================================================
--- trunk/engine/pom.xml 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/pom.xml 2011-07-22 16:26:08 UTC (rev 3327)
@@ -78,14 +78,8 @@
<dependency>
<groupId>net.sourceforge.saxon</groupId>
- <artifactId>saxon</artifactId>
+ <artifactId>saxonhe</artifactId>
</dependency>
-
- <dependency>
- <groupId>net.sourceforge.saxon</groupId>
- <classifier>dom</classifier>
- <artifactId>saxon</artifactId>
- </dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
@@ -106,4 +100,4 @@
</dependencies>
-</project>
\ No newline at end of file
+</project>
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -115,6 +115,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.SelectSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.translator.TranslatorException;
@@ -179,9 +180,9 @@
/* Query */
Select translate(Query query) {
- List symbols = query.getSelect().getSymbols();
+ List<SelectSymbol> symbols = query.getSelect().getSymbols();
List<DerivedColumn> translatedSymbols = new ArrayList<DerivedColumn>(symbols.size());
- for (Iterator i = symbols.iterator(); i.hasNext();) {
+ for (Iterator<SelectSymbol> i = symbols.iterator(); i.hasNext();) {
SingleElementSymbol symbol = (SingleElementSymbol)i.next();
String alias = null;
if(symbol instanceof AliasSymbol) {
@@ -375,7 +376,7 @@
In translate(SetCriteria criteria) {
Collection expressions = criteria.getValues();
- List translatedExpressions = new ArrayList();
+ List<org.teiid.language.Expression> translatedExpressions = new ArrayList<org.teiid.language.Expression>();
for (Iterator i = expressions.iterator(); i.hasNext();) {
translatedExpressions.add(translate((Expression)i.next()));
}
@@ -423,13 +424,13 @@
return new SubqueryComparison(translate(criteria.getLeftExpression()),
operator,
quantifier,
- translate((QueryCommand)criteria.getCommand()));
+ translate(criteria.getCommand()));
}
SubqueryIn translate(SubquerySetCriteria criteria) {
return new SubqueryIn(translate(criteria.getExpression()),
criteria.isNegated(),
- translate((QueryCommand)criteria.getCommand()));
+ translate(criteria.getCommand()));
}
Not translate(NotCriteria criteria) {
@@ -462,7 +463,7 @@
if(items.get(i).isUnrelated() || (!set && symbol instanceof ElementSymbol)){
orderByItem = new SortSpecification(direction, translate(symbol));
} else {
- orderByItem = new SortSpecification(direction, new ColumnReference(null, symbol.getOutputName(), null, symbol.getType()));
+ orderByItem = new SortSpecification(direction, new ColumnReference(null, SingleElementSymbol.getShortName(symbol.getOutputName()), null, symbol.getType()));
}
orderByItem.setNullOrdering(items.get(i).getNullOrdering());
translatedItems.add(orderByItem);
@@ -558,7 +559,7 @@
}
ColumnReference translate(ElementSymbol symbol) {
- ColumnReference element = new ColumnReference(translate(symbol.getGroupSymbol()), symbol.getOutputName(), null, symbol.getType());
+ ColumnReference element = new ColumnReference(translate(symbol.getGroupSymbol()), SingleElementSymbol.getShortName(symbol.getOutputName()), null, symbol.getType());
if (element.getTable().getMetadataObject() == null) {
return element;
}
@@ -746,10 +747,10 @@
/* Batched Updates */
BatchedUpdates translate(BatchedUpdateCommand command) {
- List updates = command.getUpdateCommands();
+ List<Command> updates = command.getUpdateCommands();
List<org.teiid.language.Command> translatedUpdates = new ArrayList<org.teiid.language.Command>(updates.size());
- for (Iterator i = updates.iterator(); i.hasNext();) {
- translatedUpdates.add(translate((Command)i.next()));
+ for (Iterator<Command> i = updates.iterator(); i.hasNext();) {
+ translatedUpdates.add(translate(i.next()));
}
return new BatchedUpdates(translatedUpdates);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/AbstractWorkItem.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -26,7 +26,6 @@
import javax.resource.spi.work.WorkEvent;
import javax.resource.spi.work.WorkListener;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.logging.LogManager;
@@ -43,23 +42,14 @@
private ThreadState threadState = ThreadState.MORE_WORK;
private volatile boolean isProcessing;
- private Thread callingThread;
- public AbstractWorkItem(Thread callingThread) {
- this.callingThread = callingThread;
- }
-
public void run() {
- do {
- startProcessing();
- try {
- process();
- } finally {
- if (!endProcessing()) {
- break;
- }
- }
- } while (!isDoneProcessing());
+ startProcessing();
+ try {
+ process();
+ } finally {
+ endProcessing();
+ }
}
synchronized ThreadState getThreadState() {
@@ -79,10 +69,7 @@
this.threadState = ThreadState.WORKING;
}
- /**
- * @return true if processing should be continued
- */
- final private synchronized boolean endProcessing() {
+ private synchronized void endProcessing() {
isProcessing = false;
logTrace("end processing"); //$NON-NLS-1$
switch (this.threadState) {
@@ -92,21 +79,20 @@
this.threadState = ThreadState.DONE;
} else {
this.threadState = ThreadState.IDLE;
- return pauseProcessing();
+ pauseProcessing();
}
break;
case MORE_WORK:
if (isDoneProcessing()) {
logTrace("done processing - ignoring more"); //$NON-NLS-1$
this.threadState = ThreadState.DONE;
- } else if (this.callingThread == null) {
- resumeProcessing();
+ } else {
+ resumeProcessing();
}
break;
default:
throw new IllegalStateException("Should not END on " + this.threadState); //$NON-NLS-1$
}
- return this.callingThread != null;
}
protected boolean isIdle() {
@@ -117,8 +103,9 @@
moreWork(true);
}
- final protected synchronized void moreWork(boolean ignoreDone) {
+ protected synchronized void moreWork(boolean ignoreDone) {
logTrace("more work"); //$NON-NLS-1$
+ this.notifyAll();
switch (this.threadState) {
case WORKING:
this.threadState = ThreadState.MORE_WORK;
@@ -127,15 +114,7 @@
break;
case IDLE:
this.threadState = ThreadState.MORE_WORK;
- if (this.callingThread != null) {
- if (this.callingThread == Thread.currentThread()) {
- run(); //restart with the calling thread
- } else {
- this.notifyAll(); //notify the waiting caller
- }
- } else {
- resumeProcessing();
- }
+ resumeProcessing();
break;
default:
if (!ignoreDone) {
@@ -151,33 +130,8 @@
protected abstract void process();
- protected boolean pauseProcessing() {
- if (this.callingThread != null && !shouldPause()) {
- return false;
- }
- while (this.callingThread != null && this.getThreadState() == ThreadState.IDLE) {
- try {
- this.wait(); //the lock should already be held
- } catch (InterruptedException e) {
- interrupted(e);
- }
- }
- return this.callingThread != null;
+ protected void pauseProcessing() {
}
-
- /**
- * only called for synch processing
- */
- protected boolean shouldPause() {
- return false;
- }
-
- /**
- * only called for synch processing
- */
- protected void interrupted(InterruptedException e) {
- throw new TeiidRuntimeException(e);
- }
protected abstract void resumeProcessing();
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -93,9 +93,11 @@
private long creationTime = System.currentTimeMillis();
private DQPWorkContext workContext = DQPWorkContext.getWorkContext();
private List<CompletionListener<T>> completionListeners = new LinkedList<CompletionListener<T>>();
+ private String parentName;
public FutureWork(final Callable<T> processor, int priority) {
super(processor);
+ this.parentName = Thread.currentThread().getName();
this.priority = priority;
}
@@ -105,6 +107,12 @@
}
@Override
+ public void run() {
+ LogManager.logDetail(LogConstants.CTX_DQP, "Running task for parent thread", parentName); //$NON-NLS-1$
+ super.run();
+ }
+
+ @Override
public int getPriority() {
return priority;
}
@@ -344,6 +352,7 @@
}
}
if (runInThread) {
+ workItem.useCallingThread = true;
workItem.run();
}
return resultsFuture;
@@ -721,6 +730,8 @@
processorDataManager.setMetadataRepository(metadataRepository);
dataTierMgr = new TempTableDataManager(processorDataManager, this.bufferManager, this.processWorkerPool, this.rsCache, this.matTables, this.cacheFactory);
dataTierMgr.setEventDistributor(eventDistributor);
+
+ LogManager.logDetail(LogConstants.CTX_DQP, "DQPCore started maxThreads", this.config.getMaxThreads(), "maxActivePlans", this.maxActivePlans, "source concurrency", this.userRequestSourceConcurrency); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void setBufferService(BufferService service) {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -188,11 +188,8 @@
}
public void runInContext(final Runnable runnable) {
- DQPWorkContext.setWorkContext(this);
- boolean associated = false;
- if (securityHelper != null && this.getSubject() != null) {
- associated = securityHelper.assosiateSecurityContext(this.getSecurityDomain(), this.getSecurityContext());
- }
+ DQPWorkContext previous = DQPWorkContext.getWorkContext();
+ boolean associated = attachDQPWorkContext();
try {
runnable.run();
} finally {
@@ -200,9 +197,21 @@
securityHelper.clearSecurityContext(this.getSecurityDomain());
}
DQPWorkContext.releaseWorkContext();
+ if (previous != null) {
+ previous.attachDQPWorkContext();
+ }
}
}
+ private boolean attachDQPWorkContext() {
+ DQPWorkContext.setWorkContext(this);
+ boolean associated = false;
+ if (securityHelper != null && this.getSubject() != null) {
+ associated = securityHelper.assosiateSecurityContext(this.getSecurityDomain(), this.getSecurityContext());
+ }
+ return associated;
+ }
+
public HashMap<String, DataPolicy> getAllowedDataPolicies() {
if (this.policies == null) {
this.policies = new HashMap<String, DataPolicy>();
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -162,8 +162,10 @@
/**The time when command begins processing on the server.*/
private long processingTimestamp = System.currentTimeMillis();
+ protected boolean useCallingThread;
+ private volatile boolean hasThread;
+
public RequestWorkItem(DQPCore dqpCore, RequestMessage requestMsg, Request request, ResultsReceiver<ResultsMessage> receiver, RequestID requestID, DQPWorkContext workContext) {
- super(workContext.useCallingThread() || requestMsg.isSync() ? Thread.currentThread() : null);
this.requestMsg = requestMsg;
this.requestID = requestID;
this.processorTimeslice = dqpCore.getProcessorTimeSlice();
@@ -196,24 +198,65 @@
protected boolean isDoneProcessing() {
return isClosed;
}
+
+ @Override
+ public void run() {
+ hasThread = true;
+ try {
+ while (!isDoneProcessing()) {
+ super.run();
+ if (!useCallingThread) {
+ break;
+ }
+ //should use the calling thread
+ synchronized (this) {
+ if (this.resultsReceiver == null) {
+ break; //allow results to be processed by calling thread
+ }
+ if (this.getThreadState() == ThreadState.MORE_WORK) {
+ continue;
+ }
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ try {
+ requestCancel();
+ } catch (TeiidComponentException e1) {
+ throw new TeiidRuntimeException(e1);
+ }
+ }
+ }
+ }
+ } finally {
+ hasThread = false;
+ }
+ }
@Override
protected void resumeProcessing() {
- if (doneProducingBatches && !closeRequested && !isCanceled) {
- this.run(); // just run in the IO thread
- } else {
+ if (!this.useCallingThread) {
dqpCore.addWork(this);
}
}
- @Override
- protected void interrupted(InterruptedException e) {
- try {
- this.requestCancel();
- } catch (TeiidComponentException e1) {
- throw new TeiidRuntimeException(e1);
+ /**
+ * Special call from request threads to allow resumption of processing by
+ * the calling thread.
+ */
+ public void doMoreWork() {
+ boolean run = false;
+ synchronized (this) {
+ moreWork();
+ if (!useCallingThread || this.getThreadState() != ThreadState.MORE_WORK) {
+ return;
+ }
+ run = !hasThread;
}
- super.interrupted(e);
+ if (run) {
+ //run outside of the lock
+ LogManager.logDetail(LogConstants.CTX_DQP, "Restarting processing using the calling thread", requestID); //$NON-NLS-1$
+ run();
+ }
}
@Override
@@ -293,7 +336,7 @@
}
private void suspend() {
- if (this.transactionState == TransactionState.ACTIVE && this.transactionContext.getTransaction() != null) {
+ if ((this.transactionState != TransactionState.NONE) && this.transactionContext.getTransaction() != null) {
try {
this.transactionService.suspend(this.transactionContext);
} catch (XATransactionException e) {
@@ -650,12 +693,6 @@
return new TeiidProcessingException(exception, SQLStates.QUERY_CANCELED, exception.getMessage());
}
- @Override
- protected boolean shouldPause() {
- //if we are waiting on results it's ok to pause
- return this.resultsReceiver != null;
- }
-
private static List<ParameterInfo> getParameterInfo(StoredProcedure procedure) {
List<ParameterInfo> paramInfos = new ArrayList<ParameterInfo>();
@@ -750,12 +787,12 @@
if (!this.doneProducingBatches) {
this.requestCancel(); //pending work should be canceled for fastest clean up
}
- this.moreWork();
+ this.doMoreWork();
}
public void requestMore(int batchFirst, int batchLast, ResultsReceiver<ResultsMessage> receiver) {
this.requestResults(batchFirst, batchLast, receiver);
- this.moreWork();
+ this.doMoreWork();
}
public void closeAtomicRequest(AtomicRequestID atomicRequestId) {
Modified: trunk/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -25,8 +25,8 @@
import java.io.PrintStream;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -214,7 +214,7 @@
*/
public Map<MappingNodeConstants.Properties, Object> getNodeProperties(){
if(nodeProperties == null) {
- nodeProperties = new HashMap<MappingNodeConstants.Properties, Object>();
+ nodeProperties = new LinkedHashMap<MappingNodeConstants.Properties, Object>();
}
return nodeProperties;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/NodeConstants.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/plantree/NodeConstants.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -43,7 +43,6 @@
public static final int SET_OP = 1<<8;
public static final int NULL = 1<<9;
public static final int TUPLE_LIMIT = 1<<10;
- public static final int WITH = 1<<11;
}
/**
@@ -64,7 +63,6 @@
case NodeConstants.Types.SET_OP: return "SetOperation"; //$NON-NLS-1$
case NodeConstants.Types.NULL: return "Null"; //$NON-NLS-1$
case NodeConstants.Types.TUPLE_LIMIT: return "TupleLimit"; //$NON-NLS-1$
- case NodeConstants.Types.WITH: return "With"; //$NON-NLS-1$
default: return "Unknown: " + type; //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -37,7 +37,6 @@
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.Assertion;
import org.teiid.query.QueryPlugin;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -50,17 +49,21 @@
import org.teiid.query.resolver.util.AccessPattern;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompoundCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.GroupBy;
import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.lang.QueryCommand;
import org.teiid.query.sql.lang.Select;
import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.util.SymbolMap;
@@ -125,15 +128,15 @@
}
static boolean canConvertAccessPatterns(PlanNode sourceNode) {
- List accessPatterns = (List)sourceNode.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
+ List<AccessPattern> accessPatterns = (List)sourceNode.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
if (accessPatterns == null) {
return true;
}
SymbolMap symbolMap = (SymbolMap)sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
- for (Iterator i = accessPatterns.iterator(); i.hasNext();) {
- AccessPattern ap = (AccessPattern)i.next();
- for (Iterator elems = ap.getUnsatisfied().iterator(); elems.hasNext();) {
- ElementSymbol symbol = (ElementSymbol)elems.next();
+ for (Iterator<AccessPattern> i = accessPatterns.iterator(); i.hasNext();) {
+ AccessPattern ap = i.next();
+ for (Iterator<ElementSymbol> elems = ap.getUnsatisfied().iterator(); elems.hasNext();) {
+ ElementSymbol symbol = elems.next();
Expression mapped = convertExpression(symbol, symbolMap.asMap());
if (ElementCollectorVisitor.getElements(mapped, true).isEmpty()) {
return false;
@@ -154,15 +157,15 @@
if (accessPatterns != null) {
for (AccessPattern ap : accessPatterns) {
Set<ElementSymbol> newElements = new HashSet<ElementSymbol>();
- for (Iterator elems = ap.getUnsatisfied().iterator(); elems.hasNext();) {
- ElementSymbol symbol = (ElementSymbol)elems.next();
+ for (Iterator<ElementSymbol> elems = ap.getUnsatisfied().iterator(); elems.hasNext();) {
+ ElementSymbol symbol = elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
newElements.addAll(ElementCollectorVisitor.getElements(mapped, true));
}
ap.setUnsatisfied(newElements);
Set<ElementSymbol> newHistory = new HashSet<ElementSymbol>();
- for (Iterator elems = ap.getCurrentElements().iterator(); elems.hasNext();) {
- ElementSymbol symbol = (ElementSymbol)elems.next();
+ for (Iterator<ElementSymbol> elems = ap.getCurrentElements().iterator(); elems.hasNext();) {
+ ElementSymbol symbol = elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
newHistory.addAll(ElementCollectorVisitor.getElements(mapped, true));
}
@@ -233,6 +236,11 @@
List<SingleElementSymbol> projectedSymbols = (List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.PROJECT_COLS);
Select select = new Select(projectedSymbols);
ExpressionMappingVisitor.mapExpressions(select, symbolMap);
+ if (rewrite) {
+ for (LanguageObject expr : select.getSymbols()) {
+ rewriteSingleElementSymbol(metadata, (SingleElementSymbol) expr);
+ }
+ }
node.setProperty(NodeConstants.Info.PROJECT_COLS, select.getSymbols());
if (!singleMapping) {
GroupsUsedByElementsVisitor.getGroups(select, groups);
@@ -257,6 +265,11 @@
} else if(type == NodeConstants.Types.SORT) {
OrderBy orderBy = (OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER);
ExpressionMappingVisitor.mapExpressions(orderBy, symbolMap);
+ if (rewrite) {
+ for (OrderByItem item : orderBy.getOrderByItems()) {
+ rewriteSingleElementSymbol(metadata, item.getSymbol());
+ }
+ }
if (!singleMapping) {
GroupsUsedByElementsVisitor.getGroups(orderBy, groups);
}
@@ -278,6 +291,25 @@
convertAccessPatterns(symbolMap, node);
}
}
+
+ private static void rewriteSingleElementSymbol(
+ QueryMetadataInterface metadata, SingleElementSymbol ses) throws QueryPlannerException {
+ try {
+ if (ses instanceof AliasSymbol) {
+ ses = ((AliasSymbol)ses).getSymbol();
+ }
+ if (ses instanceof ExpressionSymbol) {
+ ExpressionSymbol es = (ExpressionSymbol)ses;
+ if (es.getExpression() != null) {
+ es.setExpression(QueryRewriter.rewriteExpression(es.getExpression(), null, null, metadata));
+ }
+ }
+ } catch(TeiidProcessingException e) {
+ throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0023", ses)); //$NON-NLS-1$
+ } catch (TeiidComponentException e) {
+ throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0023", ses)); //$NON-NLS-1$
+ }
+ }
private static Expression convertExpression(Expression expression, Map symbolMap) {
@@ -314,7 +346,7 @@
} catch(TeiidProcessingException e) {
throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0023", criteria)); //$NON-NLS-1$
} catch (TeiidComponentException e) {
- throw new TeiidRuntimeException(e);
+ throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0023", criteria)); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -419,11 +419,11 @@
result.type = crit.getClass();
result.not = exists.isNegated();
//the correlations can only be in where (if no group by or aggregates) or having
- result.query = (Query)exists.getCommand();
result.mergeJoin = exists.getSubqueryHint().isMergeJoin();
if (!UNNEST && !result.mergeJoin) {
return result;
}
+ result.query = (Query)exists.getCommand();
}
return result;
}
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -52,6 +52,7 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
import org.teiid.core.util.Assertion;
import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.language.SQLConstants.NonReserved;
@@ -148,7 +149,6 @@
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.SelectSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.util.SymbolMap;
@@ -240,6 +240,7 @@
* @throws QueryValidatorException
*/
private Command rewriteCommand(Command command, boolean removeOrderBy) throws TeiidComponentException, TeiidProcessingException{
+ boolean oldRewriteAggs = rewriteAggs;
QueryMetadataInterface oldMetadata = metadata;
CreateUpdateProcedureCommand oldProcCommand = procCommand;
@@ -299,6 +300,7 @@
break;
}
+ this.rewriteAggs = oldRewriteAggs;
this.metadata = oldMetadata;
this.procCommand = oldProcCommand;
return command;
@@ -605,9 +607,9 @@
From from = query.getFrom();
if(from != null){
List<FromClause> clauses = new ArrayList<FromClause>(from.getClauses().size());
- Iterator clauseIter = from.getClauses().iterator();
+ Iterator<FromClause> clauseIter = from.getClauses().iterator();
while(clauseIter.hasNext()) {
- clauses.add( rewriteFromClause(query, (FromClause) clauseIter.next()) );
+ clauses.add( rewriteFromClause(query, clauseIter.next()) );
}
from.setClauses(clauses);
} else {
@@ -765,6 +767,7 @@
*/
private Query rewriteGroupBy(Query query) throws TeiidComponentException, TeiidProcessingException {
if (query.getGroupBy() == null) {
+ rewriteAggs = false;
return query;
}
if (isDistinctWithGroupBy(query)) {
@@ -811,11 +814,11 @@
try {
PostOrderNavigator.doVisit(obj, visitor);
} catch (TeiidRuntimeException err) {
- if (err.getChild() instanceof TeiidComponentException) {
- throw (TeiidComponentException)err.getChild();
+ if (err.getCause() instanceof TeiidComponentException) {
+ throw (TeiidComponentException)err.getCause();
}
- if (err.getChild() instanceof TeiidProcessingException) {
- throw (TeiidProcessingException)err.getChild();
+ if (err.getCause() instanceof TeiidProcessingException) {
+ throw (TeiidProcessingException)err.getCause();
}
throw err;
}
@@ -1552,6 +1555,7 @@
private BigDecimal BIG_DECIMAL_ZERO = new BigDecimal("0"); //$NON-NLS-1$
private Short SHORT_ZERO = new Short((short)0);
private Byte BYTE_ZERO = new Byte((byte)0);
+ private boolean rewriteAggs = true;
/**
* @param criteria
@@ -2246,6 +2250,9 @@
expression.setAggregateFunction(Type.MAX);
}
}
+ if (rewriteAggs && expression.getExpression() != null && EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
+ return expression.getExpression();
+ }
if (expression.getExpression() != null && expression.getCondition() != null && !expression.respectsNulls()) {
Expression cond = expression.getCondition();
Expression ex = expression.getExpression();
@@ -2414,17 +2421,44 @@
}
function.setArgs(newArgs);
- if( FunctionLibrary.isConvert(function) &&
- newArgs[1] instanceof Constant) {
-
- Class srcType = newArgs[0].getType();
- String tgtTypeName = (String) ((Constant)newArgs[1]).getValue();
- Class tgtType = DataTypeManager.getDataTypeClass(tgtTypeName);
+ if( FunctionLibrary.isConvert(function)) {
+ Class<?> srcType = newArgs[0].getType();
+ Class<?> tgtType = function.getType();
if(srcType != null && tgtType != null && srcType.equals(tgtType)) {
- return newArgs[0];
+ return newArgs[0]; //unnecessary conversion
}
-
+
+ if (!(newArgs[0] instanceof Function) || tgtType == DataTypeManager.DefaultDataClasses.OBJECT) {
+ return function;
+ }
+ Function nested = (Function) newArgs[0];
+ if (!FunctionLibrary.isConvert(nested)) {
+ return function;
+ }
+ Class<?> nestedType = nested.getArgs()[0].getType();
+
+ Transform t = DataTypeManager.getTransform(nestedType, nested.getType());
+ if (t.isExplicit()) {
+ //explicit conversions are required
+ return function;
+ }
+ if (DataTypeManager.getTransform(nestedType, tgtType) == null) {
+ //no direct conversion exists
+ return function;
+ }
+ //can't remove a convert that would alter the lexical form
+ if (tgtType == DataTypeManager.DefaultDataClasses.STRING &&
+ (nestedType == DataTypeManager.DefaultDataClasses.BOOLEAN
+ || nestedType == DataTypeManager.DefaultDataClasses.DATE
+ || nestedType == DataTypeManager.DefaultDataClasses.TIME
+ || tgtType == DataTypeManager.DefaultDataClasses.BIG_DECIMAL
+ || tgtType == DataTypeManager.DefaultDataClasses.FLOAT
+ || (tgtType == DataTypeManager.DefaultDataClasses.DOUBLE && srcType != DataTypeManager.DefaultDataClasses.FLOAT))) {
+ return function;
+ }
+ //nested implicit transform is not needed
+ return rewriteExpressionDirect(ResolverUtil.getConversion(nested.getArgs()[0], DataTypeManager.getDataTypeName(nestedType), DataTypeManager.getDataTypeName(tgtType), false, funcLibrary));
}
//convert DECODESTRING function to CASE expression
@@ -2702,7 +2736,7 @@
select.setSymbols(select.getProjectedSymbols());
- List<SelectSymbol> symbols = select.getSymbols();
+ List symbols = select.getSymbols();
HashSet<String> uniqueNames = new HashSet<String>();
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -30,7 +30,7 @@
import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
- * Represents XMLATTRIBUTES name value pairs
+ * Represents query string name value pairs
*/
public class QueryString implements Expression {
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -37,6 +37,8 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidComponentException;
import org.teiid.language.SQLConstants;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataID;
@@ -96,6 +98,7 @@
public synchronized MatState setState(MatState state, Boolean valid, Long timestamp) {
MatState oldState = this.state;
+ LogManager.logDetail(LogConstants.CTX_MATVIEWS, this, "setting matState to", state, valid, timestamp, "old values", oldState, this.valid); //$NON-NLS-1$ //$NON-NLS-2$
if (valid != null) {
this.valid = valid;
}
Modified: trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -404,7 +404,7 @@
String groupName = es.getGroupSymbol().getCanonicalName();
UpdateMapping info = updateInfo.updatableGroups.get(groupName);
if (es.getGroupSymbol().getDefinition() != null) {
- ElementSymbol clone = (ElementSymbol)es.clone();
+ ElementSymbol clone = es.clone();
clone.setOutputName(null);
clone.getGroupSymbol().setName(clone.getGroupSymbol().getNonCorrelationName());
clone.getGroupSymbol().setDefinition(null);
Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocumentWrapper.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocumentWrapper.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocumentWrapper.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -115,7 +115,7 @@
* @return the unique number identifying this document within the name pool
*/
- public int getDocumentNumber() {
+ public long getDocumentNumber() {
return documentNumber;
}
@@ -124,12 +124,16 @@
*
* @param id
* the required ID value
+ * @param getParent
+ * true if running the element-with-id() function rather than the id()
+ * function; the difference is that in the case of an element of type xs:ID,
+ * the parent of the element should be returned, not the element itself.
* @return the element with the given ID, or null if there is no such ID
* present (or if the parser has not notified attributes as being of
* type ID).
*/
- public NodeInfo selectID(String id) {
+ public NodeInfo selectID(String id, boolean getParent) {
if (idIndex == null) {
Element elem;
switch (nodeKind) {
@@ -145,7 +149,14 @@
idIndex = new HashMap(50);
buildIDIndex(elem);
}
- return (NodeInfo) idIndex.get(id);
+
+ NodeInfo result = (NodeInfo) idIndex.get(id);
+
+ if (result != null && getParent && result.isId() && result.getStringValue().equals(id)) {
+ result = result.getParent();
+ }
+
+ return result ;
}
Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/NodeWrapper.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/NodeWrapper.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/NodeWrapper.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -160,6 +160,14 @@
}
/**
+ * Get the real XOM node, to implement the VirtualNode interface
+ */
+
+ public Object getRealNode() {
+ return node;
+ }
+
+ /**
* Get the name pool for this node
*
* @return the NamePool
@@ -799,7 +807,7 @@
* free-standing orphan node, just return the hashcode.
*/
- public int getDocumentNumber() {
+ public long getDocumentNumber() {
return docWrapper.getDocumentNumber();
}
Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/StreamingUtils.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -256,6 +256,7 @@
public void close() throws XPathException {
reciever.close();
+ super.close();
}
public void comment(CharSequence content, int locationId, int properties)
@@ -265,6 +266,7 @@
public void endDocument() throws XPathException {
reciever.endDocument();
+ super.endDocument() ;
}
public void endElement() throws XPathException {
@@ -285,6 +287,7 @@
}
public void open() throws XPathException {
+ super.open();
reciever.open();
}
@@ -295,10 +298,12 @@
public void setPipelineConfiguration(PipelineConfiguration config) {
reciever.setPipelineConfiguration(config);
+ super.setPipelineConfiguration(config);
}
public void setSystemId(String systemId) {
reciever.setSystemId(systemId);
+ super.setSystemId(systemId);
}
public void setUnparsedEntity(String name, String systemID,
@@ -311,6 +316,7 @@
}
public void startDocument(int properties) throws XPathException {
+ super.startDocument(properties);
reciever.startDocument(properties);
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-07-22 16:26:08 UTC (rev 3327)
@@ -232,7 +232,7 @@
ERR.015.004.0010= Unknown group specified in OPTION MAKEDEP/MAKENOTDEP: {0}
ERR.015.004.0012= Group has an access pattern which has not been met: group(s) {0}; access pattern(s) {1}
ERR.015.004.0020= Error getting model for {0}
-ERR.015.004.0023= Error rewriting criteria: {0}
+ERR.015.004.0023= Error rewriting: {0}
ERR.015.004.0024= Unable to create a query plan that sends a criteria to \"{0}\". This connection factory requires criteria set to true indicating that a query against this model requires criteria.
ERR.015.004.0029= Could not resolve group symbol {0}
ERR.015.004.0035= The criteria {0} has elements from the root staging table and the document nodes which is not allowed.
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -33,7 +33,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.query.sql.symbol.ElementSymbol;
-@SuppressWarnings("nls")
+@SuppressWarnings({"nls", "unchecked"})
public class TestSTree {
@Test public void testRemoveAll() throws TeiidComponentException {
@@ -42,7 +42,7 @@
e1.setType(Integer.class);
ElementSymbol e2 = new ElementSymbol("y");
e2.setType(String.class);
- List elements = Arrays.asList(e1, e2);
+ List<ElementSymbol> elements = Arrays.asList(e1, e2);
STree map = bm.createSTree(elements, "1", 1);
for (int i = 20000; i > 0; i--) {
@@ -83,7 +83,7 @@
ElementSymbol e1 = new ElementSymbol("x");
e1.setType(Integer.class);
- List elements = Arrays.asList(e1);
+ List<ElementSymbol> elements = Arrays.asList(e1);
STree map = bm.createSTree(elements, "1", 1);
int size = (1<<16)+(1<<4)+1;
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/FakeConnector.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/FakeConnector.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/FakeConnector.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -22,35 +22,25 @@
package org.teiid.dqp.internal.datamgr;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import junit.framework.Assert;
-
import org.teiid.language.Command;
-import org.teiid.language.QueryExpression;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.Execution;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.UpdateExecution;
-public class FakeConnector extends ExecutionFactory {
- private static final int RESULT_SIZE = 5;
-
- private boolean executeBlocks;
- private boolean nextBatchBlocks;
- private boolean returnsFinalBatch;
- private boolean driverThrowsExceptionOnCancel;
- private long simulatedBatchRetrievalTime = 1000L;
- private ClassLoader classloader;
+public class FakeConnector extends ExecutionFactory<Object, Object> {
private int connectionCount;
private int executionCount;
-
+
public int getConnectionCount() {
return connectionCount;
}
@@ -62,123 +52,52 @@
@Override
public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
executionCount++;
- return new FakeBlockingExecution(executionContext);
+ return new FakeExecution(executionContext);
}
- public Object getConnection() {
- return new FakeConnection();
- }
-
@Override
public Object getConnection(Object factory) throws TranslatorException {
+ connectionCount++;
return factory;
}
@Override
public void closeConnection(Object connection, Object factory) {
}
-
- private class FakeConnection {
- public FakeConnection() {
- connectionCount++;
- }
-
- public boolean released = false;
- public void close() {
- Assert.assertFalse("The connection should not be released more than once", released); //$NON-NLS-1$
- released = true;
- }
- }
- private final class FakeBlockingExecution implements ResultSetExecution, UpdateExecution {
- private boolean closed = false;
- private boolean cancelled = false;
+ public final class FakeExecution implements ResultSetExecution, UpdateExecution {
private int rowCount;
ExecutionContext ec;
- public FakeBlockingExecution(ExecutionContext ec) {
+
+ public FakeExecution(ExecutionContext ec) {
this.ec = ec;
}
- public void execute(QueryExpression query, int maxBatchSize) throws TranslatorException {
- if (executeBlocks) {
- waitForCancel();
- }
- if (classloader != null) {
- Assert.assertSame(classloader, Thread.currentThread().getContextClassLoader());
- }
- }
- public synchronized void cancel() throws TranslatorException {
- cancelled = true;
- this.notify();
- }
- public void close() {
- Assert.assertFalse("The execution should not be closed more than once", closed); //$NON-NLS-1$
- closed = true;
- }
@Override
public void execute() throws TranslatorException {
ec.addWarning(new Exception("Some warning")); //$NON-NLS-1$
}
@Override
- public List next() throws TranslatorException, DataNotAvailableException {
- if (nextBatchBlocks) {
- waitForCancel();
- }
- if (this.rowCount >= RESULT_SIZE || returnsFinalBatch) {
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ if (this.rowCount == 1) {
return null;
}
this.rowCount++;
- return Arrays.asList(this.rowCount - 1);
+ return new ArrayList<Object>(Arrays.asList(this.rowCount - 1));
}
- private synchronized void waitForCancel() throws TranslatorException {
- try {
- this.wait(simulatedBatchRetrievalTime);
- if (cancelled && driverThrowsExceptionOnCancel) {
- throw new TranslatorException("Request cancelled"); //$NON-NLS-1$
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
@Override
public int[] getUpdateCounts() throws DataNotAvailableException,
TranslatorException {
return new int[] {1};
}
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ }
}
- public boolean isExecuteBlocks() {
- return executeBlocks;
- }
- public void setExecuteBlocks(boolean executeBlocks) {
- this.executeBlocks = executeBlocks;
- }
- public boolean isNextBatchBlocks() {
- return nextBatchBlocks;
- }
- public void setNextBatchBlocks(boolean nextBatchBlocks) {
- this.nextBatchBlocks = nextBatchBlocks;
- }
- public boolean isReturnsFinalBatch() {
- return returnsFinalBatch;
- }
- public void setReturnsFinalBatch(boolean returnsFinalBatch) {
- this.returnsFinalBatch = returnsFinalBatch;
- }
- public boolean isDriverThrowsExceptionOnCancel() {
- return driverThrowsExceptionOnCancel;
- }
- public void setDriverThrowsExceptionOnCancel(
- boolean driverThrowsExceptionOnCancel) {
- this.driverThrowsExceptionOnCancel = driverThrowsExceptionOnCancel;
- }
- public long getSimulatedBatchRetrievalTime() {
- return simulatedBatchRetrievalTime;
- }
- public void setSimulatedBatchRetrievalTime(long simulatedBatchRetrievalTime) {
- this.simulatedBatchRetrievalTime = simulatedBatchRetrievalTime;
- }
- public void setClassloader(ClassLoader classloader) {
- this.classloader = classloader;
- }
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -50,7 +50,7 @@
return c;
}
protected Object getConnectionFactory(){
- return c.getConnection();
+ return c;
}
};
cm.start();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorWorkItem.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorWorkItem.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorWorkItem.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -87,7 +87,7 @@
int total_columns = 3;
StoredProcedure command = (StoredProcedure)helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT); //$NON-NLS-1$
command.getInputParameters().get(0).setExpression(new Constant(1));
- Call proc = (Call)new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
+ Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestElementImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestElementImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestElementImpl.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -72,7 +72,7 @@
public void testGetName() throws Exception {
Object metadataID = TstLanguageBridgeFactory.metadata.getElementID("pm1.g1.e1"); //$NON-NLS-1$
- assertEquals("pm1.g1.e1", example("pm1.g1", "e1", metadataID).getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("e1", example("pm1.g1", "e1", metadataID).getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testGetGroup() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestWorkItemState.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -25,20 +25,10 @@
import static org.junit.Assert.*;
import org.junit.Test;
-import org.teiid.dqp.internal.process.AbstractWorkItem.ThreadState;
public class TestWorkItemState {
- private final class WorkItemRunner implements Runnable {
- TestWorkItem workItem;
-
- @Override
- public void run() {
- workItem.run();
- }
- }
-
private class TestWorkItem extends AbstractWorkItem {
private boolean isDone;
@@ -50,11 +40,6 @@
}
private TestWorkItem(boolean done, boolean callMoreWork) {
- this(done, callMoreWork, null);
- }
-
- private TestWorkItem(boolean done, boolean callMoreWork, Thread callingThread) {
- super(callingThread);
this.isDone = done;
this.callMoreWork = callMoreWork;
}
@@ -167,26 +152,4 @@
}
}
- @Test public void testUsingCallingThreadIdle() throws Exception {
- WorkItemRunner r = new WorkItemRunner();
- Thread t = new Thread(r);
- final TestWorkItem item = new TestWorkItem(false, false, t) {
- @Override
- protected boolean shouldPause() {
- return true;
- }
- };
- r.workItem = item;
- t.start();
- for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
- Thread.sleep(100);
- }
- if (item.getThreadState() != ThreadState.IDLE) {
- fail();
- }
- item.moreWork();
- //if we don't return from this call, that means that this thread has been hijacked -
- //we should instead use t.
- }
-
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -1000,9 +1000,10 @@
}
@Test public void testTimestampDiffTimeStamp_Day_1() throws Exception {
+ // Moving to June, March fails because of DST
helpTestTimestampDiff(NonReserved.SQL_TSI_DAY,
- TimestampUtil.createTimestamp((2004-1900), 2, 1, 0, 0, 0, 0),
- TimestampUtil.createTimestamp((2004-1900), 3, 1, 0, 0, 0, 0),
+ TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 0, 0),
+ TimestampUtil.createTimestamp((2004-1900), 5, 1, 0, 0, 0, 0),
new Long(31));
}
Property changes on: trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/function/TestFunction.java:3281-3325
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -757,6 +757,7 @@
}
@Test public void testSubqueryRewriteToJoinDistinct() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1)", "SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example1Cached());
}
@@ -764,6 +765,7 @@
* Agg does not depend on cardinality
*/
@Test public void testSubqueryRewriteToJoinGroupBy() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select max(e1) from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1) group by e2", "SELECT MAX(e1) FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1 GROUP BY e2", RealMetadataFactory.example1Cached());
}
@@ -775,6 +777,7 @@
}
@Test public void testSubqueryRewriteToJoin() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 = X__1.e1", RealMetadataFactory.example4());
}
@@ -919,6 +922,7 @@
* Same as above, but the source is much larger, so a semi-join is favorable
*/
@Test public void testSemiJoinExistsCosting() {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
ProcessorPlan plan = helpPlan("Select e1 from pm2.g2 as o where not exists (select 1 from pm3.g1 where e1 = o.e1 having o.e2 = count(e2))", RealMetadataFactory.example4(), //$NON-NLS-1$
new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm2.g2 AS g_0 ORDER BY c_0, c_1" }); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3149-3217
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java:3149-3217,3281-3325
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -202,8 +202,8 @@
String sql = "select * from xmltable('/a/b' passing convert('<a><b>first</b><b x=\"1\">second</b></a>', xml) columns val xml path '.') as x"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
- Arrays.asList("<b>first</b>"),
- Arrays.asList("<b x=\"1\">second</b>"),
+ Arrays.asList("<b xmlns=\"\">first</b>"),
+ Arrays.asList("<b xmlns=\"\" x=\"1\">second</b>"),
};
process(sql, expected);
@@ -286,7 +286,7 @@
String sql = "select xmlquery('/a/b' passing xmlparse(document '<a><b x=''1''/><b x=''2''/></a>') null on empty)"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
- Arrays.asList("<b x=\"1\"/><b x=\"2\"/>")
+ Arrays.asList("<b xmlns=\"\" x=\"1\"/><b xmlns=\"\" x=\"2\"/>")
};
process(sql, expected);
Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275
+ /branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java:3149-3217,3220-3275,3281-3325
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -124,11 +124,11 @@
}
private Map<ElementSymbol, Integer> elements;
- private List<List> tuples;
+ private List<List<? extends Object>> tuples;
@Before public void setUp() {
elements = null;
- tuples = new ArrayList<List>();
+ tuples = new ArrayList<List<? extends Object>>();
}
private Criteria helpTestRewriteCriteria(String original, Criteria expectedCrit, QueryMetadataInterface metadata) {
@@ -138,7 +138,7 @@
// rewrite
try {
ArrayList<Boolean> booleanVals = new ArrayList<Boolean>(tuples.size());
- for (List<Object> tuple : tuples) {
+ for (List<?> tuple : tuples) {
booleanVals.add(new Evaluator(elements, null, null).evaluate(origCrit, tuple));
}
actual = QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
@@ -2085,10 +2085,6 @@
helpTestRewriteCriteria("concat2('a', pm1.g1.e1) = 'xyz'", "concat('a', ifnull(pm1.g1.e1, '')) = 'xyz'"); //$NON-NLS-1$ //$NON-NLS-2$
}
- @Test public void testRewiteEvaluatableAggregate() {
- helpTestRewriteCommand("select max(1) from pm1.g1", "SELECT MAX(1) FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
@Test public void testRewriteFromUnixTime() throws Exception {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
@@ -2448,5 +2444,21 @@
String sql = "parsedate_(pm1.g1.e1) = {d'2001-01-01'}";
helpTestRewriteCriteria(sql, parseCriteria(sql, metadata), metadata);
}
+
+ @Test public void testRewriteNestedConvert() throws Exception {
+ helpTestRewriteExpression("cast(cast(pm1.g1.e3 as integer) as long)", "cast(pm1.g1.e3 as long)", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testRewriteNestedConvert1() throws Exception {
+ helpTestRewriteExpression("cast(cast(pm1.g1.e3 as integer) as string)", "convert(convert(pm1.g1.e3, integer), string)", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ @Test public void testRewriteNestedConvert2() throws Exception {
+ helpTestRewriteExpression("cast(cast(pm1.g1.e3 as string) as clob)", "convert(convert(pm1.g1.e3, string), clob)", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testRewriteConstantAgg() throws Exception {
+ helpTestRewriteCommand("select max(1) from pm1.g1 group by e1", "SELECT 1 FROM pm1.g1 GROUP BY e1");
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -419,6 +419,14 @@
new String[] {"COUNT(DISTINCT ObjectValue)"}, RealMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
}
+ /**
+ * previously failed on stringkey, which is not entirely correct
+ */
+ @Test public void testInvalidAggregate10() {
+ helpValidate("SELECT xmlparse(document stringkey) FROM BQT1.SmallA GROUP BY xmlparse(document stringkey)", //$NON-NLS-1$
+ new String[] {"XMLPARSE(DOCUMENT stringkey)"}, RealMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
+ }
+
@Test public void testInvalidAggregateIssue190644() {
helpValidate("SELECT e3 + 1 from pm1.g1 GROUP BY e2 + 1 HAVING e2 + 1 = 5", new String[] {"e3"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -436,6 +444,11 @@
"FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end", //$NON-NLS-1$
new String[] {}, RealMetadataFactory.exampleBQTCached());
}
+
+ @Test public void testValidAggregate4() {
+ helpValidate("SELECT max(e1), e2 is null from pm1.g1 GROUP BY e2 is null", new String[] {}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$
+ }
+
@Test public void testInvalidHaving1() {
helpValidate("SELECT e3 FROM test.group HAVING e3 > 0", new String[] {"e3"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/pom.xml 2011-07-22 16:26:08 UTC (rev 3327)
@@ -439,16 +439,10 @@
</dependency>
<dependency>
<groupId>net.sourceforge.saxon</groupId>
- <artifactId>saxon</artifactId>
- <version>9.1.0.8</version>
+ <artifactId>saxonhe</artifactId>
+ <version>9.2.1.5</version>
</dependency>
<dependency>
- <groupId>net.sourceforge.saxon</groupId>
- <artifactId>saxon</artifactId>
- <classifier>dom</classifier>
- <version>9.1.0.8</version>
- </dependency>
- <dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.1.Final</version>
@@ -493,4 +487,4 @@
<url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
-</project>
\ No newline at end of file
+</project>
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCClientRemote.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -21,13 +21,14 @@
*/
package org.teiid.odbc;
+import java.io.IOException;
import java.sql.ParameterMetaData;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
+import java.util.List;
import java.util.Properties;
import org.teiid.client.util.ResultsFuture;
import org.teiid.jdbc.ResultSetImpl;
+import org.teiid.odbc.PGUtil.PgColInfo;
public interface ODBCClientRemote {
@@ -62,11 +63,19 @@
// RowDescription (B)
// NoData (B)
- void sendResultSetDescription(ResultSetMetaData metaData, Statement stmt);
+ void sendResultSetDescription(List<PgColInfo> cols);
// DataRow (B)
// CommandComplete (B)
- void sendResults(String sql, ResultSetImpl rs, ResultsFuture<Void> result, boolean describeRows);
+ void sendResults(String sql, ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, boolean describeRows);
+
+ void sendCursorResults(ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, int rowCount);
+
+ void sendPortalResults(String sql, ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, int rowCount, boolean portal);
+
+ void sendMoveCursor(ResultSetImpl rs, int rowCount, ResultsFuture<Integer> results);
+
+ void sendCommandComplete(String sql, int updateCount) throws IOException;
// CommandComplete (B)
void sendUpdateCount(String sql, int updateCount);
@@ -106,8 +115,5 @@
// NoticeResponse (B)
// NotificationResponse (B)
- // PortalSuspended (B)
-
-
-
+ void sendPortalSuspended();
}
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -21,14 +21,19 @@
*/
package org.teiid.odbc;
+import static org.teiid.odbc.PGUtil.convertType;
+
import java.io.IOException;
import java.io.StringReader;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
@@ -40,10 +45,12 @@
import org.teiid.core.util.StringUtil;
import org.teiid.jdbc.ConnectionImpl;
import org.teiid.jdbc.PreparedStatementImpl;
+import org.teiid.jdbc.ResultSetImpl;
import org.teiid.jdbc.StatementImpl;
import org.teiid.jdbc.TeiidDriver;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.odbc.PGUtil.PgColInfo;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.transport.ODBCClientInstance;
@@ -133,11 +140,17 @@
private static Pattern preparedAutoIncrement = Pattern.compile("select 1 \\s*from pg_catalog.pg_attrdef \\s*where adrelid = \\$1 AND adnum = \\$2 " + //$NON-NLS-1$
"\\s*and pg_catalog.pg_get_expr\\(adbin, adrelid\\) \\s*like '%nextval\\(%'", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
- private static Pattern deallocatePattern = Pattern.compile("DEALLOCATE \"(\\w+\\d+_*)\""); //$NON-NLS-1$
- private static Pattern releasePattern = Pattern.compile("RELEASE (\\w+\\d+_*)"); //$NON-NLS-1$
- private static Pattern savepointPattern = Pattern.compile("SAVEPOINT (\\w+\\d+_*)"); //$NON-NLS-1$
- private static Pattern rollbackPattern = Pattern.compile("ROLLBACK\\s*(to)*\\s*(\\w+\\d+_*)*"); //$NON-NLS-1$
+ private static Pattern cursorSelectPattern = Pattern.compile("DECLARE \"(\\w+)\" CURSOR(\\s(WITH HOLD|SCROLL))? FOR (.*)", Pattern.CASE_INSENSITIVE|Pattern.DOTALL); //$NON-NLS-1$
+ private static Pattern fetchPattern = Pattern.compile("FETCH (\\d+) IN \"(\\w+)\".*", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern movePattern = Pattern.compile("MOVE (\\d+) IN \"(\\w+)\".*", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern closePattern = Pattern.compile("CLOSE \"(\\w+)\"", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern deallocatePattern = Pattern.compile("DEALLOCATE \"(\\w+\\d+_*)\"", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern releasePattern = Pattern.compile("RELEASE (\\w+\\d?_*)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern savepointPattern = Pattern.compile("SAVEPOINT (\\w+\\d?_*)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ private static Pattern rollbackPattern = Pattern.compile("ROLLBACK\\s*(to)*\\s*(\\w+\\d+_*)*", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+
+
private TeiidDriver driver;
private ODBCClientRemote client;
private Properties props;
@@ -151,6 +164,7 @@
// TODO: this is unbounded map; need to define some boundaries as to how many stmts each session can have
private Map<String, Prepared> preparedMap = Collections.synchronizedMap(new HashMap<String, Prepared>());
private Map<String, Portal> portalMap = Collections.synchronizedMap(new HashMap<String, Portal>());
+ private Map<String, Cursor> cursorMap = Collections.synchronizedMap(new HashMap<String, Cursor>());
public ODBCServerRemoteImpl(ODBCClientInstance client, AuthenticationType authType, TeiidDriver driver) {
this.driver = driver;
@@ -196,6 +210,173 @@
}
}
+ private void cursorExecute(final String cursorName, final String sql, final ResultsFuture<Integer> completion) {
+ if (this.connection != null) {
+ if (sql != null) {
+ try {
+ // close if the name is already used or the unnamed prepare; otherwise
+ // stmt is alive until session ends.
+ Prepared previous = this.preparedMap.remove(cursorName);
+ if (previous != null) {
+ previous.stmt.close();
+ }
+
+ final PreparedStatementImpl stmt = this.connection.prepareStatement(sql);
+ this.executionFuture = stmt.submitExecute();
+ this.executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
+ @Override
+ public void onCompletion(ResultsFuture<Boolean> future) {
+ executionFuture = null;
+ try {
+ if (future.get()) {
+ List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
+ cursorMap.put(cursorName, new Cursor(cursorName, sql, stmt, null, stmt.getResultSet(), cols));
+ client.sendCommandComplete("DECLARE CURSOR", 0); //$NON-NLS-1$
+ }
+ else {
+ errorOccurred(RuntimePlugin.Util.getString("execution_failed")); //$NON-NLS-1$
+ }
+ } catch (Throwable e) {
+ errorOccurred(e);
+ }
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ });
+ } catch (SQLException e) {
+ errorOccurred(e);
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ }
+ }
+ else {
+ errorOccurred(RuntimePlugin.Util.getString("no_active_connection")); //$NON-NLS-1$
+ completion.getResultsReceiver().receiveResults(1);
+ }
+
+ }
+
+ private void cursorFetch(String cursorName, int rows, final ResultsFuture<Integer> completion) {
+ Cursor cursor = this.cursorMap.get(cursorName);
+ if (cursor != null) {
+ cursor.fetchSize = rows;
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ this.client.sendCursorResults(cursor.rs, cursor.columnMetadata, result, rows);
+ result.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ int rowsSent = 0;
+ try {
+ rowsSent = future.get();
+ client.sendCommandComplete("FETCH", rowsSent); //$NON-NLS-1$
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ } catch (ExecutionException e) {
+ errorOccurred(e.getCause());
+ } catch (IOException e) {
+ errorOccurred(e);
+ }
+ completion.getResultsReceiver().receiveResults(rowsSent);
+ };
+ });
+ }
+ else {
+ errorOccurred(RuntimePlugin.Util.getString("not_bound", cursorName)); //$NON-NLS-1$
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ }
+
+ private void cursorMove(String prepareName, int rows, final ResultsFuture<Integer> completion) {
+
+ // win odbc driver sending a move after close; and error is ending up in failure; since the below
+ // is not harmful it is ok to send empty move.
+ if (rows == 0) {
+ try {
+ client.sendCommandComplete("MOVE", 0); //$NON-NLS-1$
+ } catch (IOException e) {
+ errorOccurred(e);
+ }
+ completion.getResultsReceiver().receiveResults(0);
+ return;
+ }
+
+ Cursor cursor = this.cursorMap.get(prepareName);
+ if (cursor != null) {
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ this.client.sendMoveCursor(cursor.rs, rows, result);
+ result.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ int rowsMoved = 0;
+ try {
+ rowsMoved = future.get();
+ client.sendCommandComplete("MOVE", rowsMoved); //$NON-NLS-1$
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ } catch (ExecutionException e) {
+ errorOccurred(e.getCause());
+ } catch (IOException e) {
+ errorOccurred(e);
+ }
+ completion.getResultsReceiver().receiveResults(rowsMoved);
+ };
+ });
+ }
+ else {
+ errorOccurred(RuntimePlugin.Util.getString("not_bound", prepareName)); //$NON-NLS-1$
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ }
+
+ private void cursorClose(String prepareName) throws SQLException, IOException {
+ Cursor cursor = this.cursorMap.remove(prepareName);
+ if (cursor != null) {
+ cursor.rs.close();
+ cursor.stmt.close();
+ this.client.sendCommandComplete("CLOSE CURSOR", 0); //$NON-NLS-1$
+ }
+ }
+
+ private void sqlExecute(final String sql, final ResultsFuture<Integer> completion) throws SQLException {
+ String modfiedSQL = fixSQL(sql);
+ final StatementImpl stmt = connection.createStatement();
+ executionFuture = stmt.submitExecute(modfiedSQL);
+ executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
+ @Override
+ public void onCompletion(ResultsFuture<Boolean> future) {
+ executionFuture = null;
+ try {
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ if (future.get()) {
+ if (stmt.getResultSet() != null) {
+ List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
+ client.sendResults(sql, stmt.getResultSet(), cols, result, true);
+ }
+ else {
+ // handles the "SET" commands.
+ client.sendUpdateCount(sql, 0);
+ result.getResultsReceiver().receiveResults(1);
+ }
+ } else {
+ client.sendUpdateCount(sql, stmt.getUpdateCount());
+ setEncoding();
+ result.getResultsReceiver().receiveResults(1);
+ }
+ result.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ LogManager.logDetail(LogConstants.CTX_ODBC, e, "Error closing statement"); //$NON-NLS-1$
+ }
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ });
+ } catch (Throwable e) {
+ errorOccurred(e);
+ completion.getResultsReceiver().receiveResults(1);
+ }
+ }
+ });
+ }
+
@Override
public void prepare(String prepareName, String sql, int[] paramType) {
if (this.connection != null) {
@@ -274,60 +455,96 @@
bindName = UNNAMED;
}
+ // special case cursor execution through portal
+ final Cursor cursor = this.cursorMap.get(bindName);
+ if (cursor != null) {
+ sendCursorResults(cursor);
+ return;
+ }
+
final Portal query = this.portalMap.get(bindName);
if (query == null) {
errorOccurred(RuntimePlugin.Util.getString("not_bound", bindName)); //$NON-NLS-1$
- }
- else {
- if (query.sql.trim().isEmpty()) {
- this.client.emptyQueryReceived();
- return;
- }
-
- final PreparedStatementImpl stmt = query.stmt;
- try {
- // maxRows = 0, means unlimited.
- if (maxRows != 0) {
- stmt.setMaxRows(maxRows);
- }
-
- this.executionFuture = stmt.submitExecute();
- executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
- @Override
- public void onCompletion(ResultsFuture<Boolean> future) {
- executionFuture = null;
- try {
- ResultsFuture<Void> result = null;
- if (future.get()) {
- result = new ResultsFuture<Void>();
- client.sendResults(query.sql, stmt.getResultSet(), result, true);
- } else {
- result = ResultsFuture.NULL_FUTURE;
- client.sendUpdateCount(query.sql, stmt.getUpdateCount());
- setEncoding();
- }
- result.addCompletionListener(new ResultsFuture.CompletionListener<Void>() {
- public void onCompletion(ResultsFuture<Void> future) {
- try {
- future.get();
- doneExecuting();
- } catch (InterruptedException e) {
- throw new AssertionError(e);
- } catch (ExecutionException e) {
- errorOccurred(e.getCause());
- }
- };
- });
- } catch (Throwable e) {
- errorOccurred(e);
- }
- }
- });
- } catch (SQLException e) {
- errorOccurred(e);
- }
+ return;
+ }
+
+ if (query.sql.trim().isEmpty()) {
+ this.client.emptyQueryReceived();
+ return;
}
+
+ sendPortalResults(maxRows, query);
}
+
+ private void sendPortalResults(int maxRows, final Portal query) {
+ final PreparedStatementImpl stmt = query.stmt;
+ try {
+ // maxRows = 0, means unlimited.
+ if (maxRows != 0) {
+ stmt.setMaxRows(maxRows);
+ }
+
+ this.executionFuture = stmt.submitExecute();
+ executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
+ @Override
+ public void onCompletion(ResultsFuture<Boolean> future) {
+ executionFuture = null;
+ try {
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ if (future.get()) {
+ List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
+ client.sendResults(query.sql, stmt.getResultSet(), cols, result, true);
+ } else {
+ // null future
+ client.sendUpdateCount(query.sql, stmt.getUpdateCount());
+ setEncoding();
+ result.getResultsReceiver().receiveResults(1);
+ }
+ result.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ try {
+ future.get();
+ doneExecuting();
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ } catch (ExecutionException e) {
+ errorOccurred(e.getCause());
+ }
+ };
+ });
+ } catch (Throwable e) {
+ errorOccurred(e);
+ }
+ }
+ });
+ } catch (SQLException e) {
+ errorOccurred(e);
+ }
+ }
+
+ private void sendCursorResults(final Cursor cursor) {
+ ResultsFuture<Integer> result = new ResultsFuture<Integer>();
+ this.client.sendPortalResults(cursor.sql, cursor.rs, cursor.columnMetadata, result, cursor.fetchSize, true);
+ result.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ try {
+ int rowsSent = future.get();
+ if (rowsSent < cursor.fetchSize) {
+ client.sendCommandComplete(cursor.sql, 0);
+ }
+ else {
+ client.sendPortalSuspended();
+ }
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ } catch (ExecutionException e) {
+ errorOccurred(e.getCause());
+ } catch (IOException e) {
+ errorOccurred(e);
+ }
+ };
+ });
+ }
private String fixSQL(String sql) {
String modified = modifySQL(sql);
@@ -409,16 +626,6 @@
}
else if ((m = rollbackPattern.matcher(modified)).matches()) {
return "ROLLBACK"; //$NON-NLS-1$
- }
- else if ((m = savepointPattern.matcher(modified)).matches()) {
- return "SELECT 'SAVEPOINT'"; //$NON-NLS-1$
- }
- else if ((m = releasePattern.matcher(modified)).matches()) {
- return "SELECT 'RELEASE'"; //$NON-NLS-1$
- }
- else if ((m = deallocatePattern.matcher(modified)).matches()) {
- closePreparedStatement(m.group(1));
- return "SELECT 'DEALLOCATE'"; //$NON-NLS-1$
}
}
modified = sql;
@@ -431,7 +638,7 @@
@Override
public void executeQuery(final String query) {
if (beginExecution()) {
- this.client.errorOccurred("Awaiting asynch result"); //$NON-NLS-1$
+ errorOccurred("Awaiting asynch result"); //$NON-NLS-1$
ready();
return;
}
@@ -482,7 +689,8 @@
// followed by a RowDescription message describing the rows that will be returned when the statement
// is eventually executed (or a NoData message if the statement will not return rows).
- this.client.sendResultSetDescription(query.stmt.getMetaData(), query.stmt);
+ List<PgColInfo> cols = getPgColInfo(query.stmt.getMetaData());
+ this.client.sendResultSetDescription(cols);
} catch (SQLException e) {
errorOccurred(e);
}
@@ -516,7 +724,8 @@
}
else {
try {
- this.client.sendResultSetDescription(query.stmt.getMetaData(), query.stmt);
+ List<PgColInfo> cols = getPgColInfo(query.stmt.getMetaData());
+ this.client.sendResultSetDescription(cols);
} catch (SQLException e) {
errorOccurred(e);
}
@@ -622,6 +831,9 @@
try {
if (this.connection != null) {
+ if (!this.connection.getAutoCommit()) {
+ this.connection.rollback(false);
+ }
this.connection.close();
}
} catch (SQLException e) {
@@ -663,90 +875,124 @@
private final class QueryWorkItem implements Runnable {
private final ScriptReader reader;
- String modfiedSQL;
String sql;
private QueryWorkItem(String query) {
- this.reader = new ScriptReader(new StringReader(query));
+ this.reader = new ScriptReader(new StringReader(query));
}
@Override
public void run() {
try {
- if (modfiedSQL == null) {
+ if (sql == null) {
sql = reader.readStatement();
- modfiedSQL = fixSQL(sql);
}
- while (modfiedSQL != null) {
+ while (sql != null) {
try {
- final StatementImpl stmt = connection.createStatement();
- executionFuture = stmt.submitExecute(modfiedSQL);
- executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
- @Override
- public void onCompletion(ResultsFuture<Boolean> future) {
- executionFuture = null;
- try {
- ResultsFuture<Void> result = null;
- if (future.get()) {
- if (stmt.getResultSet() != null) {
- result = new ResultsFuture<Void>();
- client.sendResults(sql, stmt.getResultSet(), result, true);
- }
- else {
- // handles the "SET" commands.
- result = ResultsFuture.NULL_FUTURE;
- client.sendUpdateCount(sql, 0);
- }
- } else {
- result = ResultsFuture.NULL_FUTURE;
- client.sendUpdateCount(sql, stmt.getUpdateCount());
- setEncoding();
- }
- result.addCompletionListener(new ResultsFuture.CompletionListener<Void>() {
- public void onCompletion(ResultsFuture<Void> future) {
- try {
- future.get();
- sql = reader.readStatement();
- modfiedSQL = fixSQL(sql);
- } catch (InterruptedException e) {
- throw new AssertionError(e);
- } catch (IOException e) {
- client.errorOccurred(e);
- return;
- } catch (ExecutionException e) {
- client.errorOccurred(e.getCause());
- return;
- } finally {
- try {
- stmt.close();
- } catch (SQLException e) {
- LogManager.logDetail(LogConstants.CTX_ODBC, e, "Error closing statement"); //$NON-NLS-1$
- }
- }
- QueryWorkItem.this.run(); //continue processing
- };
- });
- } catch (Throwable e) {
- client.errorOccurred(e);
- return;
- }
- }
- });
+
+ ResultsFuture<Integer> results = new ResultsFuture<Integer>();
+ results.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
+ public void onCompletion(ResultsFuture<Integer> future) {
+ try {
+ future.get();
+ sql = reader.readStatement();
+ } catch (InterruptedException e) {
+ throw new AssertionError(e);
+ } catch (IOException e) {
+ client.errorOccurred(e);
+ return;
+ } catch (ExecutionException e) {
+ client.errorOccurred(e.getCause());
+ return;
+ }
+ QueryWorkItem.this.run(); //continue processing
+ };
+ });
+
+ if (isErrorOccurred()) {
+ if (!connection.getAutoCommit()) {
+ connection.rollback(false);
+ }
+ break;
+ }
+
+ Matcher m = null;
+ if ((m = cursorSelectPattern.matcher(sql)).matches()){
+ cursorExecute(m.group(1), fixSQL(m.group(4)), results);
+ }
+ else if ((m = fetchPattern.matcher(sql)).matches()){
+ cursorFetch(m.group(2), Integer.parseInt(m.group(1)), results);
+ }
+ else if ((m = movePattern.matcher(sql)).matches()){
+ cursorMove(m.group(2), Integer.parseInt(m.group(1)), results);
+ }
+ else if ((m = closePattern.matcher(sql)).matches()){
+ cursorClose(m.group(1));
+ results.getResultsReceiver().receiveResults(1);
+ }
+ else if ((m = savepointPattern.matcher(sql)).matches()) {
+ client.sendCommandComplete("SAVEPOINT", 0); //$NON-NLS-1$
+ results.getResultsReceiver().receiveResults(1);
+ }
+ else if ((m = releasePattern.matcher(sql)).matches()) {
+ client.sendCommandComplete("RELEASE", 0); //$NON-NLS-1$
+ results.getResultsReceiver().receiveResults(1);
+ }
+ else if ((m = deallocatePattern.matcher(sql)).matches()) {
+ closePreparedStatement(m.group(1));
+ client.sendCommandComplete("DEALLOCATE", 0); //$NON-NLS-1$
+ results.getResultsReceiver().receiveResults(1);
+ }
+ else {
+ sqlExecute(sql, results);
+ }
return; //wait for the execution to finish
} catch (SQLException e) {
- client.errorOccurred(e);
+ errorOccurred(e);
break;
}
}
} catch(IOException e) {
- client.errorOccurred(e);
+ errorOccurred(e);
}
doneExecuting();
ready();
}
-
}
-
+
+ private List<PgColInfo> getPgColInfo(ResultSetMetaData meta)
+ throws SQLException {
+ int columns = meta.getColumnCount();
+ final ArrayList<PgColInfo> result = new ArrayList<PgColInfo>(columns);
+ for (int i = 1; i < columns + 1; i++) {
+ final PgColInfo info = new PgColInfo();
+ info.name = meta.getColumnLabel(i).toLowerCase();
+ info.type = meta.getColumnType(i);
+ info.type = convertType(info.type);
+ info.precision = meta.getColumnDisplaySize(i);
+ String name = meta.getColumnName(i);
+ String table = meta.getTableName(i);
+ String schema = meta.getSchemaName(i);
+ if (schema != null) {
+ final PreparedStatementImpl ps = this.connection.prepareStatement("select attrelid, attnum, typoid from matpg_relatt where attname = ? and relname = ? and nspname = ?"); //$NON-NLS-1$
+ ps.setString(1, name);
+ ps.setString(2, table);
+ ps.setString(3, schema);
+ ResultSet rs = ps.executeQuery();
+ if (rs.next()) {
+ info.reloid = rs.getInt(1);
+ info.attnum = rs.getShort(2);
+ int specificType = rs.getInt(3);
+ if (!rs.wasNull()) {
+ info.type = specificType;
+ }
+ }
+ }
+ result.add(info);
+ }
+ return result;
+ }
+
/**
* Represents a PostgreSQL Prepared object.
*/
@@ -777,7 +1023,7 @@
/**
* The list of parameter types (if set).
*/
- int[] paramType;
+ int[] paramType;
}
/**
@@ -813,7 +1059,22 @@
/**
* The prepared statement.
*/
- PreparedStatementImpl stmt;
+ PreparedStatementImpl stmt;
}
+
+ static class Cursor extends Prepared {
+ ResultSetImpl rs;
+ int fetchSize = 1000;
+ /**
+ * calculated column metadata
+ */
+ List<PgColInfo> columnMetadata;
+
+ public Cursor (String name, String sql, PreparedStatementImpl stmt, int[] paramType, ResultSetImpl rs, List<PgColInfo> colMetadata) {
+ super(name, sql, stmt, paramType);
+ this.rs = rs;
+ this.columnMetadata = colMetadata;
+ }
+ }
}
Copied: trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java (from rev 3325, branches/7.4.x/runtime/src/main/java/org/teiid/odbc/PGUtil.java)
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java (rev 0)
+++ trunk/runtime/src/main/java/org/teiid/odbc/PGUtil.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -0,0 +1,114 @@
+/*
+ * 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.odbc;
+
+import java.sql.Types;
+
+import org.teiid.deployers.PgCatalogMetadataStore;
+
+public class PGUtil {
+
+ public static final int PG_TYPE_VARCHAR = 1043;
+
+ public static final int PG_TYPE_BOOL = 16;
+ public static final int PG_TYPE_BYTEA = 17;
+ public static final int PG_TYPE_BPCHAR = 1042;
+ public static final int PG_TYPE_INT8 = 20;
+ public static final int PG_TYPE_INT2 = 21;
+ public static final int PG_TYPE_INT4 = 23;
+ public static final int PG_TYPE_TEXT = 25;
+ //private static final int PG_TYPE_OID = 26;
+ public static final int PG_TYPE_FLOAT4 = 700;
+ public static final int PG_TYPE_FLOAT8 = 701;
+ public static final int PG_TYPE_UNKNOWN = 705;
+
+ public static final int PG_TYPE_OIDVECTOR = PgCatalogMetadataStore.PG_TYPE_OIDVECTOR;
+ public static final int PG_TYPE_OIDARRAY = PgCatalogMetadataStore.PG_TYPE_OIDARRAY;
+ public static final int PG_TYPE_CHARARRAY = PgCatalogMetadataStore.PG_TYPE_CHARARRAY;
+ public static final int PG_TYPE_TEXTARRAY = PgCatalogMetadataStore.PG_TYPE_TEXTARRAY;
+
+ public static final int PG_TYPE_DATE = 1082;
+ public static final int PG_TYPE_TIME = 1083;
+ public static final int PG_TYPE_TIMESTAMP_NO_TMZONE = 1114;
+ public static final int PG_TYPE_NUMERIC = 1700;
+ //private static final int PG_TYPE_LO = 14939;
+
+ public static class PgColInfo {
+ public String name;
+ public int reloid;
+ public short attnum;
+ public int type;
+ public int precision;
+ }
+
+ /**
+ * Types.ARRAY is not supported
+ */
+ public static int convertType(final int type) {
+ switch (type) {
+ case Types.BIT:
+ case Types.BOOLEAN:
+ return PG_TYPE_BOOL;
+ case Types.VARCHAR:
+ return PG_TYPE_VARCHAR;
+ case Types.CHAR:
+ return PG_TYPE_BPCHAR;
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ return PG_TYPE_INT2;
+ case Types.INTEGER:
+ return PG_TYPE_INT4;
+ case Types.BIGINT:
+ return PG_TYPE_INT8;
+ case Types.NUMERIC:
+ case Types.DECIMAL:
+ return PG_TYPE_NUMERIC;
+ case Types.FLOAT:
+ case Types.REAL:
+ return PG_TYPE_FLOAT4;
+ case Types.DOUBLE:
+ return PG_TYPE_FLOAT8;
+ case Types.TIME:
+ return PG_TYPE_TIME;
+ case Types.DATE:
+ return PG_TYPE_DATE;
+ case Types.TIMESTAMP:
+ return PG_TYPE_TIMESTAMP_NO_TMZONE;
+
+ case Types.BLOB:
+ case Types.BINARY:
+ case Types.VARBINARY:
+ case Types.LONGVARBINARY:
+ return PG_TYPE_BYTEA;
+
+ case Types.LONGVARCHAR:
+ case Types.CLOB:
+ return PG_TYPE_TEXT;
+
+ case Types.SQLXML:
+ return PG_TYPE_TEXT;
+
+ default:
+ return PG_TYPE_UNKNOWN;
+ }
+ }
+}
Modified: trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/runtime/src/main/java/org/teiid/transport/PgBackendProtocol.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -21,6 +21,26 @@
* 02110-1301 USA.
*/package org.teiid.transport;
+import static org.teiid.odbc.PGUtil.PG_TYPE_BOOL;
+import static org.teiid.odbc.PGUtil.PG_TYPE_BPCHAR;
+import static org.teiid.odbc.PGUtil.PG_TYPE_BYTEA;
+import static org.teiid.odbc.PGUtil.PG_TYPE_CHARARRAY;
+import static org.teiid.odbc.PGUtil.PG_TYPE_DATE;
+import static org.teiid.odbc.PGUtil.PG_TYPE_FLOAT4;
+import static org.teiid.odbc.PGUtil.PG_TYPE_FLOAT8;
+import static org.teiid.odbc.PGUtil.PG_TYPE_INT2;
+import static org.teiid.odbc.PGUtil.PG_TYPE_INT4;
+import static org.teiid.odbc.PGUtil.PG_TYPE_INT8;
+import static org.teiid.odbc.PGUtil.PG_TYPE_NUMERIC;
+import static org.teiid.odbc.PGUtil.PG_TYPE_OIDARRAY;
+import static org.teiid.odbc.PGUtil.PG_TYPE_OIDVECTOR;
+import static org.teiid.odbc.PGUtil.PG_TYPE_TEXT;
+import static org.teiid.odbc.PGUtil.PG_TYPE_TEXTARRAY;
+import static org.teiid.odbc.PGUtil.PG_TYPE_TIME;
+import static org.teiid.odbc.PGUtil.PG_TYPE_TIMESTAMP_NO_TMZONE;
+import static org.teiid.odbc.PGUtil.PG_TYPE_UNKNOWN;
+import static org.teiid.odbc.PGUtil.PG_TYPE_VARCHAR;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -32,13 +52,9 @@
import java.sql.Blob;
import java.sql.Clob;
import java.sql.ParameterMetaData;
-import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
import java.sql.SQLException;
-import java.sql.Statement;
import java.sql.Types;
-import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -58,16 +74,15 @@
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.ReaderInputStream;
import org.teiid.core.util.ReflectionHelper;
-import org.teiid.deployers.PgCatalogMetadataStore;
import org.teiid.jdbc.ResultSetImpl;
import org.teiid.jdbc.TeiidSQLException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.net.socket.ServiceInvocationStruct;
import org.teiid.odbc.ODBCClientRemote;
+import org.teiid.odbc.PGUtil.PgColInfo;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.transport.pg.PGbytea;
-
/**
* Represents the messages going from Server --> PG ODBC Client
* Some parts of this code is taken from H2's implementation of ODBC
@@ -92,19 +107,24 @@
}
}
}
-
+
+ // 300k
+ static int ODBC_SOCKET_BUFF_SIZE = Integer.parseInt(System.getProperty("ODBCPacketSize", "307200"));
+
private final class ResultsWorkItem implements Runnable {
private final List<PgColInfo> cols;
- private final String sql;
private final ResultSetImpl rs;
- private final ResultsFuture<Void> result;
+ private final ResultsFuture<Integer> result;
+ private int rows2Send;
+ private int rowsSent = 0;
+ private int rowsInBuffer = 0;
+ private ChannelBuffer buffer = ChannelBuffers.directBuffer(ODBC_SOCKET_BUFF_SIZE);
- private ResultsWorkItem(List<PgColInfo> cols, String sql,
- ResultSetImpl rs, ResultsFuture<Void> result) {
+ private ResultsWorkItem(List<PgColInfo> cols, ResultSetImpl rs, ResultsFuture<Integer> result, int rows2Send) {
this.cols = cols;
- this.sql = sql;
this.rs = rs;
this.result = result;
+ this.rows2Send = rows2Send;
}
@Override
@@ -117,8 +137,10 @@
@Override
public void onCompletion(ResultsFuture<Boolean> future) {
if (processRow(future)) {
- //this can be recursive, but ideally won't be called many times
- ResultsWorkItem.this.run();
+ if (rowsSent != rows2Send) {
+ //this can be recursive, but ideally won't be called many times
+ ResultsWorkItem.this.run();
+ }
}
}
});
@@ -138,10 +160,18 @@
boolean processNext = true;
try {
if (future.get()) {
- sendDataRow(rs, cols);
+ sendDataRow(rs, cols, buffer);
+ rowsSent++;
+ rowsInBuffer++;
+ boolean done = rowsSent == rows2Send;
+ flushResults(done);
+ processNext = !done;
+ if (done) {
+ result.getResultsReceiver().receiveResults(rowsSent);
+ }
} else {
- sendCommandComplete(sql, 0);
- result.getResultsReceiver().receiveResults(null);
+ sendContents(buffer);
+ result.getResultsReceiver().receiveResults(rowsSent);
processNext = false;
}
} catch (Throwable t) {
@@ -150,33 +180,17 @@
}
return processNext;
}
+
+ private void flushResults(boolean force) {
+ int avgRowsize = buffer.readableBytes()/rowsInBuffer;
+ if (force || buffer.writableBytes() < (avgRowsize*2)) {
+ sendContents(buffer);
+ buffer= ChannelBuffers.directBuffer(ODBC_SOCKET_BUFF_SIZE);
+ rowsInBuffer = 0;
+ }
+ }
}
-
- private static final int PG_TYPE_VARCHAR = 1043;
-
- private static final int PG_TYPE_BOOL = 16;
- private static final int PG_TYPE_BYTEA = 17;
- private static final int PG_TYPE_BPCHAR = 1042;
- private static final int PG_TYPE_INT8 = 20;
- private static final int PG_TYPE_INT2 = 21;
- private static final int PG_TYPE_INT4 = 23;
- private static final int PG_TYPE_TEXT = 25;
- //private static final int PG_TYPE_OID = 26;
- private static final int PG_TYPE_FLOAT4 = 700;
- private static final int PG_TYPE_FLOAT8 = 701;
- private static final int PG_TYPE_UNKNOWN = 705;
- private static final int PG_TYPE_OIDVECTOR = PgCatalogMetadataStore.PG_TYPE_OIDVECTOR;
- private static final int PG_TYPE_OIDARRAY = PgCatalogMetadataStore.PG_TYPE_OIDARRAY;
- private static final int PG_TYPE_CHARARRAY = PgCatalogMetadataStore.PG_TYPE_CHARARRAY;
- private static final int PG_TYPE_TEXTARRAY = PgCatalogMetadataStore.PG_TYPE_TEXTARRAY;
-
- private static final int PG_TYPE_DATE = 1082;
- private static final int PG_TYPE_TIME = 1083;
- private static final int PG_TYPE_TIMESTAMP_NO_TMZONE = 1114;
- private static final int PG_TYPE_NUMERIC = 1700;
- //private static final int PG_TYPE_LO = 14939;
-
private DataOutputStream dataOut;
private ByteArrayOutputStream outBuffer;
private char messageType;
@@ -191,7 +205,7 @@
private SSLConfiguration config;
- public PgBackendProtocol(int maxLobSize, SSLConfiguration config) {
+ public PgBackendProtocol(int maxLobSize, SSLConfiguration config) {
this.maxLobSize = maxLobSize;
this.config = config;
}
@@ -340,35 +354,65 @@
}
@Override
- public void sendResultSetDescription(ResultSetMetaData metaData, Statement stmt) {
+ public void sendResultSetDescription(List<PgColInfo> cols) {
try {
+ sendRowDescription(cols);
+ } catch (IOException e) {
+ terminate(e);
+ }
+ }
+
+ @Override
+ public void sendCursorResults(ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, int rowCount) {
+ try {
+ sendRowDescription(cols);
+
+ ResultsWorkItem r = new ResultsWorkItem(cols, rs, result, rowCount);
+ r.run();
+ } catch (IOException e) {
+ terminate(e);
+ }
+ }
+
+ @Override
+ public void sendPortalResults(String sql, ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, int rowCount, boolean portal) {
+ ResultsWorkItem r = new ResultsWorkItem(cols, rs, result, rowCount);
+ r.run();
+ }
+
+ @Override
+ public void sendMoveCursor(ResultSetImpl rs, int rowCount, ResultsFuture<Integer> results) {
+ try {
try {
- List<PgColInfo> cols = getPgColInfo(metaData, stmt);
- sendRowDescription(cols);
+ int rowsMoved = 0;
+ for (int i = 0; i < rowCount; i++) {
+ if (!rs.next()) {
+ break;
+ }
+ rowsMoved++;
+ }
+ results.getResultsReceiver().receiveResults(rowsMoved);
} catch (SQLException e) {
- sendErrorResponse(e);
- }
+ sendErrorResponse(e);
+ }
} catch (IOException e) {
terminate(e);
}
- }
+ }
@Override
- public void sendResults(final String sql, final ResultSetImpl rs, ResultsFuture<Void> result, boolean describeRows) {
+ public void sendResults(final String sql, final ResultSetImpl rs, List<PgColInfo> cols, ResultsFuture<Integer> result, boolean describeRows) {
try {
if (nextFuture != null) {
sendErrorResponse(new IllegalStateException("Pending results have not been sent")); //$NON-NLS-1$
}
- ResultSetMetaData meta = rs.getMetaData();
- List<PgColInfo> cols = getPgColInfo(meta, rs.getStatement());
if (describeRows) {
sendRowDescription(cols);
}
- Runnable r = new ResultsWorkItem(cols, sql, rs, result);
+ ResultsWorkItem r = new ResultsWorkItem(cols, rs, result, -1);
r.run();
- } catch (SQLException e) {
- result.getResultsReceiver().exceptionOccurred(e);
+ sendCommandComplete(sql, 0);
} catch (IOException e) {
terminate(e);
}
@@ -425,8 +469,9 @@
startMessage('I');
sendMessage();
}
-
- private void sendCommandComplete(String sql, int updateCount) throws IOException {
+
+ @Override
+ public void sendCommandComplete(String sql, int updateCount) throws IOException {
startMessage('C');
sql = sql.trim().toUpperCase();
// TODO remove remarks at the beginning
@@ -439,7 +484,7 @@
tag = "UPDATE " + updateCount;
} else if (sql.startsWith("SELECT") || sql.startsWith("CALL")) {
tag = "SELECT";
- } else if (sql.startsWith("BEGIN")) {
+ } else if (sql.startsWith("BEGIN") || sql.startsWith("START TRANSACTION")) {
tag = "BEGIN";
} else if (sql.startsWith("COMMIT")) {
tag = "COMMIT";
@@ -447,15 +492,23 @@
tag = "ROLLBACK";
} else if (sql.startsWith("SET ")) {
tag = "SET";
- }else {
- trace("Check command tag:", sql);
- tag = "UPDATE " + updateCount;
+ } else if (sql.startsWith("DECLARE CURSOR")) {
+ tag = "DECLARE CURSOR";
+ } else if (sql.startsWith("CLOSE CURSOR")) {
+ tag = "CLOSE CURSOR";
+ } else if (sql.startsWith("FETCH")) {
+ tag = "FETCH "+ updateCount;
+ } else if (sql.startsWith("MOVE")) {
+ tag = "MOVE "+ updateCount;
}
+ else {
+ tag = sql;
+ }
writeString(tag);
sendMessage();
}
- private void sendDataRow(ResultSet rs, List<PgColInfo> cols) throws SQLException, IOException {
+ private void sendDataRow(ResultSet rs, List<PgColInfo> cols, ChannelBuffer buffer) throws SQLException, IOException {
startMessage('D');
writeShort(cols.size());
for (int i = 0; i < cols.size(); i++) {
@@ -467,9 +520,18 @@
write(bytes);
}
}
- sendMessage();
+
+ byte[] buff = outBuffer.toByteArray();
+ int len = buff.length;
+ this.outBuffer = null;
+ this.dataOut = null;
+
+ // now build the wire contents.
+ buffer.writeByte((byte)this.messageType);
+ buffer.writeInt(len+4);
+ buffer.writeBytes(buff);
}
-
+
private byte[] getContent(ResultSet rs, PgColInfo col, int column) throws SQLException, TeiidSQLException, IOException {
byte[] bytes = null;
switch (col.type) {
@@ -612,20 +674,7 @@
write(0);
sendMessage();
}
-
- private void sendNoData() {
- startMessage('n');
- sendMessage();
- }
- private static class PgColInfo {
- String name;
- int reloid;
- short attnum;
- int type;
- int precision;
- }
-
private void sendRowDescription(List<PgColInfo> cols) throws IOException {
startMessage('T');
writeShort(cols.size());
@@ -647,46 +696,6 @@
sendMessage();
}
- private List<PgColInfo> getPgColInfo(ResultSetMetaData meta, Statement stmt)
- throws SQLException {
- int columns = meta.getColumnCount();
- ArrayList<PgColInfo> result = new ArrayList<PgColInfo>(columns);
- for (int i = 1; i < columns + 1; i++) {
- PgColInfo info = new PgColInfo();
- info.name = meta.getColumnName(i).toLowerCase();
- info.type = meta.getColumnType(i);
- info.type = convertType(info.type);
- info.precision = meta.getColumnDisplaySize(i);
- String name = meta.getColumnName(i);
- String table = meta.getTableName(i);
- String schema = meta.getSchemaName(i);
- if (schema != null) {
- PreparedStatement ps = null;
- try {
- ps = stmt.getConnection().prepareStatement("select attrelid, attnum, typoid from matpg_relatt where attname = ? and relname = ? and nspname = ?");
- ps.setString(1, name);
- ps.setString(2, table);
- ps.setString(3, schema);
- ResultSet rs = ps.executeQuery();
- if (rs.next()) {
- info.reloid = rs.getInt(1);
- info.attnum = rs.getShort(2);
- int specificType = rs.getInt(3);
- if (!rs.wasNull()) {
- info.type = specificType;
- }
- }
- } finally {
- if (ps != null) {
- ps.close();
- }
- }
- }
- result.add(info);
- }
- return result;
- }
-
private int getTypeSize(int pgType, int precision) {
switch (pgType) {
case PG_TYPE_VARCHAR:
@@ -728,6 +737,12 @@
startMessage('2');
sendMessage();
}
+
+ @Override
+ public void sendPortalSuspended() {
+ startMessage('s');
+ sendMessage();
+ }
private void sendAuthenticationCleartextPassword() throws IOException {
startMessage('R');
@@ -844,6 +859,10 @@
buffer.writeBytes(buff);
Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());
}
+
+ private void sendContents(ChannelBuffer buffer) {
+ Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());
+ }
private static void trace(String... msg) {
LogManager.logTrace(LogConstants.CTX_ODBC, (Object[])msg);
Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-07-22 16:26:08 UTC (rev 3327)
@@ -92,5 +92,6 @@
ambigious_name=Ambiguous VDB name specified. Only single occurrence of the "." is allowed in the VDB name. Also, when version based vdb name is specified, then a separate "version" connection option is not allowed:{0}.{1}
lo_not_supported=LO functions are not supported
SSLConfiguration.no_anonymous=The anonymous cipher suite TLS_DH_anon_WITH_AES_128_CBC_SHA is not available. Please change the transport to be non-SSL or use non-anonymous SSL.
+execution_failed=Cursor execution failed
PgBackendProtocol.ssl_error=Could not initialize ODBC SSL. non-SSL connections will still be allowed.
\ No newline at end of file
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -26,24 +26,39 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
-import org.jboss.netty.handler.timeout.TimeoutException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.dqp.internal.datamgr.ConnectorManager;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import org.teiid.language.Command;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.FunctionParameter;
-import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.Schema;
+import org.teiid.metadata.RuntimeMetadata;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.function.metadata.FunctionCategoryConstants;
-import org.teiid.query.metadata.TransformationMetadata.Resource;
+import org.teiid.translator.DataNotAvailableException;
+import org.teiid.translator.Execution;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ResultSetExecution;
+import org.teiid.translator.TranslatorException;
@SuppressWarnings("nls")
public class TestLocalConnections {
@@ -62,12 +77,14 @@
static Condition waiting = lock.newCondition();
static Condition wait = lock.newCondition();
+ static Semaphore sourceCounter = new Semaphore(0);
+
public static int blocking() throws InterruptedException {
lock.lock();
try {
waiting.signal();
if (!wait.await(2, TimeUnit.SECONDS)) {
- throw new TimeoutException();
+ throw new RuntimeException();
}
} finally {
lock.unlock();
@@ -77,15 +94,75 @@
static FakeServer server = new FakeServer();
- @BeforeClass public static void oneTimeSetup() {
+ @SuppressWarnings("serial")
+ @BeforeClass public static void oneTimeSetup() throws Exception {
server.setUseCallingThread(true);
- MetadataStore ms = new MetadataStore();
- Schema s = new Schema();
- s.setName("test");
+ server.setConnectorManagerRepository(new ConnectorManagerRepository() {
+ @Override
+ public ConnectorManager getConnectorManager(String connectorName) {
+ return new ConnectorManager(connectorName, connectorName) {
+ @Override
+ protected ExecutionFactory<Object, Object> getExecutionFactory() {
+ return new ExecutionFactory<Object, Object>() {
+ @Override
+ public Execution createExecution(Command command,
+ ExecutionContext executionContext,
+ RuntimeMetadata metadata, Object connection)
+ throws TranslatorException {
+ return new ResultSetExecution() {
+
+ boolean returnedRow = false;
+
+ @Override
+ public void execute() throws TranslatorException {
+ lock.lock();
+ try {
+ sourceCounter.release();
+ if (!wait.await(2, TimeUnit.SECONDS)) {
+ throw new RuntimeException();
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+
+ }
+
+ @Override
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ if (returnedRow) {
+ return null;
+ }
+ returnedRow = true;
+ return new ArrayList<Object>(Collections.singleton(null));
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ protected Object getConnectionFactory()
+ throws TranslatorException {
+ return null;
+ }
+ };
+ }
+ });
FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", new FunctionParameter[0], new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), true, FunctionMethod.Determinism.NONDETERMINISTIC);
- s.addFunction(function);
- ms.addSchema(s);
- server.deployVDB("test", ms, new LinkedHashMap<String, Resource>());
+ HashMap<String, Collection<FunctionMethod>> udfs = new HashMap<String, Collection<FunctionMethod>>();
+ udfs.put("test", Arrays.asList(function));
+ server.deployVDB("test", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb", udfs);
}
@AfterClass public static void oneTimeTearDown() {
@@ -102,6 +179,7 @@
Statement s = c.createStatement();
s.execute("select foo()");
+ s.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -131,9 +209,129 @@
if (t.isAlive()) {
fail();
}
+ s.close();
if (handler.t != null) {
throw handler.t;
}
}
+ @Test public void testUseInDifferentThreads() throws Throwable {
+ Connection c = server.createConnection("jdbc:teiid:test");
+
+ final Statement s = c.createStatement();
+ s.execute("select 1");
+
+ assertFalse(server.dqp.getRequests().isEmpty());
+
+ Thread t = new Thread() {
+ public void run() {
+ try {
+ s.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ SimpleUncaughtExceptionHandler handler = new SimpleUncaughtExceptionHandler();
+ t.setUncaughtExceptionHandler(handler);
+ t.start();
+ t.join(2000);
+ if (t.isAlive()) {
+ fail();
+ }
+
+ assertTrue(server.dqp.getRequests().isEmpty());
+
+ if (handler.t != null) {
+ throw handler.t;
+ }
+ }
+
+ @Test public void testWait() throws Throwable {
+ final Connection c = server.createConnection("jdbc:teiid:test");
+
+ Thread t = new Thread() {
+ public void run() {
+ Statement s;
+ try {
+ s = c.createStatement();
+ assertTrue(s.execute("select part_id from parts"));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ t.start();
+ SimpleUncaughtExceptionHandler handler = new SimpleUncaughtExceptionHandler();
+ t.setUncaughtExceptionHandler(handler);
+
+ sourceCounter.acquire();
+
+ //t should now be waiting also
+
+ lock.lock();
+ try {
+ wait.signal();
+ } finally {
+ lock.unlock();
+ }
+
+ //t should finish
+ t.join();
+
+ if (handler.t != null) {
+ throw handler.t;
+ }
+ }
+
+ @Test public void testWaitMultiple() throws Throwable {
+ final Connection c = server.createConnection("jdbc:teiid:test");
+
+ Thread t = new Thread() {
+ public void run() {
+ Statement s;
+ try {
+ s = c.createStatement();
+ assertTrue(s.execute("select part_id from parts union all select part_id from parts"));
+ ResultSet r = s.getResultSet();
+
+ //wake up the other source thread, should put the requestworkitem into the more work state
+ lock.lock();
+ try {
+ wait.signal();
+ } finally {
+ lock.unlock();
+ }
+ Thread.sleep(1000); //TODO: need a better hook to determine that connector work has finished
+ while (r.next()) {
+ //will hang unless this thread is allowed to resume processing
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ t.start();
+ SimpleUncaughtExceptionHandler handler = new SimpleUncaughtExceptionHandler();
+ t.setUncaughtExceptionHandler(handler);
+
+ sourceCounter.acquire(2);
+
+ //t should now be waiting also
+
+ //wake up 1 source thread
+ lock.lock();
+ try {
+ wait.signal();
+ } finally {
+ lock.unlock();
+ }
+
+ t.join();
+
+ if (handler.t != null) {
+ throw handler.t;
+ }
+ }
+
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -615,6 +615,12 @@
ResultSet rs = dbmd.getTables(null, "SYSTEM", "VIRTUALDATABASES", null); //$NON-NLS-1$ //$NON-NLS-2$
compareResultSet(rs);
}
+
+ @Test
+ public void testGetTables_noTypes() throws Exception {
+ ResultSet rs = dbmd.getTables(null, "SYSTEM", "VIRTUALDATABASES", new String[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertFalse(rs.next());
+ }
@Test
public void testGetTables_specificTableTypes() throws Exception {
Modified: trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-07-22 16:26:08 UTC (rev 3327)
@@ -222,6 +222,12 @@
TestMMDatabaseMetaData.compareResultSet(rs);
}
+ @Test public void testColumnMetadataWithAlias() throws Exception {
+ PreparedStatement stmt = conn.prepareStatement("select ta.attname as x from pg_catalog.pg_attribute ta limit 1");
+ ResultSet rs = stmt.executeQuery();
+ TestMMDatabaseMetaData.compareResultSet(rs);
+ }
+
@Test public void testPreparedError() throws Exception {
PreparedStatement stmt = conn.prepareStatement("select cast(? as integer)");
stmt.setString(1, "a");
@@ -255,6 +261,13 @@
assertEquals("oid", rs.getArray("proargtypes").getBaseTypeName());
}
+ // this does not work as JDBC always sends the queries in prepared form
+ public void testPgDeclareCursor() throws Exception {
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("begin;declare \"foo\" cursor for select * from pg_proc;fetch 10 in \"foo\"; close \"foo\"");
+ rs.next();
+ }
+
@Test public void testPgProcedure() throws Exception {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select has_function_privilege(100, 'foo')");
Property changes on: trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3149-3217
+ /branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java:3149-3217,3281-3325
Added: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected (rev 0)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected 2011-07-22 16:26:08 UTC (rev 3327)
@@ -0,0 +1,6 @@
+varchar
+x
+PART_ID
+Row Count : 1
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
+x 12 java.lang.String x varchar 2147483647 0 0 false true false false 1 false true false true
Modified: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected 2011-07-22 16:26:08 UTC (rev 3327)
@@ -1,10 +1,10 @@
varchar int2 varchar varchar varchar
-name attnum tablename schemaname tablename
+attname attnum relname nspname relname
oid 1 pg_attribute pg_catalog pg_attribute
Row Count : 1
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
-name 12 java.lang.String name varchar 2147483647 0 0 false true false false 0 false true false true
+attname 12 java.lang.String attname varchar 2147483647 0 0 false true false false 0 false true false true
attnum 5 java.lang.Integer attnum int2 6 5 0 false false false false 2 false true true true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
-schemaname 12 java.lang.String schemaname varchar 2147483647 0 0 false true false false 1 false true false true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
+nspname 12 java.lang.String nspname varchar 2147483647 0 0 false true false false 1 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
Property changes on: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected:3281-3325
Modified: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected 2011-07-22 15:32:56 UTC (rev 3326)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected 2011-07-22 16:26:08 UTC (rev 3327)
@@ -1,10 +1,10 @@
varchar int2 varchar varchar varchar
-name attnum tablename schemaname tablename
+attname attnum relname nspname relname
oid 1 pg_attribute pg_catalog pg_attribute
Row Count : 1
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
-name 12 java.lang.String name varchar 2147483647 0 0 false true false false 0 false true false true
+attname 12 java.lang.String attname varchar 2147483647 0 0 false true false false 0 false true false true
attnum 5 java.lang.Integer attnum int2 6 5 0 false false false false 2 false true true true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
-schemaname 12 java.lang.String schemaname varchar 2147483647 0 0 false true false false 1 false true false true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
+nspname 12 java.lang.String nspname varchar 2147483647 0 0 false true false false 1 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
Property changes on: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected:3281-3325
14 years, 5 months
teiid SVN: r3326 - in branches/7.4.x: client/src/main/java/org/teiid/jdbc and 4 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-22 11:32:56 -0400 (Fri, 22 Jul 2011)
New Revision: 3326
Added:
branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected
Modified:
branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
Log:
TEIID-1651 hopefully the final touches to jdbc/odbc metadata related to column name/label
Modified: branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/build/kits/jboss-container/teiid-releasenotes.html 2011-07-22 15:32:56 UTC (rev 3326)
@@ -75,6 +75,7 @@
<h4>from 7.4</h4>
<ul>
<li>ColumnReference.getName will always return just the element name. Previously it inconsistently returned the qualified and unqualified form depending upon where the ColumnReference appeared.
+ <li>As per JDBC4, ResultSetMetadata.getColumnName will return the unaliased column name if available rather than return the alias. Set useJDBC4ColumnNameAndLabelSemantics to false to use the alias name as the column name.
</ul>
<h4>from 7.3</h4>
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/ResultSetMetaDataImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
@@ -35,11 +35,13 @@
private MetadataProvider provider;
- private boolean useJDBC4ColumnNameAndLabelSemantics = false;
+ private boolean useJDBC4ColumnNameAndLabelSemantics = true;
public ResultSetMetaDataImpl(MetadataProvider provider, String supportBackwardsCompatibility) {
this.provider = provider;
- this.useJDBC4ColumnNameAndLabelSemantics = (supportBackwardsCompatibility != null && supportBackwardsCompatibility.equalsIgnoreCase("false") ? false : true);
+ if (supportBackwardsCompatibility != null) {
+ this.useJDBC4ColumnNameAndLabelSemantics = Boolean.parseBoolean(supportBackwardsCompatibility);
+ }
}
/**
Modified: branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
===================================================================
--- branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2011-07-22 15:32:56 UTC (rev 3326)
@@ -250,10 +250,9 @@
<code>boolean</code>
</entry>
<entry>
- <para>A change was made in JDBC4 so that when an 'Alias' is used it will
- now be returned as the label. Prior to this, it was returned as
- the name. Setting this property to false will enable
- backwards compatibility when JDBC3 and older support is still required.
+ <para>A change was made in JDBC4 to return unaliased column names as the ResultSetMetadata column name.
+ Prior to this, if a column alias were used it was returned as the column name. Setting this property to false will enable
+ backwards compatibility when JDBC3 and older support is still required. Defaults to true.
</para>
</entry>
</row>
Modified: branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml
===================================================================
--- branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-extensions.xml 2011-07-22 15:32:56 UTC (rev 3326)
@@ -175,11 +175,7 @@
<code>JDBC4COLUMNNAMEANDLABELSEMANTICS / useJDBC4ColumnNameAndLabelSemantics</code>
</entry>
<entry>
- <para>A change was made in JDBC4 so that when an 'Alias' is used it will.
- now be returned as the label. Prior to this, it was returned as
- the name. Setting this property to false will enable
- backwards compatibility when JDBC3 and older support is still required.
- </para>
+ <para>Same as the connection property.</para>
</entry>
</row>
</tbody>
Modified: branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-07-22 15:32:56 UTC (rev 3326)
@@ -966,7 +966,7 @@
final ArrayList<PgColInfo> result = new ArrayList<PgColInfo>(columns);
for (int i = 1; i < columns + 1; i++) {
final PgColInfo info = new PgColInfo();
- info.name = meta.getColumnName(i).toLowerCase();
+ info.name = meta.getColumnLabel(i).toLowerCase();
info.type = meta.getColumnType(i);
info.type = convertType(info.type);
info.precision = meta.getColumnDisplaySize(i);
Modified: branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
--- branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2011-07-22 15:32:56 UTC (rev 3326)
@@ -222,6 +222,12 @@
TestMMDatabaseMetaData.compareResultSet(rs);
}
+ @Test public void testColumnMetadataWithAlias() throws Exception {
+ PreparedStatement stmt = conn.prepareStatement("select ta.attname as x from pg_catalog.pg_attribute ta limit 1");
+ ResultSet rs = stmt.executeQuery();
+ TestMMDatabaseMetaData.compareResultSet(rs);
+ }
+
@Test public void testPreparedError() throws Exception {
PreparedStatement stmt = conn.prepareStatement("select cast(? as integer)");
stmt.setString(1, "a");
Added: branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected
===================================================================
--- branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected (rev 0)
+++ branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testColumnMetadataWithAlias.expected 2011-07-22 15:32:56 UTC (rev 3326)
@@ -0,0 +1,6 @@
+varchar
+x
+PART_ID
+Row Count : 1
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
+x 12 java.lang.String x varchar 2147483647 0 0 false true false false 1 false true false true
Modified: branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected
===================================================================
--- branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPk.expected 2011-07-22 15:32:56 UTC (rev 3326)
@@ -1,10 +1,10 @@
varchar int2 varchar varchar varchar
-name attnum tablename schemaname tablename
+attname attnum relname nspname relname
oid 1 pg_attribute pg_catalog pg_attribute
Row Count : 1
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
-name 12 java.lang.String name varchar 2147483647 0 0 false true false false 0 false true false true
+attname 12 java.lang.String attname varchar 2147483647 0 0 false true false false 0 false true false true
attnum 5 java.lang.Integer attnum int2 6 5 0 false false false false 2 false true true true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
-schemaname 12 java.lang.String schemaname varchar 2147483647 0 0 false true false false 1 false true false true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
+nspname 12 java.lang.String nspname varchar 2147483647 0 0 false true false false 1 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
Modified: branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected
===================================================================
--- branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected 2011-07-22 10:33:31 UTC (rev 3325)
+++ branches/7.4.x/test-integration/common/src/test/resources/TestODBCSocketTransport/testPkPrepared.expected 2011-07-22 15:32:56 UTC (rev 3326)
@@ -1,10 +1,10 @@
varchar int2 varchar varchar varchar
-name attnum tablename schemaname tablename
+attname attnum relname nspname relname
oid 1 pg_attribute pg_catalog pg_attribute
Row Count : 1
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
-name 12 java.lang.String name varchar 2147483647 0 0 false true false false 0 false true false true
+attname 12 java.lang.String attname varchar 2147483647 0 0 false true false false 0 false true false true
attnum 5 java.lang.Integer attnum int2 6 5 0 false false false false 2 false true true true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
-schemaname 12 java.lang.String schemaname varchar 2147483647 0 0 false true false false 1 false true false true
-tablename 12 java.lang.String tablename varchar 2147483647 0 0 false true false false 0 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
+nspname 12 java.lang.String nspname varchar 2147483647 0 0 false true false false 1 false true false true
+relname 12 java.lang.String relname varchar 2147483647 0 0 false true false false 0 false true false true
14 years, 5 months
teiid SVN: r3325 - in trunk/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-22 06:33:31 -0400 (Fri, 22 Jul 2011)
New Revision: 3325
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
Log:
TEIID-1665 optimizing grouping of all constants
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java 2011-07-22 10:29:03 UTC (rev 3324)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleAssignOutputElements.java 2011-07-22 10:33:31 UTC (rev 3325)
@@ -42,7 +42,9 @@
import org.teiid.query.optimizer.relational.RuleStack;
import org.teiid.query.optimizer.relational.plantree.NodeConstants;
import org.teiid.query.optimizer.relational.plantree.NodeEditor;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants.Info;
import org.teiid.query.processor.relational.RelationalNode;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
@@ -51,6 +53,7 @@
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
@@ -218,6 +221,30 @@
}
List<SingleElementSymbol> requiredInput = collectRequiredInputSymbols(root);
+ //targeted optimization for unnecessary aggregation
+ if (root.getType() == NodeConstants.Types.GROUP && root.hasBooleanProperty(Info.IS_OPTIONAL) && NodeEditor.findParent(root, NodeConstants.Types.ACCESS) == null) {
+ PlanNode old = root;
+ PlanNode next = root.getFirstChild();
+ NodeEditor.removeChildNode(root.getParent(), root);
+
+ if (old.hasCollectionProperty(Info.GROUP_COLS)) {
+ SymbolMap symbolMap = (SymbolMap) old.getProperty(NodeConstants.Info.SYMBOL_MAP);
+ FrameUtil.convertFrame(next.getParent(), symbolMap.asMap().keySet().iterator().next().getGroupSymbol(), null, symbolMap.asMap(), metadata);
+ PlanNode limit = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT);
+ limit.setProperty(Info.MAX_TUPLE_LIMIT, new Constant(1));
+ PlanNode parent = next.getParent();
+ while (parent.getParent() != null && parent.getParent().getType() != NodeConstants.Types.SOURCE) {
+ parent = parent.getParent();
+ }
+ if (!rules.contains(RuleConstants.PUSH_LIMIT)) {
+ rules.push(RuleConstants.PUSH_LIMIT);
+ }
+ parent.getFirstChild().addAsParent(limit);
+ execute(parent, metadata, capFinder, rules, analysisRecord, context);
+ return;
+ }
+ root = next;
+ }
// Call children recursively
if(root.getChildCount() == 1) {
@@ -482,7 +509,7 @@
ElementCollectorVisitor.getElements(expression, requiredSymbols);
}
}
-
+ boolean hasAggregate = false;
SymbolMap symbolMap = (SymbolMap) node.getProperty(NodeConstants.Info.SYMBOL_MAP);
// Take credit for creating any aggregates that are needed above
@@ -491,7 +518,7 @@
Expression ex = symbolMap.getMappedExpression((ElementSymbol) outputSymbol);
if(ex instanceof AggregateSymbol) {
AggregateSymbol agg = (AggregateSymbol)ex;
-
+ hasAggregate = true;
Expression aggExpr = agg.getExpression();
if(aggExpr != null) {
ElementCollectorVisitor.getElements(aggExpr, requiredSymbols);
@@ -506,7 +533,9 @@
}
}
}
-
+ if (requiredSymbols.isEmpty() && !hasAggregate) {
+ node.setProperty(Info.IS_OPTIONAL, true);
+ }
break;
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-07-22 10:29:03 UTC (rev 3324)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-07-22 10:33:31 UTC (rev 3325)
@@ -6607,6 +6607,34 @@
helpPlan("select count(*) from agg3", metadata, new String[] {"SELECT COUNT(*) FROM (SELECT COUNT(*) AS c_0 FROM BQT1.SmallA AS g_0) AS v_0"}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
}
+
+ @Test public void testMergeGroupBy1() throws Exception {
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setFunctionSupport("+", true); //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT a, b FROM (select 1 as a, 2 as b from pm1.g1) as x group by a, b", //$NON-NLS-1$
+ RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps),
+ new String[] {
+ "SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 1"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
public static final boolean DEBUG = false;
}
14 years, 5 months
teiid SVN: r3324 - in branches/7.4.x/engine/src: test/java/org/teiid/query/rewriter and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-22 06:29:03 -0400 (Fri, 22 Jul 2011)
New Revision: 3324
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-1645 re-enabling agg rewrite optimization
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-21 19:28:44 UTC (rev 3323)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-22 10:29:03 UTC (rev 3324)
@@ -240,6 +240,7 @@
* @throws QueryValidatorException
*/
private Command rewriteCommand(Command command, boolean removeOrderBy) throws TeiidComponentException, TeiidProcessingException{
+ boolean oldRewriteAggs = rewriteAggs;
QueryMetadataInterface oldMetadata = metadata;
CreateUpdateProcedureCommand oldProcCommand = procCommand;
@@ -299,6 +300,7 @@
break;
}
+ this.rewriteAggs = oldRewriteAggs;
this.metadata = oldMetadata;
this.procCommand = oldProcCommand;
return command;
@@ -764,6 +766,7 @@
*/
private Query rewriteGroupBy(Query query) throws TeiidComponentException, TeiidProcessingException{
if (query.getGroupBy() == null) {
+ rewriteAggs = false;
return query;
}
if (isDistinctWithGroupBy(query)) {
@@ -1664,6 +1667,7 @@
private BigDecimal BIG_DECIMAL_ZERO = new BigDecimal("0"); //$NON-NLS-1$
private Short SHORT_ZERO = new Short((short)0);
private Byte BYTE_ZERO = new Byte((byte)0);
+ private boolean rewriteAggs = true;
/**
* @param criteria
@@ -2358,6 +2362,9 @@
expression.setAggregateFunction(Type.MAX);
}
}
+ if (rewriteAggs && expression.getExpression() != null && EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
+ return expression.getExpression();
+ }
return expression;
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-21 19:28:44 UTC (rev 3323)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-22 10:29:03 UTC (rev 3324)
@@ -2460,4 +2460,10 @@
@Test public void testRewriteNestedConvert2() throws Exception {
helpTestRewriteExpression("cast(cast(pm1.g1.e3 as string) as clob)", "convert(convert(pm1.g1.e3, string), clob)", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ @Test public void testRewriteConstantAgg() throws Exception {
+ helpTestRewriteCommand("select max(1) from pm1.g1 group by e1", "SELECT 1 FROM pm1.g1 GROUP BY e1");
+ }
+
+
}
14 years, 5 months
teiid SVN: r3323 - in trunk: documentation/developer-guide/src/main/docbook/en-US/content and 22 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-21 15:28:44 -0400 (Thu, 21 Jul 2011)
New Revision: 3323
Removed:
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllInGroupSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllSymbol.java
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Select.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/MultipleElementSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/SelectSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/SingleElementSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/AggregateSymbolCollectorVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ElementCollectorVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java
trunk/engine/src/test/java/org/teiid/query/parser/TestLimitParsing.java
trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1667 refining agg and window function validation and also continuing to refine the language object model to move beyond the symbol base class
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -725,8 +725,6 @@
/**
* <p>Support indicates that the connector supports functions in GROUP BY, such as:
* <code>SELECT dayofmonth(theDate), COUNT(*) FROM table GROUP BY dayofmonth(theDate)</code></p>
- *
- * <br>NOT CURRENTLY USED - group by expressions create an inline view for pushdown
* @since 5.0
*/
public boolean supportsFunctionsInGroupBy() {
Modified: trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
===================================================================
--- trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2011-07-21 19:28:44 UTC (rev 3323)
@@ -1229,7 +1229,7 @@
<para>GroupBy</para>
</entry>
<entry>
- <para>Not currently used - non-element expressions in the group by create an inline view.</para>
+ <para>Translator can support non-column reference grouping expressions.</para>
</entry>
</row>
<row>
@@ -1287,6 +1287,28 @@
<para>Translator supports the WITH clause.</para>
</entry>
</row>
+ <row>
+ <entry>
+ <para>ElementaryOlapOperations</para>
+ </entry>
+ <entry>
+ <para/>
+ </entry>
+ <entry>
+ <para>Translator supports window functions and analytic functions RANK, DENSE_RANK, and ROW_NUMBER.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <para>AdvancedOlapOperations</para>
+ </entry>
+ <entry>
+ <para/>
+ </entry>
+ <entry>
+ <para>Translator supports aggregate conditions.</para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -180,12 +180,12 @@
this.metadata = tempFacade;
}
- List projectedSymbols = originalCommand.getProjectedSymbols();
+ List<SingleElementSymbol> projectedSymbols = originalCommand.getProjectedSymbols();
columnMetadata = new Map[projectedSymbols.size()];
- Iterator symbolIter = projectedSymbols.iterator();
+ Iterator<SingleElementSymbol> symbolIter = projectedSymbols.iterator();
for(int i=0; symbolIter.hasNext(); i++) {
- SingleElementSymbol symbol = (SingleElementSymbol) symbolIter.next();
+ SingleElementSymbol symbol = symbolIter.next();
String shortColumnName = SingleElementSymbol.getShortName(symbol.getOutputName());
if(symbol instanceof AliasSymbol) {
symbol = ((AliasSymbol)symbol).getSymbol();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -112,7 +112,7 @@
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -744,7 +744,7 @@
Collection<AggregateSymbol> aggs = AggregateSymbolCollectorVisitor.getAggregates(query.getSelect(), true);
boolean hasGrouping = !aggs.isEmpty();
if (query.getHaving() != null) {
- AggregateSymbolCollectorVisitor.getAggregates(query.getHaving(), aggs, null);
+ aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getHaving(), true));
hasGrouping = true;
}
if (query.getGroupBy() != null) {
@@ -1224,7 +1224,7 @@
}else{
this.context.accessedPlanningObject(matMetadataId);
qnode = new QueryNode(null);
- Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new AllSymbol()), isImplicitGlobal);
+ Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new MultipleElementSymbol()), isImplicitGlobal);
query.setCacheHint(hint);
qnode.setCommand(query);
cacheString = "matview"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseJoinStrategy.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseJoinStrategy.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -24,11 +24,9 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
@@ -169,22 +167,14 @@
}
}
- private static AtomicInteger EXPRESSION_INDEX = new AtomicInteger(0);
-
public static List<SingleElementSymbol> createExpressionSymbols(List<? extends Expression> expressions) {
- HashMap<Expression, ExpressionSymbol> uniqueExpressions = new HashMap<Expression, ExpressionSymbol>();
List<SingleElementSymbol> result = new ArrayList<SingleElementSymbol>();
for (Expression expression : expressions) {
if (expression instanceof SingleElementSymbol) {
result.add((SingleElementSymbol)expression);
continue;
}
- ExpressionSymbol expressionSymbol = uniqueExpressions.get(expression);
- if (expressionSymbol == null) {
- expressionSymbol = new ExpressionSymbol("$" + EXPRESSION_INDEX.getAndIncrement(), expression); //$NON-NLS-1$
- uniqueExpressions.put(expression, expressionSymbol);
- }
- result.add(expressionSymbol);
+ result.add(new ExpressionSymbol("expr", expression)); //$NON-NLS-1$
}
return result;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -68,10 +68,10 @@
import org.teiid.query.sql.lang.SubquerySetCriteria;
import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -455,7 +455,7 @@
private boolean isSimpleJoin(Query query) {
if (query.getFrom() != null) {
- for (FromClause clause : (List<FromClause>)query.getFrom().getClauses()) {
+ for (FromClause clause : query.getFrom().getClauses()) {
if (RuleCollapseSource.hasOuterJoins(clause)) {
return false;
}
@@ -479,7 +479,7 @@
plannedResult.query.setLimit(null);
List<GroupSymbol> rightGroups = plannedResult.query.getFrom().getGroups();
- Set<SingleElementSymbol> requiredExpressions = new LinkedHashSet<SingleElementSymbol>();
+ Set<Expression> requiredExpressions = new LinkedHashSet<Expression>();
final SymbolMap refs = plannedResult.query.getCorrelatedReferences();
boolean addGroupBy = false;
if (refs != null) {
@@ -494,7 +494,7 @@
return false;
}
if (plannedResult.query.getGroupBy() == null) {
- processCriteria(leftGroups, plannedResult, rightGroups, requiredExpressions, refs, where, true);
+ processCriteria(leftGroups, plannedResult, rightGroups, requiredExpressions, refs, where, null, true);
if (hasAggregates) {
if (!plannedResult.nonEquiJoinCriteria.isEmpty()) {
return false;
@@ -502,7 +502,7 @@
addGroupBy = true;
}
}
- processCriteria(leftGroups, plannedResult, rightGroups, requiredExpressions, refs, having, false);
+ processCriteria(leftGroups, plannedResult, rightGroups, requiredExpressions, refs, having, plannedResult.query.getGroupBy(), false);
}
if (plannedResult.additionalCritieria != null) {
@@ -525,29 +525,29 @@
}
if (addGroupBy) {
- LinkedHashSet<SingleElementSymbol> groupingSymbols = new LinkedHashSet<SingleElementSymbol>();
- ArrayList<SingleElementSymbol> aggs = new ArrayList<SingleElementSymbol>();
+ LinkedHashSet<Expression> groupingSymbols = new LinkedHashSet<Expression>();
for (Expression expr : (List<Expression>)plannedResult.rightExpressions) {
- AggregateSymbolCollectorVisitor.getAggregates(expr, aggs, groupingSymbols);
+ AggregateSymbolCollectorVisitor.getAggregates(expr, null, groupingSymbols, null, null, null);
}
if (!groupingSymbols.isEmpty()) {
- plannedResult.query.setGroupBy((GroupBy) new GroupBy(new ArrayList<SingleElementSymbol>(groupingSymbols)).clone());
+ plannedResult.query.setGroupBy((GroupBy) new GroupBy(new ArrayList<Expression>(groupingSymbols)).clone());
}
}
- HashSet<SingleElementSymbol> projectedSymbols = new HashSet<SingleElementSymbol>();
+ HashSet<Expression> projectedSymbols = new HashSet<Expression>();
for (SingleElementSymbol ses : plannedResult.query.getProjectedSymbols()) {
- if (ses instanceof AliasSymbol) {
- ses = ((AliasSymbol)ses).getSymbol();
- }
- projectedSymbols.add(ses);
+ projectedSymbols.add(SymbolMap.getExpression(ses));
}
- for (SingleElementSymbol ses : requiredExpressions) {
+ for (Expression ses : requiredExpressions) {
if (projectedSymbols.add(ses)) {
- plannedResult.query.getSelect().addSymbol((SingleElementSymbol) ses.clone());
+ if (ses instanceof SingleElementSymbol) {
+ plannedResult.query.getSelect().addSymbol((SingleElementSymbol)ses);
+ } else {
+ plannedResult.query.getSelect().addSymbol(new ExpressionSymbol("expr", (Expression) ses.clone())); //$NON-NLS-1$
+ }
}
}
for (SingleElementSymbol ses : (List<SingleElementSymbol>)plannedResult.rightExpressions) {
- if (projectedSymbols.add(ses)) {
+ if (projectedSymbols.add(SymbolMap.getExpression(ses))) {
plannedResult.query.getSelect().addSymbol((SingleElementSymbol)ses.clone());
}
}
@@ -556,8 +556,8 @@
private void processCriteria(Collection<GroupSymbol> leftGroups,
PlannedResult plannedResult, List<GroupSymbol> rightGroups,
- Set<SingleElementSymbol> requiredExpressions, final SymbolMap refs,
- Criteria joinCriteria, boolean where) {
+ Set<Expression> requiredExpressions, final SymbolMap refs,
+ Criteria joinCriteria, GroupBy groupBy, boolean where) {
if (joinCriteria == null) {
return;
}
@@ -565,9 +565,8 @@
for (Iterator<Criteria> critIter = crits.iterator(); critIter.hasNext();) {
Criteria conjunct = critIter.next();
- List<SingleElementSymbol> aggregates = new LinkedList<SingleElementSymbol>();
- List<SingleElementSymbol> elements = new LinkedList<SingleElementSymbol>();
- AggregateSymbolCollectorVisitor.getAggregates(conjunct, aggregates, elements);
+ List<Expression> additionalRequired = new LinkedList<Expression>();
+ AggregateSymbolCollectorVisitor.getAggregates(conjunct, additionalRequired, additionalRequired, additionalRequired, null, groupBy!=null?groupBy.getSymbols():null);
ReferenceReplacementVisitor emv = new ReferenceReplacementVisitor(refs);
DeepPostOrderNavigator.doVisit(conjunct, emv);
if (!emv.replacedAny) {
@@ -579,8 +578,7 @@
plannedResult.query.setHaving(Criteria.combineCriteria(plannedResult.query.getHaving(), conjunct));
}
} else {
- requiredExpressions.addAll(aggregates);
- requiredExpressions.addAll(elements);
+ requiredExpressions.addAll(additionalRequired);
}
}
RuleChooseJoinStrategy.separateCriteria(leftGroups, rightGroups, plannedResult.leftExpressions, plannedResult.rightExpressions, crits, plannedResult.nonEquiJoinCriteria);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -277,7 +277,7 @@
if (ex instanceof AggregateSymbol) {
compositeAggs.add((AggregateSymbol) ex);
} else {
- AggregateSymbolCollectorVisitor.getAggregates(ex, compositeAggs, null);
+ compositeAggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(ex, false));
hasExpressionMapping = true;
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -51,10 +51,10 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
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.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
@@ -135,7 +135,7 @@
static Query wrapQuery(FromClause fromClause, String groupName) {
Select select = new Select();
- select.addSymbol(new AllInGroupSymbol(groupName + ".*")); //$NON-NLS-1$
+ select.addSymbol(new MultipleElementSymbol(groupName));
Query query = new Query();
query.setSelect(select);
From from = new From();
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -53,9 +53,9 @@
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
@@ -247,7 +247,7 @@
SelectSymbol firstSymbol = select.getSymbol(0);
// 0. mark the nodes to be excluded
- if(firstSymbol instanceof AllSymbol) {
+ if(firstSymbol instanceof MultipleElementSymbol && ((MultipleElementSymbol)firstSymbol).getGroup() == null) {
return doc;
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -76,12 +76,11 @@
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.navigator.PostOrderNavigator;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SingleElementSymbol;
@@ -89,8 +88,6 @@
public class SimpleQueryResolver implements CommandResolver {
- private static final String ALL_IN_GROUP_SUFFIX = ".*"; //$NON-NLS-1$
-
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
*/
@@ -107,14 +104,14 @@
ResolverVisitor visitor = (ResolverVisitor)qrv.getVisitor();
visitor.throwException(true);
} catch (TeiidRuntimeException e) {
- if (e.getChild() instanceof QueryMetadataException) {
- throw (QueryMetadataException)e.getChild();
+ if (e.getCause() instanceof QueryMetadataException) {
+ throw (QueryMetadataException)e.getCause();
}
- if (e.getChild() instanceof QueryResolverException) {
- throw (QueryResolverException)e.getChild();
+ if (e.getCause() instanceof QueryResolverException) {
+ throw (QueryResolverException)e.getCause();
}
- if (e.getChild() instanceof TeiidComponentException) {
- throw (TeiidComponentException)e.getChild();
+ if (e.getCause() instanceof TeiidComponentException) {
+ throw (TeiidComponentException)e.getCause();
}
throw e;
}
@@ -185,18 +182,18 @@
}
}
- private static GroupSymbol resolveAllInGroup(AllInGroupSymbol allInGroupSymbol, Set<GroupSymbol> groups, QueryMetadataInterface metadata) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
- String name = allInGroupSymbol.getName();
- int index = name.lastIndexOf(ALL_IN_GROUP_SUFFIX);
- String groupAlias = name.substring(0, index);
- List<GroupSymbol> groupSymbols = ResolverUtil.findMatchingGroups(groupAlias.toUpperCase(), groups, metadata);
+ private static GroupSymbol resolveAllInGroup(MultipleElementSymbol allInGroupSymbol, Set<GroupSymbol> groups, QueryMetadataInterface metadata) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
+ String groupAlias = allInGroupSymbol.getGroup().getCanonicalName();
+ List<GroupSymbol> groupSymbols = ResolverUtil.findMatchingGroups(groupAlias, groups, metadata);
if(groupSymbols.isEmpty() || groupSymbols.size() > 1) {
String msg = QueryPlugin.Util.getString(groupSymbols.isEmpty()?"ERR.015.008.0047":"SimpleQueryResolver.ambiguous_all_in_group", allInGroupSymbol); //$NON-NLS-1$ //$NON-NLS-2$
QueryResolverException qre = new QueryResolverException(msg);
qre.addUnresolvedSymbol(new UnresolvedSymbolDescription(allInGroupSymbol.toString(), msg));
throw qre;
}
-
+ GroupSymbol gs = allInGroupSymbol.getGroup();
+ allInGroupSymbol.setGroup(groupSymbols.get(0).clone());
+ allInGroupSymbol.getGroup().setOutputName(gs.getOutputName());
return groupSymbols.get(0);
}
@@ -260,14 +257,19 @@
}
}
- public void visit(AllSymbol obj) {
+ public void visit(MultipleElementSymbol obj) {
+ // Determine group that this symbol is for
try {
List<ElementSymbol> elementSymbols = new ArrayList<ElementSymbol>();
- for (GroupSymbol group : currentGroups) {
+ Collection<GroupSymbol> groups = currentGroups;
+ if (obj.getGroup() != null) {
+ groups = Arrays.asList(resolveAllInGroup(obj, currentGroups, metadata));
+ }
+ for (GroupSymbol group : groups) {
elementSymbols.addAll(resolveSelectableElements(group));
}
obj.setElementSymbols(elementSymbols);
- } catch (TeiidComponentException err) {
+ } catch (TeiidException err) {
throw new TeiidRuntimeException(err);
}
}
@@ -289,19 +291,6 @@
return result;
}
- public void visit(AllInGroupSymbol obj) {
- // Determine group that this symbol is for
- try {
- GroupSymbol group = resolveAllInGroup(obj, currentGroups, metadata);
-
- List<ElementSymbol> elements = resolveSelectableElements(group);
-
- obj.setElementSymbols(elements);
- } catch (TeiidException err) {
- throw new TeiidRuntimeException(err);
- }
- }
-
public void visit(ScalarSubquery obj) {
resolveSubQuery(obj, this.currentGroups);
}
@@ -471,7 +460,7 @@
from.addClause(new SubqueryFromClause("X", storedProcedureCommand)); //$NON-NLS-1$
procQuery.setFrom(from);
Select select = new Select();
- select.addSymbol(new AllInGroupSymbol("X.*")); //$NON-NLS-1$
+ select.addSymbol(new MultipleElementSymbol("X")); //$NON-NLS-1$
procQuery.setSelect(select);
List<String> accessPatternElementNames = new LinkedList<String>();
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/XMLQueryResolver.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -58,11 +58,10 @@
import org.teiid.query.sql.lang.Select;
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
@@ -337,47 +336,38 @@
// There are other cases of "xml", such as, element name = "xml",
// but those are ok because those will be resolved later as normal elements
- String symbolName = ss.getName();
+ ElementSymbol es = (ElementSymbol)ss;
+ String symbolName = es.getName();
if(!subquery && (symbolName.equalsIgnoreCase("xml") || symbolName.equalsIgnoreCase(group.getName() + ".xml"))) { //$NON-NLS-1$ //$NON-NLS-2$
if(elements.size() != 1) {
throw new QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.xml_only_valid_alone")); //$NON-NLS-1$
}
select.clearSymbols();
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
all.setElementSymbols(validElements.values());
select.addSymbol(all);
query.setSelect(select);
return;
}
// normal elements
- resolveElement((ElementSymbol)ss, validElements, externalGroups, metadata);
- } else if (ss instanceof AllInGroupSymbol) {
+ resolveElement(es, validElements, externalGroups, metadata);
+ } else if (ss instanceof MultipleElementSymbol) {
// Resolve the element with "*" case. such as "A.*"
// by stripping off the ".*" part,
- String symbolName = ss.getName();
- int index = symbolName.indexOf("*"); //$NON-NLS-1$
- String elementPart = symbolName.substring(0, index-1);
+ MultipleElementSymbol all = (MultipleElementSymbol)ss;
// Check for case where we have model.doc.*
- if(elementPart.equalsIgnoreCase(group.getName())) {
- select.clearSymbols();
- AllSymbol all = new AllSymbol();
+ if(all.getGroup() == null || all.getGroup().getName().equalsIgnoreCase(group.getName())) {
all.setElementSymbols(validElements.values());
- select.addSymbol(all);
- query.setSelect(select);
- } else {
- // resovlve the node which is specified
- ElementSymbol elementSymbol = new ElementSymbol(elementPart);
- resolveElement(elementSymbol, validElements, externalGroups, metadata);
-
- // now find all the elements under this node and set as elements.
- List<ElementSymbol> elementsInNode = getElementsUnderNode(elementSymbol.getMetadataID(), validElements.values(), metadata);
- ((AllInGroupSymbol)ss).setElementSymbols(elementsInNode);
+ return;
}
- } else if (ss instanceof AllSymbol) {
- AllSymbol all = (AllSymbol)ss;
- all.setElementSymbols(validElements.values());
- return;
+ // resovlve the node which is specified
+ ElementSymbol elementSymbol = new ElementSymbol(all.getGroup().getName());
+ resolveElement(elementSymbol, validElements, externalGroups, metadata);
+
+ // now find all the elements under this node and set as elements.
+ List<ElementSymbol> elementsInNode = getElementsUnderNode(elementSymbol.getMetadataID(), validElements.values(), metadata);
+ all.setElementSymbols(elementsInNode);
} else if (ss instanceof ExpressionSymbol) {
throw new QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.no_expressions_in_select")); //$NON-NLS-1$
} else if (ss instanceof AliasSymbol) {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -83,8 +83,6 @@
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.DerivedColumn;
@@ -92,6 +90,7 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -172,8 +171,7 @@
// Visitor methods for symbol objects
public void visit(AggregateSymbol obj) {}
public void visit(AliasSymbol obj) {}
- public void visit(AllInGroupSymbol obj) {}
- public void visit(AllSymbol obj) {}
+ public void visit(MultipleElementSymbol obj) {}
public void visit(Constant obj) {}
public void visit(ElementSymbol obj) {}
public void visit(ExpressionSymbol obj) {}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Select.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Select.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Select.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -30,7 +30,6 @@
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.SelectSymbol;
@@ -85,7 +84,7 @@
* @return True if Select * is used
*/
public boolean isStar() {
- return (symbols.size() == 1 && symbols.get(0) instanceof AllSymbol);
+ return (symbols.size() == 1 && symbols.get(0) instanceof MultipleElementSymbol && ((MultipleElementSymbol)symbols.get(0)).getGroup() == null);
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -87,8 +87,6 @@
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.DerivedColumn;
@@ -97,6 +95,7 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -154,14 +153,10 @@
visitNode(obj.getSymbol());
postVisitVisitor(obj);
}
- public void visit(AllInGroupSymbol obj) {
+ public void visit(MultipleElementSymbol obj) {
preVisitVisitor(obj);
postVisitVisitor(obj);
}
- public void visit(AllSymbol obj) {
- preVisitVisitor(obj);
- postVisitVisitor(obj);
- }
public void visit(AssignmentStatement obj) {
preVisitVisitor(obj);
visitNode(obj.getVariable());
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -72,6 +72,7 @@
private boolean distinct;
private OrderBy orderBy;
private Expression condition;
+ private boolean isWindowed;
private static final Class<Integer> COUNT_TYPE = DataTypeManager.DefaultDataClasses.INTEGER;
private static final Map<Class<?>, Class<?>> SUM_TYPES;
@@ -224,6 +225,7 @@
if (condition != null) {
copy.setCondition((Expression) condition.clone());
}
+ copy.isWindowed = this.isWindowed;
return copy;
}
@@ -247,6 +249,7 @@
return this.aggregate.equals(other.aggregate)
&& this.distinct == other.distinct
+ && this.isWindowed == other.isWindowed
&& EquivalenceUtil.areEqual(this.getExpression(), other.getExpression())
&& EquivalenceUtil.areEqual(this.condition, other.condition)
&& EquivalenceUtil.areEqual(this.getOrderBy(), other.getOrderBy());
@@ -302,5 +305,13 @@
}
return true;
}
+
+ public boolean isWindowed() {
+ return isWindowed;
+ }
+
+ public void setWindowed(boolean isWindowed) {
+ this.isWindowed = isWindowed;
+ }
}
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllInGroupSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllInGroupSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllInGroupSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -1,72 +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.query.sql.symbol;
-
-import java.util.List;
-
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.LanguageVisitor;
-
-/**
- * <p>This is a subclass of Symbol representing <group>.*, which contains all of
- * the elements from a single group in the query. The name of this symbol is "group.*",
- * when resolved it contains a single Group Symbols and a set of Element Symbols</p>
- */
-public class AllInGroupSymbol extends MultipleElementSymbol {
-
- /**
- * Constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected AllInGroupSymbol(String name, String canonicalName) {
- super(name, canonicalName);
- }
-
- /**
- * Default constructor
- */
- public AllInGroupSymbol(String name) {
- super(name);
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Return a deep copy of this object
- * @return Deep copy of this object
- */
- public Object clone() {
- AllInGroupSymbol copy = new AllInGroupSymbol(getName(), getCanonical());
-
- List<ElementSymbol> elements = getElementSymbols();
- if(elements != null && elements.size() > 0) {
- copy.setElementSymbols(LanguageObject.Util.deepClone(elements, ElementSymbol.class));
- }
-
- return copy;
- }
-}
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AllSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -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.query.sql.symbol;
-
-import java.util.List;
-
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.LanguageVisitor;
-
-/**
- * <p>This is a subclass of Symbol representing *, which contains all of
- * the elements from all groups in the query. The name of this symbol is always "*",
- * when resolved it contains a set of Element Symbols referred to by the AllSymbol</p>
- */
-public class AllSymbol extends MultipleElementSymbol {
-
- private static final String ALL_SYMBOL_NAME = "*"; //$NON-NLS-1$
-
- /**
- * Constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected AllSymbol(String name, String canonicalName) {
- super(name, canonicalName);
- }
-
- /**
- * Default constructor
- */
- public AllSymbol(){
- this(ALL_SYMBOL_NAME, ALL_SYMBOL_NAME);
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Return a deep copy of this object
- * @return Deep copy of this object
- */
- public Object clone() {
- AllSymbol copy = new AllSymbol(ALL_SYMBOL_NAME, ALL_SYMBOL_NAME);
-
- List<ElementSymbol> elements = getElementSymbols();
- if(elements != null && elements.size() > 0) {
- copy.setElementSymbols(LanguageObject.Util.deepClone(elements, ElementSymbol.class));
- }
-
- return copy;
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -24,7 +24,6 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.visitor.SQLStringVisitor;
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/MultipleElementSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/MultipleElementSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/MultipleElementSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -22,22 +22,23 @@
package org.teiid.query.sql.symbol;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
/**
* <p>This is a subclass of Symbol representing multiple output columns.</p>
*/
-public abstract class MultipleElementSymbol extends SelectSymbol {
+public class MultipleElementSymbol implements SelectSymbol {
private List<ElementSymbol> elementSymbols;
+ private GroupSymbol group;
- /**
- * Passthrough constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected MultipleElementSymbol(String name, String canonicalName) {
- super(name, canonicalName);
+ public MultipleElementSymbol() {
}
/**
@@ -45,7 +46,7 @@
* @param name Name of the symbol
*/
public MultipleElementSymbol(String name){
- super(name);
+ this.group = new GroupSymbol(name);
}
/**
@@ -83,5 +84,60 @@
public boolean isResolved() {
return(elementSymbols != null);
}
+
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+ /**
+ * Return a deep copy of this object
+ * @return Deep copy of this object
+ */
+ public Object clone() {
+ MultipleElementSymbol copy = new MultipleElementSymbol();
+ if (group != null) {
+ copy.group = group.clone();
+ }
+
+ List<ElementSymbol> elements = getElementSymbols();
+ if(elements != null && elements.size() > 0) {
+ copy.setElementSymbols(LanguageObject.Util.deepClone(elements, ElementSymbol.class));
+ }
+
+ return copy;
+ }
+
+ /**
+ * @return null if selecting all groups, otherwise the specific group
+ */
+ public GroupSymbol getGroup() {
+ return group;
+ }
+
+ public void setGroup(GroupSymbol group) {
+ this.group = group;
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(0, group);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof MultipleElementSymbol)) {
+ return false;
+ }
+ MultipleElementSymbol other = (MultipleElementSymbol)obj;
+ return EquivalenceUtil.areEqual(this.group, other.group);
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/SelectSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/SelectSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/SelectSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -22,29 +22,14 @@
package org.teiid.query.sql.symbol;
+import org.teiid.query.sql.LanguageObject;
+
/**
* This is the server's representation of a metadata symbol that can be used
* in a SELECT statement. It exists as a typing mechanism and to provide a single
* additional method to get an ordered list of elements from each symbol.
*/
-public abstract class SelectSymbol extends Symbol {
+public interface SelectSymbol extends LanguageObject {
+
- /**
- * Passthrough constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected SelectSymbol(String name, String canonicalName) {
- super(name, canonicalName);
- }
-
- /**
- * Construct a symbol with a name
- * @param name Name of symbol
- */
- public SelectSymbol(String name) {
- super(name);
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/SingleElementSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/SingleElementSymbol.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/SingleElementSymbol.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -27,7 +27,7 @@
/**
* <p>This is a subclass of Symbol representing a single output column.</p>
*/
-public abstract class SingleElementSymbol extends SelectSymbol implements Expression {
+public abstract class SingleElementSymbol extends Symbol implements Expression, SelectSymbol {
/**
* Character used to delimit name components in a symbol
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -29,6 +29,7 @@
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
public class WindowFunction implements Expression {
@@ -46,6 +47,7 @@
public void setFunction(AggregateSymbol expression) {
this.function = expression;
+ this.function.setWindowed(true);
}
public List<Expression> getPartition() {
@@ -111,4 +113,9 @@
return clone;
}
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/AbstractSymbolMappingVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -33,11 +33,10 @@
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
import org.teiid.query.sql.proc.CriteriaSelector;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
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.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Symbol;
@@ -124,70 +123,28 @@
* Swap each ElementSymbol referenced by AllInGroupSymbol
* @param obj Object to remap
*/
- public void visit(AllInGroupSymbol obj) {
- // Discover new group name during course of mapping
- String newGroupName = null;
-
- List oldSymbols = obj.getElementSymbols();
+ public void visit(MultipleElementSymbol obj) {
+ List<ElementSymbol> oldSymbols = obj.getElementSymbols();
if(oldSymbols != null && oldSymbols.size() > 0) {
- List newSymbols = new ArrayList(oldSymbols.size());
+ List<ElementSymbol> newSymbols = new ArrayList<ElementSymbol>(oldSymbols.size());
- Iterator iter = oldSymbols.iterator();
+ Iterator<ElementSymbol> iter = oldSymbols.iterator();
while(iter.hasNext()) {
- ElementSymbol es = (ElementSymbol) iter.next();
+ ElementSymbol es = iter.next();
ElementSymbol mappedSymbol = getMappedElement(es);
-
- // Save group name on first valid mapped element
- if(newGroupName == null && mappedSymbol != null) {
- GroupSymbol newGroup = mappedSymbol.getGroupSymbol();
- if(newGroup != null) {
- newGroupName = newGroup.getName();
- }
- }
-
newSymbols.add( mappedSymbol );
}
obj.setElementSymbols(newSymbols);
}
-
- // If haven't discovered group name yet (if, for instance, stuff isn't resolved),
- // then fake up a group symbol, map it, and use the name of the mapped group symbol
- if(newGroupName == null) {
- String symbolName = obj.getName();
- String oldGroupName = symbolName.substring(0, symbolName.length()-2); // cut .* off
-
- GroupSymbol fakeSymbol = new GroupSymbol(oldGroupName);
- GroupSymbol mappedSymbol = getMappedGroup(fakeSymbol);
-
- newGroupName = mappedSymbol.getName();
+
+ if (obj.getGroup() == null) {
+ return;
}
- // Finally, swap name of group, which should be the name of the group
- // for all of the element symbols
- obj.setShortName(newGroupName + ".*"); //$NON-NLS-1$
-
+ obj.setGroup(getMappedGroup(obj.getGroup()));
}
/**
- * Swap each ElementSymbol referenced by AllSymbol
- * @param obj Object to remap
- */
- public void visit(AllSymbol obj) {
- List oldSymbols = obj.getElementSymbols();
- if(oldSymbols != null && oldSymbols.size() > 0) {
- List newSymbols = new ArrayList(oldSymbols.size());
-
- Iterator iter = oldSymbols.iterator();
- while(iter.hasNext()) {
- ElementSymbol es = (ElementSymbol) iter.next();
- newSymbols.add( getMappedElement(es) );
- }
-
- obj.setElementSymbols(newSymbols);
- }
- }
-
- /**
* Swap group in unary from clause.
* @param obj Object to remap
*/
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/AggregateSymbolCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -32,15 +32,21 @@
import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.WindowFunction;
public class AggregateSymbolCollectorVisitor extends LanguageVisitor {
public static class AggregateStopNavigator extends PreOrPostOrderNavigator {
-
- public AggregateStopNavigator(LanguageVisitor visitor) {
- super(visitor, PreOrPostOrderNavigator.POST_ORDER, false);
+
+ private Collection<? extends Expression> groupingCols;
+ private Collection<? super Expression> groupingColsUsed;
+
+ public AggregateStopNavigator(LanguageVisitor visitor, Collection<? super Expression> groupingColsUsed, Collection<? extends Expression> groupingCols) {
+ super(visitor, PreOrPostOrderNavigator.PRE_ORDER, false);
+ this.groupingCols = groupingCols;
+ this.groupingColsUsed = groupingColsUsed;
}
public void visit(AggregateSymbol obj) {
@@ -49,32 +55,56 @@
postVisitVisitor(obj);
}
+ @Override
+ protected void visitNode(LanguageObject obj) {
+ if (groupingCols != null && obj instanceof Expression && groupingCols.contains(obj)) {
+ if (groupingColsUsed != null) {
+ groupingColsUsed.add((Expression)obj);
+ }
+ return;
+ }
+ super.visitNode(obj);
+ }
+
}
private Collection<? super AggregateSymbol> aggregates;
- private Collection<? super SingleElementSymbol> groupingSymbols;
+ private Collection<? super ElementSymbol> otherElements;
+ private Collection<? super WindowFunction> windowFunctions;
- public AggregateSymbolCollectorVisitor(Collection<? super AggregateSymbol> aggregates, Collection<? super SingleElementSymbol> elements) {
+ public AggregateSymbolCollectorVisitor(Collection<? super AggregateSymbol> aggregates, Collection<? super ElementSymbol> elements) {
this.aggregates = aggregates;
- this.groupingSymbols = elements;
+ this.otherElements = elements;
}
public void visit(AggregateSymbol obj) {
- if (aggregates != null) {
+ if (aggregates != null && !obj.isWindowed()) {
this.aggregates.add(obj);
}
}
+ public void visit(WindowFunction windowFunction) {
+ if (this.windowFunctions != null) {
+ this.windowFunctions.add(windowFunction);
+ }
+ }
+
public void visit(ElementSymbol obj) {
- if (this.groupingSymbols != null) {
- this.groupingSymbols.add(obj);
+ if (this.otherElements != null && !obj.isExternalReference()) {
+ this.otherElements.add(obj);
}
}
- public static final void getAggregates(LanguageObject obj, Collection<? super AggregateSymbol> aggregates, Collection<SingleElementSymbol> elements) {
- AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(aggregates, elements);
- AggregateStopNavigator asn = new AggregateStopNavigator(visitor);
- obj.acceptVisitor(asn);
+ public static final void getAggregates(LanguageObject obj,
+ Collection<? super AggregateSymbol> aggregates,
+ Collection<? super ElementSymbol> otherElements,
+ Collection<? super Expression> groupingColsUsed,
+ Collection<? super Expression> windowFunctions,
+ Collection<? extends Expression> groupingCols) {
+ AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(aggregates, otherElements);
+ visitor.windowFunctions = windowFunctions;
+ AggregateStopNavigator asn = new AggregateStopNavigator(visitor, groupingColsUsed, groupingCols);
+ asn.visitNode(obj);
}
public static final Collection<AggregateSymbol> getAggregates(LanguageObject obj, boolean removeDuplicates) {
@@ -88,7 +118,7 @@
aggregates = new ArrayList<AggregateSymbol>();
}
AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(aggregates, null);
- AggregateStopNavigator asn = new AggregateStopNavigator(visitor);
+ AggregateStopNavigator asn = new AggregateStopNavigator(visitor, null, null);
obj.acceptVisitor(asn);
return aggregates;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/ElementCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/ElementCollectorVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/ElementCollectorVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -32,9 +32,8 @@
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
import org.teiid.query.sql.navigator.PreOrderNavigator;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
/**
@@ -81,24 +80,13 @@
* called directly.
* @param obj Language object
*/
- public void visit(AllInGroupSymbol obj) {
+ public void visit(MultipleElementSymbol obj) {
if(obj.getElementSymbols() != null) {
this.elements.addAll(obj.getElementSymbols());
}
}
/**
- * Visit a language object and collect symbols. This method should <b>NOT</b> be
- * called directly.
- * @param obj Language object
- */
- public void visit(AllSymbol obj) {
- if(obj.getElementSymbols() != null) {
- this.elements.addAll(obj.getElementSymbols());
- }
- }
-
- /**
* Helper to quickly get the elements from obj in the elements collection
* @param obj Language object
* @param elements Collection to collect elements in
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -109,8 +109,6 @@
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.DerivedColumn;
@@ -119,6 +117,7 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -1157,14 +1156,16 @@
append(escapeSinglePart(obj.getOutputName()));
}
- public void visit( AllInGroupSymbol obj ) {
- append(obj.getName());
+ public void visit( MultipleElementSymbol obj ) {
+ if (obj.getGroup() == null) {
+ append(Tokens.ALL_COLS);
+ } else {
+ visitNode(obj.getGroup());
+ append(Tokens.DOT);
+ append(Tokens.ALL_COLS);
+ }
}
- public void visit( AllSymbol obj ) {
- append(obj.getName());
- }
-
public void visit( Constant obj ) {
Class<?> type = obj.getType();
String[] constantParts = null;
Deleted: trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -1,163 +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.query.validator;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.teiid.core.types.DataTypeManager;
-import org.teiid.query.QueryPlugin;
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.navigator.PreOrderNavigator;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.AggregateSymbol.Type;
-import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
-import org.teiid.query.sql.visitor.ElementCollectorVisitor;
-
-/**
- * Validate that all ElementSymbol and ExpressionSymbols used in the HAVING
- * and SELECT clauses are based on symbols used in the GROUP BY clause.
- * @since 4.2
- */
-public class AggregateValidationVisitor extends AbstractValidationVisitor {
-
- private boolean validateBelow = true;
-
- // Symbols from GROUP BY - may be null if no group symbols
- private Set<Expression> groupExpressions;
-
- public AggregateValidationVisitor(Set<Expression> groupExpressions) {
- this.groupExpressions = groupExpressions;
- }
-
- public void visit(AggregateSymbol obj) {
- Expression aggExp = obj.getExpression();
-
- validateNoNestedAggs(aggExp);
- validateNoNestedAggs(obj.getOrderBy());
- validateNoNestedAggs(obj.getCondition());
-
- // Verify data type of aggregate expression
- Type aggregateFunction = obj.getAggregateFunction();
- if((aggregateFunction == Type.SUM || aggregateFunction == Type.AVG) && obj.getType() == null) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0041", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- } else if (obj.getType() != DataTypeManager.DefaultDataClasses.NULL) {
- if (aggregateFunction == Type.XMLAGG && aggExp.getType() != DataTypeManager.DefaultDataClasses.XML) {
- handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- } else if (obj.isBoolean() && aggExp.getType() != DataTypeManager.DefaultDataClasses.BOOLEAN) {
- handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_boolean", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- }
- }
- if((obj.isDistinct() || aggregateFunction == Type.MIN || aggregateFunction == Type.MAX) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
- handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- }
- if(obj.isEnhancedNumeric()) {
- if (!Number.class.isAssignableFrom(aggExp.getType())) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0041", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- }
- if (obj.isDistinct()) {
- handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.invalid_distinct", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
- }
- }
- validateBelow = false;
- }
-
- private void validateNoNestedAggs(LanguageObject aggExp) {
- // Check for any nested aggregates (which are not allowed)
- if(aggExp != null) {
- Collection<AggregateSymbol> nestedAggs = AggregateSymbolCollectorVisitor.getAggregates(aggExp, true);
- if(nestedAggs.size() > 0) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0039", nestedAggs), nestedAggs); //$NON-NLS-1$
- }
- }
- }
-
- public void visit(ElementSymbol obj) {
- validateExpression(obj);
- }
-
- public void visit(ExpressionSymbol obj) {
- validateExpression(obj);
- }
-
- public void visit(CaseExpression obj) {
- validateExpression(obj);
- }
-
- public void visit(SearchedCaseExpression obj) {
- validateExpression(obj);
- }
-
- public void visit(Function obj) {
- validateExpression(obj);
- }
-
- private void validateExpression(Expression symbol) {
- if (ElementCollectorVisitor.getElements(symbol, false).isEmpty()) {
- validateBelow = false;
- return;
- }
-
- if(groupExpressions == null) {
- if (symbol instanceof ElementSymbol && !((ElementSymbol)symbol).isExternalReference()) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0037", symbol), symbol); //$NON-NLS-1$
- }
- } else if(! groupExpressions.contains(symbol)) {
- if (symbol instanceof ElementSymbol && !((ElementSymbol)symbol).isExternalReference()) {
- handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0038", symbol), symbol); //$NON-NLS-1$
- }
- } else {
- validateBelow = false;
- }
- }
-
- public static void validate(LanguageObject obj, final AggregateValidationVisitor visitor) {
- visitor.validateBelow = true;
- PreOrderNavigator nav = new PreOrderNavigator(visitor) {
- private boolean validateBelow;
-
- protected void visitNode(LanguageObject obj) {
- if (validateBelow) {
- super.visitNode(obj);
- }
- }
-
- protected void preVisitVisitor(LanguageObject obj) {
- super.preVisitVisitor(obj);
- this.validateBelow = visitor.validateBelow;
- }
-
- protected void postVisitVisitor(LanguageObject obj) {
- this.validateBelow = true;
- }
- };
- obj.acceptVisitor(nav);
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -121,6 +122,7 @@
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.TextLine;
+import org.teiid.query.sql.symbol.WindowFunction;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
@@ -752,42 +754,38 @@
validateNoAggsInClause(groupBy);
validateNoAggsInClause(query.getCriteria());
validateNoAggsInClause(query.getFrom());
- if(groupBy != null || having != null || !AggregateSymbolCollectorVisitor.getAggregates(select, false).isEmpty()) {
- Set<Expression> groupSymbols = null;
- if(groupBy != null) {
- groupSymbols = new HashSet<Expression>();
- for (final Iterator<Expression> iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
- final Expression element = iterator.next();
- groupSymbols.add(element);
- }
- }
-
- // Validate HAVING, if it exists
- AggregateValidationVisitor visitor = new AggregateValidationVisitor(groupSymbols);
- if(having != null) {
- AggregateValidationVisitor.validate(having, visitor);
- }
-
- // Validate SELECT
- List<SingleElementSymbol> projectedSymbols = select.getProjectedSymbols();
- for (SingleElementSymbol symbol : projectedSymbols) {
- AggregateValidationVisitor.validate(symbol, visitor);
- }
-
- // Move items to this report
- ValidatorReport report = visitor.getReport();
- Collection<ValidatorFailure> items = report.getItems();
- super.getReport().addItems(items);
+ Set<Expression> groupSymbols = null;
+ boolean hasAgg = false;
+ if (groupBy != null) {
+ groupSymbols = new HashSet<Expression>(groupBy.getSymbols());
+ hasAgg = true;
}
+ LinkedHashSet<Expression> invalid = new LinkedHashSet<Expression>();
+ LinkedHashSet<Expression> invalidWindowFunctions = new LinkedHashSet<Expression>();
+ LinkedList<AggregateSymbol> aggs = new LinkedList<AggregateSymbol>();
+ if (having != null) {
+ AggregateSymbolCollectorVisitor.getAggregates(having, aggs, invalid, null, invalidWindowFunctions, groupSymbols);
+ hasAgg = true;
+ }
+ for (SingleElementSymbol symbol : select.getProjectedSymbols()) {
+ AggregateSymbolCollectorVisitor.getAggregates(symbol, aggs, invalid, null, null, groupSymbols);
+ }
+ if ((!aggs.isEmpty() || hasAgg) && !invalid.isEmpty()) {
+ handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0037", invalid), invalid); //$NON-NLS-1$
+ }
+ if (!invalidWindowFunctions.isEmpty()) {
+ handleValidationError(QueryPlugin.Util.getString("SQLParser.window_only_top_level", invalidWindowFunctions), invalidWindowFunctions); //$NON-NLS-1$
+ }
}
private void validateNoAggsInClause(LanguageObject clause) {
if (clause == null) {
return;
}
- Collection<AggregateSymbol> aggs = AggregateSymbolCollectorVisitor.getAggregates(clause, false);
+ LinkedHashSet<Expression> aggs = new LinkedHashSet<Expression>();
+ AggregateSymbolCollectorVisitor.getAggregates(clause, aggs, null, null, aggs, null);
if (!aggs.isEmpty()) {
- handleValidationError(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level", aggs), aggs);
+ handleValidationError(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level", aggs), aggs); //$NON-NLS-1$
}
}
@@ -1204,18 +1202,56 @@
}
@Override
+ public void visit(WindowFunction windowFunction) {
+ AggregateSymbol.Type type = windowFunction.getFunction().getAggregateFunction();
+ switch (type) {
+ case RANK:
+ case DENSE_RANK:
+ case ROW_NUMBER:
+ if (windowFunction.getOrderBy() == null) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.analytical_requires_order_by", windowFunction), windowFunction); //$NON-NLS-1$
+ }
+ }
+ validateNoSubqueriesOrOuterReferences(windowFunction);
+ }
+
+ @Override
public void visit(AggregateSymbol obj) {
if (obj.getCondition() != null) {
Expression condition = obj.getCondition();
- if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(condition).isEmpty()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.filter_subquery", condition), condition); //$NON-NLS-1$
- }
- for (ElementSymbol es : ElementCollectorVisitor.getElements(condition, false)) {
- if (es.isExternalReference()) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.filter_subquery", es), es); //$NON-NLS-1$
- }
- }
+ validateNoSubqueriesOrOuterReferences(condition);
}
+ Expression aggExp = obj.getExpression();
+
+ validateNoNestedAggs(aggExp);
+ validateNoNestedAggs(obj.getOrderBy());
+ validateNoNestedAggs(obj.getCondition());
+
+ // Verify data type of aggregate expression
+ Type aggregateFunction = obj.getAggregateFunction();
+ if((aggregateFunction == Type.SUM || aggregateFunction == Type.AVG) && obj.getType() == null) {
+ handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0041", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ } else if (obj.getType() != DataTypeManager.DefaultDataClasses.NULL) {
+ if (aggregateFunction == Type.XMLAGG && aggExp.getType() != DataTypeManager.DefaultDataClasses.XML) {
+ handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ } else if (obj.isBoolean() && aggExp.getType() != DataTypeManager.DefaultDataClasses.BOOLEAN) {
+ handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_boolean", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
+ }
+ if((obj.isDistinct() || aggregateFunction == Type.MIN || aggregateFunction == Type.MAX) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
+ handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
+ if(obj.isEnhancedNumeric()) {
+ if (!Number.class.isAssignableFrom(aggExp.getType())) {
+ handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0041", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
+ if (obj.isDistinct()) {
+ handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.invalid_distinct", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
+ }
+ if (obj.isWindowed() && obj.getOrderBy() != null) {
+ handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0042", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
if (obj.getAggregateFunction() != Type.TEXTAGG) {
return;
}
@@ -1235,7 +1271,29 @@
}
}
}
+
+ private void validateNoSubqueriesOrOuterReferences(Expression expr) {
+ if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr).isEmpty()) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.filter_subquery", expr), expr); //$NON-NLS-1$
+ }
+ for (ElementSymbol es : ElementCollectorVisitor.getElements(expr, false)) {
+ if (es.isExternalReference()) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.filter_subquery", es), es); //$NON-NLS-1$
+ }
+ }
+ }
+ private void validateNoNestedAggs(LanguageObject aggExp) {
+ // Check for any nested aggregates (which are not allowed)
+ if(aggExp != null) {
+ HashSet<Expression> nestedAggs = new LinkedHashSet<Expression>();
+ AggregateSymbolCollectorVisitor.getAggregates(aggExp, nestedAggs, null, null, nestedAggs, null);
+ if(!nestedAggs.isEmpty()) {
+ handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0039", nestedAggs), nestedAggs); //$NON-NLS-1$
+ }
+ }
+ }
+
private String[] validateQName(LanguageObject obj, String name) {
try {
return Name11Checker.getInstance().getQNameParts(name);
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-07-21 19:28:44 UTC (rev 3323)
@@ -1740,7 +1740,7 @@
query=query(info) |
(<TABLE> name=id() {
Query q = new Query();
- q.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ q.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
q.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol(name)))));
query = q;
}) |
@@ -1826,7 +1826,7 @@
[<ALL> | (<DISTINCT> {isDistinct=true;})]
(<STAR>
{
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
}
|
( symbol=selectSymbol(info) { select.addSymbol(symbol); }
@@ -1908,7 +1908,7 @@
}
}
-AllInGroupSymbol allInGroupSymbol() :
+MultipleElementSymbol allInGroupSymbol() :
{
Token allInGroupToken = null;
@@ -1916,7 +1916,7 @@
{
allInGroupToken = <ALL_IN_GROUP>
{
- return new AllInGroupSymbol(normalizeId(allInGroupToken.image));
+ return new MultipleElementSymbol(normalizeId(allInGroupToken.image.substring(0, allInGroupToken.image.length() - 2)));
}
}
@@ -2773,7 +2773,7 @@
proc = storedProcedure(info, new StoredProcedure()) //deprecated
)
{
- subquery = new Query(new Select(Arrays.asList(new AllSymbol())), new From(Arrays.asList(new SubqueryFromClause("x", proc))), null, null, null);
+ subquery = new Query(new Select(Arrays.asList(new MultipleElementSymbol())), new From(Arrays.asList(new SubqueryFromClause("x", proc))), null, null, null);
}
)
<RPAREN>
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-07-21 19:28:44 UTC (rev 3323)
@@ -204,10 +204,10 @@
ERR.015.012.0033 = Metadata does not allow updates on the group: {0}
ERR.015.012.0034 = Queries involving UNIONs, INTERSECTs and EXCEPTs not allowed on XML documents
ERR.015.012.0035 = Queries combined with the set operator {0} must have the same number of output elements.
-ERR.015.012.0037 = Invalid symbol: {0}. When an aggregate function is used in the SELECT clause and no GROUP BY clause is specified, the SELECT clause may contain only aggregate functions and constants.
-ERR.015.012.0038 = Invalid symbol: {0}. When a GROUP BY clause is used, all elements in the SELECT clause must be declared in the GROUP BY clause.
+ERR.015.012.0037 = {0} cannot be used outside of aggregate functions since they are not present in a GROUP BY clause.
ERR.015.012.0039 = Nested aggregate expressions are not allowed: {0}
ERR.015.012.0041 = The aggregate function {0} cannot be used with non-numeric expressions: {1}
+ERR.015.012.0042 = The aggregate function {0} cannot use its own order by clause when windowed: {1}
AggregateValidationVisitor.non_comparable = The aggregate function {0} cannot be used with non-comparable expressions: {1}
AggregateValidationVisitor.non_xml = The XMLAGG aggregate function {0} requires an expression of type XML: {1}
AggregateValidationVisitor.non_boolean=The boolean aggregate functions ANY, SOME, EVERY require a boolean expression.
@@ -259,7 +259,8 @@
SQLParser.Unknown_join_type=Unknown join type: {0}
-SQLParser.Aggregate_only_top_level=Aggregate functions are not allowed in the FROM/WHERE/GROUP BY clauses: {0}
+SQLParser.Aggregate_only_top_level=Aggregate and window functions are not allowed in the FROM/WHERE/GROUP BY clauses: {0}
+SQLParser.window_only_top_level=Window functions are not allowed in the HAVING clause: {0}
SQLParser.Unknown_agg_func=Unknown aggregate function: {0}
SQLParser.Invalid_func=Invalid function name: [{0}]
SQLParser.Integer_parse=Unable to parse integer literal: {0}
@@ -678,7 +679,8 @@
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.groupby_subquery=Expressions used in a GROUP BY clause cannot be constant and must not contain subqueries: "{0}".
-ValidationVisitor.filter_subquery=Expressions used in a FILTER clause must not contain subqueries nor outer references: "{0}".
+ValidationVisitor.filter_subquery=Expressions used in a FILTER clause or a window function must not contain subqueries nor outer references: "{0}".
+ValidationVisitor.analytical_requires_order_by=The window analytical functions RANK, DENSE_RANK, and ROW_NUMBER require the use of an ORDER BY clause in the window specification: {0}.
ValidationVisitor.Procedure_has_group_self_reference=Procedure cannot have a Group reference to itself.
ExpressionEvaluator.Expected_props_for_payload_function=Unable to evaluate {0}: expected Properties for command payload but got object of type {1}
ValidationVisitor.The_rowlimit_function_cannot_be_used_in_a_non-XML_command=The ''rowlimit'' and ''rowlimitexception'' functions cannot be used in a non-XML command
Modified: trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -38,7 +38,7 @@
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
/**
@@ -90,8 +90,8 @@
List expandedSymbols = new ArrayList();
for (Iterator i = originalSymbols.iterator(); i.hasNext(); ) {
Object next = i.next();
- if (next instanceof AllSymbol) {
- AllSymbol allSymbol = (AllSymbol) next;
+ if (next instanceof MultipleElementSymbol) {
+ MultipleElementSymbol allSymbol = (MultipleElementSymbol) next;
expandedSymbols.addAll(allSymbol.getElementSymbols());
} else {
expandedSymbols.add(next);
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -823,6 +823,11 @@
System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 = e1 HAVING min(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS MAX, e1, MIN(e3) AS MIN FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.MIN < pm3.g1.e3) AND (pm3.g1.e2 < X__1.MAX) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4());
}
+
+ @Test public void testSubqueryRewriteToJoinWithGroupingExpression() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
+ TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm3.g1 where exists (select 1 FROM pm1.g1 group by e4 || 'x' HAVING min(e3) || (e4 || 'x') = pm3.g1.e3)", "SELECT DISTINCT e1 FROM pm3.g1, (SELECT 1 AS EXPR, MIN(e3) AS MIN, concat(e4, 'x') AS EXPR_0, concat(MIN(e3), concat(e4, 'x')) AS EXPR_1 FROM pm1.g1 GROUP BY concat(e4, 'x')) AS X__1 WHERE pm3.g1.e3 = X__1.EXPR_1", RealMetadataFactory.example4());
+ }
/**
* A join will not be used here because of the not
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -32,7 +32,7 @@
import org.teiid.query.sql.lang.From;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.Select;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.unittest.RealMetadataFactory;
@@ -67,7 +67,7 @@
query.setFrom(from);
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
group.setMetadataID(METADATA.getGroupID("pm4.g2")); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestLimitParsing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestLimitParsing.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestLimitParsing.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -34,7 +34,7 @@
import org.teiid.query.sql.lang.SetQuery;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.SetQuery.Operation;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
@@ -43,7 +43,7 @@
@Test public void testLimit() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -53,7 +53,7 @@
@Test public void testLimitWithOffset() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -63,7 +63,7 @@
@Test public void testLimitWithReferences1() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -73,7 +73,7 @@
@Test public void testLimitWithReferences2() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -83,7 +83,7 @@
@Test public void testLimitWithReferences3() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -93,7 +93,7 @@
@Test public void testSetQueryLimit() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -104,7 +104,7 @@
@Test public void testOffset() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -114,7 +114,7 @@
@Test public void testFetchFirst() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -124,7 +124,7 @@
@Test public void testFetchFirstRow() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -134,7 +134,7 @@
@Test public void testOffsetFetch() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -57,7 +57,7 @@
import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.Statement;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -434,7 +434,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -452,7 +452,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -470,7 +470,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -488,7 +488,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -506,7 +506,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -524,7 +524,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -542,7 +542,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("t1")); //$NON-NLS-1$
@@ -560,7 +560,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -578,7 +578,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("t1")); //$NON-NLS-1$
@@ -596,13 +596,13 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
Query query2 = new Query();
select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query2.setSelect(select);
From from2 = new From();
from2.addGroup(new GroupSymbol("t1")); //$NON-NLS-1$
@@ -623,7 +623,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
@@ -692,7 +692,7 @@
Query query2 = new Query();
select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from2 = new From();
from2.addGroup(new GroupSymbol("t1")); //$NON-NLS-1$
from2.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
@@ -1042,7 +1042,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -1058,7 +1058,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -1087,7 +1087,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -1106,7 +1106,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
@@ -1116,7 +1116,7 @@
Query query1 = new Query();
select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query1.setSelect(select);
from = new From();
ufc = new UnaryFromClause();
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -101,8 +101,6 @@
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.DerivedColumn;
@@ -111,6 +109,7 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
@@ -217,7 +216,7 @@
From from = new From();
from.addClause(jp);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -237,7 +236,7 @@
From from = new From();
from.addClause(jp);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -259,7 +258,7 @@
from.addClause(jp);
from.addClause(new UnaryFromClause(new GroupSymbol("g3"))); //$NON-NLS-1$
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -286,7 +285,7 @@
From from = new From();
from.addClause(jp2);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -311,7 +310,7 @@
From from = new From();
from.addClause(jp3);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -334,7 +333,7 @@
From from = new From();
from.addClause(jp2);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -358,7 +357,7 @@
from.addClause(jp2);
from.addClause(new UnaryFromClause(new GroupSymbol("g4"))); //$NON-NLS-1$
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -387,7 +386,7 @@
from.addClause(g4);
from.addClause(jp3);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -416,7 +415,7 @@
from.addClause(g1);
from.addClause(jp);
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
Select select = new Select();
select.addSymbol(all);
@@ -1918,7 +1917,7 @@
from.addGroup(h);
Select select = new Select();
- AllInGroupSymbol myG = new AllInGroupSymbol("myG.*"); //$NON-NLS-1$
+ MultipleElementSymbol myG = new MultipleElementSymbol("myG"); //$NON-NLS-1$
select.addSymbol(myG);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -1939,7 +1938,7 @@
from.addGroup(h);
Select select = new Select();
- AllInGroupSymbol myG = new AllInGroupSymbol("myG.*"); //$NON-NLS-1$
+ MultipleElementSymbol myG = new MultipleElementSymbol("myG"); //$NON-NLS-1$
select.addSymbol(myG);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -2309,7 +2308,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
Query query = new Query();
query.setSelect(select);
@@ -2327,7 +2326,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
Query query = new Query();
query.setSelect(select);
@@ -2345,7 +2344,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
Query query = new Query();
query.setSelect(select);
@@ -2676,10 +2675,10 @@
/** SELECT a FROM db.g WHERE b = aString order by c desc,d desc*/
@Test public void testOrderBysDesc(){
- ArrayList elements = new ArrayList();
+ ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(new ElementSymbol("c")); //$NON-NLS-1$
elements.add(new ElementSymbol("d")); //$NON-NLS-1$
- ArrayList orderTypes = new ArrayList();
+ ArrayList<Boolean> orderTypes = new ArrayList<Boolean>();
orderTypes.add(Boolean.FALSE);
orderTypes.add(Boolean.FALSE);
OrderBy orderBy = new OrderBy(elements, orderTypes);
@@ -2692,10 +2691,10 @@
/** SELECT a FROM db.g WHERE b = aString order by c desc,d*/
@Test public void testMixedOrderBys(){
- ArrayList elements = new ArrayList();
+ ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(new ElementSymbol("c")); //$NON-NLS-1$
elements.add(new ElementSymbol("d")); //$NON-NLS-1$
- ArrayList orderTypes = new ArrayList();
+ ArrayList<Boolean> orderTypes = new ArrayList<Boolean>();
orderTypes.add(Boolean.FALSE);
orderTypes.add(Boolean.TRUE);
OrderBy orderBy = new OrderBy(elements, orderTypes);
@@ -3358,7 +3357,7 @@
@Test public void testHasEQCriteria() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(a);
CriteriaSelector critSelector = new CriteriaSelector();
@@ -3391,7 +3390,7 @@
/**HAS IN CRITERIA ON (a)*/
@Test public void testHasInCriteria() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(a);
CriteriaSelector critSelector = new CriteriaSelector();
@@ -3408,7 +3407,7 @@
/**HAS COMPARE_LT CRITERIA ON (a)*/
@Test public void testHasLTCriteria() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(a);
CriteriaSelector critSelector = new CriteriaSelector();
@@ -3425,7 +3424,7 @@
/**HAS COMPARE_LE CRITERIA ON (a)*/
@Test public void testHasLECriteria() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- List elements = new ArrayList();
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(a);
CriteriaSelector critSelector = new CriteriaSelector();
@@ -3604,7 +3603,7 @@
* @return
*/
private Query sampleQuery() {
- List symbols = new ArrayList();
+ List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
Select select = new Select(symbols);
@@ -3645,7 +3644,7 @@
//sql is a variable, also uses the as, into, and update clauses
@Test public void testDynamicCommandStatement1() throws Exception {
- List symbols = new ArrayList();
+ List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
@@ -3737,7 +3736,7 @@
Statement declStmt = new DeclareStatement(var1, shortType);
//ifblock
- List symbols = new ArrayList();
+ List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
symbols.add(new ElementSymbol("a1")); //$NON-NLS-1$
Select select = new Select(symbols);
@@ -3761,7 +3760,7 @@
ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
Statement elseDeclStmt = new DeclareStatement(var2, shortType);
- List elseSymbols = new ArrayList();
+ List<ElementSymbol> elseSymbols = new ArrayList<ElementSymbol>();
elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
Select elseSelect = new Select(elseSymbols);
@@ -3770,7 +3769,6 @@
elseQuery.setFrom(from);
elseQuery.setCriteria(criteria);
- Command elseQueryCmd = elseQuery;
AssignmentStatement elseQueryStmt = new AssignmentStatement(var2, elseQuery);
Block elseBlock = new Block();
@@ -3867,7 +3865,7 @@
ElementSymbol var2 = new ElementSymbol("var2"); //$NON-NLS-1$
Statement elseDeclStmt = new DeclareStatement(var2, shortType);
- List elseSymbols = new ArrayList();
+ List<ElementSymbol> elseSymbols = new ArrayList<ElementSymbol>();
elseSymbols.add(new ElementSymbol("b1")); //$NON-NLS-1$
Select elseSelect = new Select(elseSymbols);
@@ -5011,7 +5009,7 @@
StoredProcedure exec = new StoredProcedure();
exec.setProcedureName("m.sq1"); //$NON-NLS-1$
- Query query = new Query(new Select(Arrays.asList(new AllSymbol())), new From(Arrays.asList(new SubqueryFromClause("x", exec))), null, null, null);
+ Query query = new Query(new Select(Arrays.asList(new MultipleElementSymbol())), new From(Arrays.asList(new SubqueryFromClause("x", exec))), null, null, null);
SubquerySetCriteria subCrit = new SubquerySetCriteria(expr, query);
Query outer = new Query();
@@ -5079,7 +5077,7 @@
@Test public void testExecSubquery(){
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addClause(new UnaryFromClause(new GroupSymbol("newModel2.Table1"))); //$NON-NLS-1$
@@ -5102,7 +5100,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("TestDocument.TestDocument")); //$NON-NLS-1$
@@ -5122,7 +5120,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("TestDocument.TestDocument")); //$NON-NLS-1$
@@ -5165,7 +5163,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
@@ -5184,7 +5182,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
@@ -5203,7 +5201,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
@@ -5220,7 +5218,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
@@ -5265,7 +5263,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
@@ -5307,7 +5305,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
@@ -5353,7 +5351,7 @@
Query query = new Query();
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
@@ -5998,7 +5996,7 @@
@Test public void testAndOrPrecedence_1575() {
Select s = new Select();
- s.addSymbol(new AllSymbol());
+ s.addSymbol(new MultipleElementSymbol());
From f = new From();
f.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$
CompareCriteria c1 = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(0))); //$NON-NLS-1$
@@ -6017,7 +6015,7 @@
@Test public void testAndOrPrecedence2_1575() {
Select s = new Select();
- s.addSymbol(new AllSymbol());
+ s.addSymbol(new MultipleElementSymbol());
From f = new From();
f.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$
CompareCriteria c1 = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(0))); //$NON-NLS-1$
@@ -6040,7 +6038,7 @@
*/
private void helpTestCompoundNonJoinCriteria(String sqlPred, PredicateCriteria predCrit) {
Select s = new Select();
- s.addSymbol(new AllSymbol());
+ s.addSymbol(new MultipleElementSymbol());
From f = new From();
CompareCriteria c1 = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(0))); //$NON-NLS-1$
@@ -6486,7 +6484,7 @@
Query query = new Query();
Select select = new Select();
query.setSelect(select);
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
query.setFrom(from);
Criteria compareCriteria = new CompareCriteria(new ElementSymbol("A.x"), CompareCriteria.EQ, new ElementSymbol("B.x")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -6522,7 +6520,7 @@
String expected = "SELECT * FROM pm1.g1 UNION JOIN pm1.g2 WHERE g1.e1 = 1"; //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addClause(new JoinPredicate(new UnaryFromClause(new GroupSymbol("pm1.g1")), new UnaryFromClause(new GroupSymbol("pm1.g2")), JoinType.JOIN_UNION)); //$NON-NLS-1$ //$NON-NLS-2$
@@ -6696,7 +6694,7 @@
@Test public void testNestedTable() throws Exception {
String sql = "SELECT * from TABLE(exec foo()) as x"; //$NON-NLS-1$
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ query.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
StoredProcedure sp = new StoredProcedure();
sp.setProcedureName("foo");
SubqueryFromClause sfc = new SubqueryFromClause("x", sp);
@@ -6708,7 +6706,7 @@
@Test public void testTextTable() throws Exception {
String sql = "SELECT * from texttable(file columns x string WIDTH 1, y date width 10 skip 10) as x"; //$NON-NLS-1$
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ query.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
TextTable tt = new TextTable();
tt.setFile(new ElementSymbol("file"));
List<TextTable.TextColumn> columns = new ArrayList<TextTable.TextColumn>();
@@ -6738,7 +6736,7 @@
@Test public void testXMLTable() throws Exception {
String sql = "SELECT * from xmltable(xmlnamespaces(no default), '/' columns x for ordinality, y date default {d'2000-01-01'} path '@date') as x"; //$NON-NLS-1$
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ query.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
XMLTable xt = new XMLTable();
xt.setName("x");
xt.setNamespaces(new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem())));
@@ -6802,7 +6800,7 @@
Query query = new Query();
Select select = new Select();
query.setSelect(select);
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("X"))));
query.setFrom(from);
helpTest("TABLE X", "SELECT * FROM X", query);
@@ -6811,7 +6809,7 @@
@Test public void testArrayTable() throws Exception {
String sql = "SELECT * from arraytable(null columns x string, y date) as x"; //$NON-NLS-1$
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ query.setSelect(new Select(Arrays.asList(new MultipleElementSymbol())));
ArrayTable tt = new ArrayTable();
tt.setArrayValue(new Constant(null, DataTypeManager.DefaultDataClasses.OBJECT));
List<TableFunctionReference.ProjectedColumn> columns = new ArrayList<TableFunctionReference.ProjectedColumn>();
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -28,7 +28,7 @@
import org.teiid.query.sql.lang.Select;
import org.teiid.query.sql.lang.SetQuery;
import org.teiid.query.sql.lang.SetQuery.Operation;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -81,7 +81,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
Query query1 = new Query();
query1.setSelect(select);
Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -7846,7 +7846,7 @@
"</Catalogs>\r\n\r\n"; //$NON-NLS-1$
- helpTestProcess("SELECT Catalogs.Catalog.Items.Item.ItemID, Order.* " + //$NON-NLS-1$
+ helpTestProcess("SELECT Catalogs.Catalog.Items.Item.ItemID, \"Order\".* " + //$NON-NLS-1$
" FROM xmltest.doc9c " + //$NON-NLS-1$
" WHERE SupplierID > '54' " + //$NON-NLS-1$
" ORDER BY ItemID DESC, OrderID DESC", //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -93,7 +93,6 @@
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.symbol.SelectSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.CommandCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
@@ -293,11 +292,11 @@
private void helpCheckSelect(Query query, String[] elementNames) {
Select select = query.getSelect();
- List elements = select.getSymbols();
+ List<SingleElementSymbol> elements = select.getProjectedSymbols();
assertEquals("Wrong number of select symbols: ", elementNames.length, elements.size()); //$NON-NLS-1$
for(int i=0; i<elements.size(); i++) {
- SelectSymbol symbol = (SelectSymbol) elements.get(i);
+ SingleElementSymbol symbol = elements.get(i);
assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase()); //$NON-NLS-1$
}
}
@@ -594,7 +593,6 @@
@Test public void testSelectStar() {
Query resolvedQuery = (Query) helpResolve("SELECT * FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -603,7 +601,6 @@
@Test public void testSelectStarFromAliasedGroup() {
Query resolvedQuery = (Query) helpResolve("SELECT * FROM pm1.g1 as x"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "x.e1", "x.e2", "x.e3", "x.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -612,7 +609,6 @@
@Test public void testSelectStarFromMultipleAliasedGroups() {
Query resolvedQuery = (Query) helpResolve("SELECT * FROM pm1.g1 as x, pm1.g1 as y"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1", "pm1.g1" }); //$NON-NLS-1$ //$NON-NLS-2$
- helpCheckSelect(resolvedQuery, new String[] { "*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "x.e1", "x.e2", "x.e3", "x.e4", "y.e1", "y.e2", "y.e3", "y.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4", "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
@@ -621,7 +617,6 @@
@Test public void testSelectStarWhereSomeElementsAreNotSelectable() {
Query resolvedQuery = (Query) helpResolve("SELECT * FROM pm1.g4"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g4" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g4.e1", "pm1.g4.e3" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { "pm1.g4.e1", "pm1.g4.e3" } ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -630,7 +625,6 @@
@Test public void testSelectGroupStarWhereSomeElementsAreNotSelectable() {
Query resolvedQuery = (Query) helpResolve("SELECT pm1.g4.* FROM pm1.g4"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g4" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g4.*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g4.e1", "pm1.g4.e3" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { "pm1.g4.e1", "pm1.g4.e3" } ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -639,7 +633,6 @@
@Test public void testFullyQualifiedSelectStar() {
Query resolvedQuery = (Query) helpResolve("SELECT pm1.g1.* FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -648,7 +641,6 @@
@Test public void testSelectAllInAliasedGroup() {
Query resolvedQuery = (Query) helpResolve("SELECT x.* FROM pm1.g1 as x"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "x.*" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "x.e1", "x.e2", "x.e3", "x.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -28,7 +28,7 @@
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.sql.lang.Select;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import junit.framework.TestCase;
@@ -50,7 +50,7 @@
symbols.add(new ElementSymbol("b")); //$NON-NLS-1$
Select select = new Select();
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
all.setElementSymbols(symbols);
select.addSymbol(all);
return select;
@@ -69,7 +69,7 @@
public void testGetProjectedNoElements() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
List projectedSymbols = select.getProjectedSymbols();
assertEquals("Did not get empty list for select * with no elements: ", new ArrayList(), projectedSymbols); //$NON-NLS-1$
@@ -81,7 +81,7 @@
symbols.add(new ElementSymbol("b")); //$NON-NLS-1$
Select select = new Select();
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
all.setElementSymbols(symbols);
select.addSymbol(all);
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -25,16 +25,15 @@
import java.util.ArrayList;
import java.util.List;
+import junit.framework.TestCase;
+
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
+import org.teiid.query.sql.symbol.Expression;
-import junit.framework.TestCase;
-
public class TestAggregateSymbolCollectorVisitor extends TestCase {
public TestAggregateSymbolCollectorVisitor(String name) {
@@ -46,9 +45,9 @@
Command command = QueryParser.getQueryParser().parseCommand(sql);
// Find aggregates
- List<SingleElementSymbol> foundAggs = new ArrayList<SingleElementSymbol>();
- List<SingleElementSymbol> foundElements = new ArrayList<SingleElementSymbol>();
- AggregateSymbolCollectorVisitor.getAggregates(command, foundAggs, foundElements);
+ List<Expression> foundAggs = new ArrayList<Expression>();
+ List<Expression> foundElements = new ArrayList<Expression>();
+ AggregateSymbolCollectorVisitor.getAggregates(command, foundAggs, foundElements, null, null, null);
// Compare
assertEquals("Incorrect number of aggregates: " + foundAggs, aggs.length, foundAggs.size()); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -77,8 +77,6 @@
import org.teiid.query.sql.proc.RaiseErrorStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -86,6 +84,7 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
@@ -571,7 +570,7 @@
public void testQuery1() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Query query = new Query();
@@ -583,7 +582,7 @@
public void testQuery2() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
@@ -606,7 +605,7 @@
public void testQuery3() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
GroupBy groupBy = new GroupBy();
@@ -627,7 +626,7 @@
public void testQuery4() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
@@ -647,7 +646,7 @@
public void testQuery5() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
@@ -668,7 +667,7 @@
public void testQuery6() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
@@ -688,7 +687,7 @@
public void testQuery7() {
Select select = new Select();
- select.addSymbol(new AllSymbol());
+ select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
@@ -1042,11 +1041,11 @@
}
public void testAllSymbol() {
- helpTest(new AllSymbol(), "*"); //$NON-NLS-1$
+ helpTest(new MultipleElementSymbol(), "*"); //$NON-NLS-1$
}
public void testAllInGroupSymbol() {
- helpTest(new AllInGroupSymbol("m.g.*"), "m.g.*"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest(new MultipleElementSymbol("m.g"), "m.g.*"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testConstantNull() {
@@ -1851,7 +1850,7 @@
public void testLimit() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -1861,7 +1860,7 @@
public void testLimitWithOffset() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new AllSymbol()));
+ Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
+import junit.framework.TestCase;
+
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.BetweenCriteria;
import org.teiid.query.sql.lang.CompareCriteria;
@@ -48,23 +50,17 @@
import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.AllInGroupSymbol;
-import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.MultipleElementSymbol;
import org.teiid.query.sql.symbol.Symbol;
-import org.teiid.query.sql.visitor.ElementCollectorVisitor;
-import org.teiid.query.sql.visitor.GroupCollectorVisitor;
-import org.teiid.query.sql.visitor.StaticSymbolMappingVisitor;
-import junit.framework.TestCase;
-
public class TestStaticSymbolMappingVisitor extends TestCase {
// ################################## FRAMEWORK ################################
@@ -209,14 +205,14 @@
public void testVisitSelect2() {
Select select = new Select();
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
select.addSymbol(all);
helpTest(select, getSymbolMap());
}
public void testVisitSelect3() {
Select select = new Select();
- AllSymbol all = new AllSymbol();
+ MultipleElementSymbol all = new MultipleElementSymbol();
all.addElementSymbol(exampleElement(true, 0));
select.addSymbol(all);
helpTest(select, getSymbolMap());
@@ -226,7 +222,7 @@
Select select = new Select();
select.addSymbol( new ExpressionSymbol(
"x", new Function("length", new Expression[] {exampleElement(true, 0)})) ); //$NON-NLS-1$ //$NON-NLS-2$
- select.addSymbol( new AllInGroupSymbol("abc.*") ); //$NON-NLS-1$
+ select.addSymbol( new MultipleElementSymbol("abc.*") ); //$NON-NLS-1$
select.addSymbol( exampleElement(true, 1) );
helpTest(select,getSymbolMap());
}
@@ -266,7 +262,7 @@
}
public void testVisitAllSymbol() {
- AllSymbol as = new AllSymbol();
+ MultipleElementSymbol as = new MultipleElementSymbol();
ArrayList elements = new ArrayList();
elements.add(exampleElement(true, 0));
elements.add(exampleElement(true, 1));
@@ -274,8 +270,8 @@
helpTest(as, getSymbolMap());
}
- public void testVisitAllInGroupSymbol() {
- AllInGroupSymbol aigs = new AllInGroupSymbol("OLDG0.*"); //$NON-NLS-1$
+ public void testVisitMultipleElementSymbol() {
+ MultipleElementSymbol aigs = new MultipleElementSymbol("OLDG0.*"); //$NON-NLS-1$
ArrayList elements = new ArrayList();
elements.add(exampleElement(true, 0));
elements.add(exampleElement(true, 1));
@@ -299,9 +295,9 @@
helpTest(f2, getSymbolMap());
}
- public void testMapAllInGroupSymbolName() {
- AllInGroupSymbol aigs = new AllInGroupSymbol("OLDG0.*"); //$NON-NLS-1$
- ArrayList elements = new ArrayList();
+ public void testMapMultipleElementSymbolName() {
+ MultipleElementSymbol aigs = new MultipleElementSymbol("OLDG0"); //$NON-NLS-1$
+ ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
elements.add(exampleElement(true, 0));
elements.add(exampleElement(true, 1));
aigs.setElementSymbols(elements);
@@ -311,7 +307,7 @@
DeepPreOrderNavigator.doVisit(aigs, visitor);
// Check name of all in group symbol
- assertEquals("AllInGroupSymbol name did not get mapped correctly: ", "NEWG0.*", aigs.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("MultipleElementSymbol name did not get mapped correctly: ", "NEWG0.*", aigs.toString()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testExecName() {
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-07-21 16:29:29 UTC (rev 3322)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-07-21 19:28:44 UTC (rev 3323)
@@ -1859,5 +1859,21 @@
@Test public void testNestedAgg() {
helpValidate("SELECT min(g1.e1) filter (where max(e2) = 1) from pm1.g1", new String[] {"MAX(e2)"}, RealMetadataFactory.example1Cached());
}
+
+ @Test public void testWindowFunction() {
+ helpValidate("SELECT e1 from pm1.g1 where row_number() over (order by e2) = 1", new String[] {"ROW_NUMBER() OVER (ORDER BY e2)"}, RealMetadataFactory.example1Cached());
+ }
+
+ @Test public void testWindowFunction1() {
+ helpValidate("SELECT 1 from pm1.g1 having row_number() over (order by e2) = 1", new String[] {"e2", "ROW_NUMBER() OVER (ORDER BY e2)"}, RealMetadataFactory.example1Cached());
+ }
+
+ @Test public void testWindowFunctionWithoutOrdering() {
+ helpValidate("SELECT row_number() over () from pm1.g1", new String[] {"ROW_NUMBER() OVER ()"}, RealMetadataFactory.example1Cached());
+ }
+ @Test public void testWindowFunctionWithNestedOrdering() {
+ helpValidate("SELECT xmlagg(xmlelement(name x, e1) order by e2) over () from pm1.g1", new String[] {"XMLAGG(XMLELEMENT(NAME x, e1) ORDER BY e2)"}, RealMetadataFactory.example1Cached());
+ }
+
}
14 years, 5 months
teiid SVN: r3322 - trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-21 12:29:29 -0400 (Thu, 21 Jul 2011)
New Revision: 3322
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
Log:
TEIID-1678 fix for ordering position
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-07-21 16:29:16 UTC (rev 3321)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-07-21 16:29:29 UTC (rev 3322)
@@ -172,8 +172,6 @@
joinNode.setProperty(NodeConstants.Info.RIGHT_EXPRESSIONS, rightExpressions);
}
- Set<SingleElementSymbol> outputSymbols = new LinkedHashSet<SingleElementSymbol>((List<SingleElementSymbol>)joinNode.getProperty(NodeConstants.Info.OUTPUT_COLS));
-
boolean pushedLeft = insertSort(joinNode.getFirstChild(), leftExpressions, joinNode, metadata, capabilitiesFinder, pushLeft);
if (origExpressionCount == 1
@@ -236,6 +234,8 @@
}
}
+ boolean sort = true;
+
if (sourceNode.getType() == NodeConstants.Types.ACCESS) {
if (distinct || NewCalculateCostUtil.usesKey(sourceNode, expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
@@ -248,13 +248,18 @@
}
return true;
}
+ } else if (sourceNode.getType() == NodeConstants.Types.GROUP) {
+ sourceNode.addAsParent(sortNode);
+ sort = false; // the grouping columns must contain all of the ordering columns
}
if (distinct) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
}
- joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
+ if (sort) {
+ joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
+ }
if (needsCorrection) {
PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
14 years, 5 months
teiid SVN: r3321 - in branches/7.4.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-21 12:29:16 -0400 (Thu, 21 Jul 2011)
New Revision: 3321
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
Log:
TEIID-1678 fix for ordering position
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-07-21 14:16:11 UTC (rev 3320)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-07-21 16:29:16 UTC (rev 3321)
@@ -172,8 +172,6 @@
joinNode.setProperty(NodeConstants.Info.RIGHT_EXPRESSIONS, rightExpressions);
}
- Set<SingleElementSymbol> outputSymbols = new LinkedHashSet<SingleElementSymbol>((List<SingleElementSymbol>)joinNode.getProperty(NodeConstants.Info.OUTPUT_COLS));
-
boolean pushedLeft = insertSort(joinNode.getFirstChild(), leftExpressions, joinNode, metadata, capabilitiesFinder, pushLeft);
if (origExpressionCount == 1
@@ -212,6 +210,10 @@
Set<SingleElementSymbol> orderSymbols = new LinkedHashSet<SingleElementSymbol>(expressions);
PlanNode sourceNode = FrameUtil.findJoinSourceNode(childNode);
+ PlanNode parentGrouping = NodeEditor.findParent(sourceNode, NodeConstants.Types.GROUP, NodeConstants.Types.JOIN);
+ if (parentGrouping != null) {
+ sourceNode = parentGrouping;
+ }
PlanNode joinNode = childNode.getParent();
Set<SingleElementSymbol> outputSymbols = new LinkedHashSet<SingleElementSymbol>((List<SingleElementSymbol>)childNode.getProperty(NodeConstants.Info.OUTPUT_COLS));
@@ -236,6 +238,8 @@
}
}
+ boolean sort = true;
+
if (sourceNode.getType() == NodeConstants.Types.ACCESS) {
if (distinct || NewCalculateCostUtil.usesKey(sourceNode, expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
@@ -248,13 +252,18 @@
}
return true;
}
+ } else if (sourceNode.getType() == NodeConstants.Types.GROUP) {
+ sourceNode.addAsParent(sortNode);
+ sort = false; // the grouping columns must contain all of the ordering columns
}
if (distinct) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
}
- joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
+ if (sort) {
+ joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.SORT_LEFT : NodeConstants.Info.SORT_RIGHT, SortOption.SORT);
+ }
if (needsCorrection) {
PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-07-21 14:16:11 UTC (rev 3320)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2011-07-21 16:29:16 UTC (rev 3321)
@@ -364,7 +364,7 @@
List<String> expectedQueries = new ArrayList<String>(6);
for (int i = 0; i < 3; i++) {
expectedQueries.add("SELECT g_0.id AS c_0, g_0.first AS c_1, g_0.last AS c_2 FROM CustomerMaster.Customers AS g_0 WHERE g_0.first = 'Miles' ORDER BY c_0"); //$NON-NLS-1$
- expectedQueries.add("SELECT g_0.id AS c_0, g_0.amount AS c_1 FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100 ORDER BY c_0"); //$NON-NLS-1$
+ expectedQueries.add("SELECT g_0.id, g_0.amount FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100"); //$NON-NLS-1$
}
assertEquals(expectedQueries, dataManager.getQueries());
14 years, 5 months
teiid SVN: r3320 - in branches/7.4.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-21 10:16:11 -0400 (Thu, 21 Jul 2011)
New Revision: 3320
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
Log:
TEIID-1677 ensuring that exists does not unnest by default
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-21 14:08:10 UTC (rev 3319)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java 2011-07-21 14:16:11 UTC (rev 3320)
@@ -419,11 +419,11 @@
result.type = crit.getClass();
result.not = exists.isNegated();
//the correlations can only be in where (if no group by or aggregates) or having
- result.query = (Query)exists.getCommand();
result.mergeJoin = exists.getSubqueryHint().isMergeJoin();
if (!UNNEST && !result.mergeJoin) {
return result;
}
+ result.query = (Query)exists.getCommand();
}
return result;
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-21 14:08:10 UTC (rev 3319)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2011-07-21 14:16:11 UTC (rev 3320)
@@ -757,6 +757,7 @@
}
@Test public void testSubqueryRewriteToJoinDistinct() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1)", "SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example1Cached());
}
@@ -764,6 +765,7 @@
* Agg does not depend on cardinality
*/
@Test public void testSubqueryRewriteToJoinGroupBy() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select max(e1) from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1) group by e2", "SELECT MAX(e1) FROM pm1.g1 AS x, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1 GROUP BY e2", RealMetadataFactory.example1Cached());
}
@@ -775,6 +777,7 @@
}
@Test public void testSubqueryRewriteToJoin() throws Exception {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT pm1.g1.e1 FROM pm1.g1) AS X__1 WHERE pm3.g1.e1 = X__1.e1", RealMetadataFactory.example4());
}
@@ -914,6 +917,7 @@
* Same as above, but the source is much larger, so a semi-join is favorable
*/
@Test public void testSemiJoinExistsCosting() {
+ System.setProperty(RuleMergeCriteria.UNNEST_DEFAULT, Boolean.TRUE.toString());
ProcessorPlan plan = helpPlan("Select e1 from pm2.g2 as o where not exists (select 1 from pm3.g1 where e1 = o.e1 having o.e2 = count(e2))", RealMetadataFactory.example4(), //$NON-NLS-1$
new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm2.g2 AS g_0 ORDER BY c_0, c_1" }); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
14 years, 5 months
teiid SVN: r3319 - in branches/7.4.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-21 10:08:10 -0400 (Thu, 21 Jul 2011)
New Revision: 3319
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1676 fix for cardinality dependent aggregation
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-07-21 03:40:15 UTC (rev 3318)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2011-07-21 14:08:10 UTC (rev 3319)
@@ -645,7 +645,16 @@
Set<PlanNode> possibleTargetNodes = new LinkedHashSet<PlanNode>(aggregateMap.keySet());
possibleTargetNodes.addAll(groupingMap.keySet());
-
+ for (Map.Entry<PlanNode, List<AggregateSymbol>> entry : aggregateMap.entrySet()) {
+ if (AggregateSymbol.areAggregatesCardinalityDependent(entry.getValue())) {
+ //can't change the cardinality on the other side of the join -
+ //unless it's a 1-1 join, in which case this optimization isn't needed
+ //TODO: make a better choice if there are multiple targets
+ possibleTargetNodes.clear();
+ possibleTargetNodes.add(entry.getKey());
+ break;
+ }
+ }
for (PlanNode planNode : possibleTargetNodes) {
Set<SingleElementSymbol> stagedGroupingSymbols = new LinkedHashSet<SingleElementSymbol>();
List<AggregateSymbol> aggregates = aggregateMap.get(planNode);
@@ -855,6 +864,10 @@
continue;
}
+ if (originatingNode.getType() != NodeConstants.Types.ACCESS) {
+ continue;
+ }
+
if (aggs && ((AggregateSymbol)aggregateSymbol).isDistinct()) {
//TODO: support distinct
continue;
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2011-07-21 03:40:15 UTC (rev 3318)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2011-07-21 14:08:10 UTC (rev 3319)
@@ -69,7 +69,7 @@
String sql = "SELECT a12.intkey AS REGION_NBR, SUM(a11.intnum) AS WJXBFS1 FROM bqt1.smalla AS a11 INNER JOIN bqt2.smalla AS a12 ON a11.stringkey = a12.stringkey WHERE a11.stringkey = 0 GROUP BY a12.intkey"; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), null, capFinder,
- new String[] {"SELECT SUM(a11.intnum) FROM bqt1.smalla AS a11 WHERE a11.stringkey = '0' HAVING COUNT(*) > 0", "SELECT a12.intkey FROM bqt2.smalla AS a12 WHERE a12.stringkey = '0' group by a12.intkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT SUM(a11.intnum) FROM bqt1.smalla AS a11 WHERE a11.stringkey = '0' HAVING COUNT(*) > 0", "SELECT a12.intkey FROM bqt2.smalla AS a12 WHERE a12.stringkey = '0'"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -203,7 +203,7 @@
String sql = "select sum(a11.intnum) Profit, (sum(a11.intnum) / sum(a11.floatnum)) WJXBFS2 from bqt1.smalla a11 join bqt2.smallb a12 on a11.intkey=a12.intkey group by a12.intkey"; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), null, capFinder,
- new String[] {"SELECT g_0.intkey, SUM(g_0.intnum), SUM(g_0.floatnum) FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey", "SELECT g_0.intkey FROM bqt2.smallb AS g_0 GROUP BY g_0.intkey"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.intkey, SUM(g_0.intnum), SUM(g_0.floatnum) FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey", "SELECT g_0.intkey FROM bqt2.smallb AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -298,7 +298,7 @@
String sql = "SELECT avg(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder,
- new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2", "SELECT g_0.e3, g_0.e1, SUM(g_0.e2), COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0", "SELECT g_0.e3, g_0.e1, SUM(g_0.e2), COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -328,7 +328,7 @@
String sql = "SELECT stddev_pop(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder,
- new String[] {"SELECT g_0.e3 AS c_0, g_0.e1 AS c_1, COUNT(g_0.e2) AS c_2, SUM(power(g_0.e2, 2)) AS c_3, SUM(g_0.e2) AS c_4 FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1 ORDER BY c_0", "SELECT g_0.e3 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2 ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.e3 AS c_0, g_0.e1 AS c_1, COUNT(g_0.e2) AS c_2, SUM(power(g_0.e2, 2)) AS c_3, SUM(g_0.e2) AS c_4 FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1 ORDER BY c_0", "SELECT g_0.e3 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -357,7 +357,7 @@
String sql = "SELECT count(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder,
- new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2", "SELECT g_0.e3, g_0.e1, COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0", "SELECT g_0.e3, g_0.e1, COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -767,8 +767,8 @@
ProcessorPlan plan = helpPlan(sql,
metadata,
null, capFinder,
- new String[] {"SELECT c2, c1, c0 FROM db2model.DB2TABLE", //$NON-NLS-1$
- "SELECT DISTINCT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"}, //$NON-NLS-1$
+ new String[] {"SELECT g_0.b2 AS c_0, g_0.b0 AS c_1 FROM oraclemodel.OraTable AS g_0 ORDER BY c_0",
+ "SELECT g_0.c2, g_0.c1, g_0.c0 FROM db2model.DB2TABLE AS g_0"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, new int[] {
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2011-07-21 03:40:15 UTC (rev 3318)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2011-07-21 14:08:10 UTC (rev 3319)
@@ -360,9 +360,9 @@
List[] expected = new List[] {
Arrays.asList(null, "cc"),
Arrays.asList(0.0, "bb"),
- Arrays.asList(1.0, null),
- Arrays.asList(2.0, "aa"),
- Arrays.asList(7.0, "aa")
+ Arrays.asList(2.0, null),
+ Arrays.asList(21.0, "aa"),
+ Arrays.asList(24.0, "aa")
};
// Construct data manager with data
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-07-21 03:40:15 UTC (rev 3318)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-07-21 14:08:10 UTC (rev 3319)
@@ -360,7 +360,7 @@
Properties props = new Properties();
props.setProperty("soap_host", "my.host.com"); //$NON-NLS-1$ //$NON-NLS-2$
props.setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
- CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
context.setProcessorBatchSize(BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
context.setConnectorBatchSize(BufferManager.DEFAULT_CONNECTOR_BATCH_SIZE);
context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
14 years, 5 months
teiid SVN: r3318 - branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-07-20 23:40:15 -0400 (Wed, 20 Jul 2011)
New Revision: 3318
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
Log:
ensuring that node properties are consistently ordered
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-07-20 03:27:02 UTC (rev 3317)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/MappingNode.java 2011-07-21 03:40:15 UTC (rev 3318)
@@ -25,8 +25,8 @@
import java.io.PrintStream;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -214,7 +214,7 @@
*/
public Map<MappingNodeConstants.Properties, Object> getNodeProperties(){
if(nodeProperties == null) {
- nodeProperties = new HashMap<MappingNodeConstants.Properties, Object>();
+ nodeProperties = new LinkedHashMap<MappingNodeConstants.Properties, Object>();
}
return nodeProperties;
}
14 years, 5 months