teiid SVN: r2958 - in trunk/engine/src: main/java/org/teiid/dqp/internal/process/multisource and 10 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-03-02 15:28:34 -0500 (Wed, 02 Mar 2011)
New Revision: 2958
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourceMetadataWrapper.java
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java
trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-1489 fix for getting the design time metadata for resolving views/procedures
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -196,14 +196,16 @@
throw new TeiidComponentException(QueryPlugin.Util.getString("DQPCore.Unable_to_load_metadata_for_VDB_name__{0},_version__{1}", this.vdbName, this.vdbVersion)); //$NON-NLS-1$
}
- this.metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
-
// Check for multi-source models and further wrap the metadata interface
Set<String> multiSourceModelList = workContext.getVDB().getMultiSourceModelNames();
if(multiSourceModelList != null && multiSourceModelList.size() > 0) {
this.multiSourceModels = multiSourceModelList;
this.metadata = new MultiSourceMetadataWrapper(this.metadata, this.multiSourceModels);
}
+
+ TempMetadataAdapter tma = new TempMetadataAdapter(metadata, new TempMetadataStore());
+ tma.setSession(true);
+ this.metadata = tma;
}
protected void createCommandContext() throws QueryValidatorException {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourceMetadataWrapper.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourceMetadataWrapper.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourceMetadataWrapper.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -352,5 +352,10 @@
}
return false;
}
+
+ @Override
+ public QueryMetadataInterface getDesignTimeMetadata() {
+ return new MultiSourceMetadataWrapper(actualMetadata.getDesignTimeMetadata(), multiSourceModels);
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -518,5 +518,15 @@
public boolean isMultiSourceElement(Object elementId) {
return false;
}
+
+ @Override
+ public QueryMetadataInterface getDesignTimeMetadata() {
+ return this;
+ }
+
+ @Override
+ public boolean hasProcedure(String name) throws TeiidComponentException {
+ return false;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -383,5 +383,15 @@
public boolean isMultiSourceElement(Object elementId) throws QueryMetadataException, TeiidComponentException {
return actualMetadata.isMultiSourceElement(elementId);
}
+
+ @Override
+ public QueryMetadataInterface getDesignTimeMetadata() {
+ return actualMetadata.getDesignTimeMetadata();
+ }
+
+ @Override
+ public boolean hasProcedure(String name) throws TeiidComponentException {
+ return actualMetadata.hasProcedure(name);
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -684,4 +684,8 @@
boolean isMultiSource(Object modelId) throws QueryMetadataException, TeiidComponentException;
boolean isMultiSourceElement(Object elementId) throws QueryMetadataException, TeiidComponentException;
+
+ QueryMetadataInterface getDesignTimeMetadata();
+
+ boolean hasProcedure(String name) throws TeiidComponentException;
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -58,6 +58,7 @@
private TempMetadataStore tempStore;
private Map materializationTables;
private Map queryNodes;
+ private boolean session;
public TempMetadataAdapter(QueryMetadataInterface metadata, TempMetadataStore tempStore) {
super(metadata);
@@ -69,8 +70,23 @@
this.tempStore = tempStore;
this.materializationTables = materializationTables;
this.queryNodes = queryNodes;
- }
+ }
+ public boolean isSession() {
+ return session;
+ }
+
+ public void setSession(boolean session) {
+ this.session = session;
+ }
+
+ public QueryMetadataInterface getDesignTimeMetadata() {
+ if (isSession()) {
+ return this.actualMetadata.getDesignTimeMetadata();
+ }
+ return new TempMetadataAdapter(this.actualMetadata.getDesignTimeMetadata(), tempStore, materializationTables, queryNodes);
+ }
+
public TempMetadataStore getMetadataStore() {
return this.tempStore;
}
@@ -290,8 +306,11 @@
throws TeiidComponentException, QueryMetadataException {
// check if any dynamic materialization tables are defined
- if (this.materializationTables != null && this.materializationTables.containsKey(groupID)) {
- return this.materializationTables.get(groupID);
+ if (this.materializationTables != null) {
+ Object result = this.materializationTables.get(groupID);
+ if (result != null) {
+ return result;
+ }
}
if(groupID instanceof TempMetadataID) {
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -158,6 +158,13 @@
}
}
+ private TransformationMetadata(final CompositeMetadataStore store, FunctionLibrary functionLibrary) {
+ ArgCheck.isNotNull(store);
+ this.store = store;
+ this.vdbEntries = Collections.emptyMap();
+ this.functionLibrary = functionLibrary;
+ }
+
//==================================================================================
// I N T E R F A C E M E T H O D S
//==================================================================================
@@ -286,11 +293,31 @@
throw createInvalidRecordTypeException(elementID);
}
}
+
+ public boolean hasProcedure(String name) throws TeiidComponentException {
+ try {
+ return getStoredProcedureInfoForProcedure(name) != null;
+ } catch (QueryMetadataException e) {
+ return false;
+ }
+ }
- public StoredProcedureInfo getStoredProcedureInfoForProcedure(final String fullyQualifiedProcedureName)
+ public StoredProcedureInfo getStoredProcedureInfoForProcedure(final String name)
throws TeiidComponentException, QueryMetadataException {
- ArgCheck.isNotEmpty(fullyQualifiedProcedureName);
- String lowerGroupName = fullyQualifiedProcedureName.toLowerCase();
+ StoredProcedureInfo result = getStoredProcInfoDirect(name);
+
+ if (result == null) {
+ throw new QueryMetadataException(name+NOT_EXISTS_MESSAGE);
+ }
+
+ return result;
+ }
+
+ private StoredProcedureInfo getStoredProcInfoDirect(
+ final String name)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(name);
+ String lowerGroupName = name.toLowerCase();
Collection<StoredProcedureInfo> results = this.procedureCache.get(lowerGroupName);
if (results == null) {
@@ -352,20 +379,15 @@
for (StoredProcedureInfo storedProcedureInfo : results) {
Schema schema = (Schema)storedProcedureInfo.getModelID();
- if(fullyQualifiedProcedureName.equalsIgnoreCase(storedProcedureInfo.getProcedureCallableName()) || vdbMetaData == null || vdbMetaData.isVisible(schema.getName())){
+ if(name.equalsIgnoreCase(storedProcedureInfo.getProcedureCallableName()) || vdbMetaData == null || vdbMetaData.isVisible(schema.getName())){
if (result != null) {
- throw new QueryMetadataException(QueryPlugin.Util.getString("ambiguous_procedure", fullyQualifiedProcedureName)); //$NON-NLS-1$
+ throw new QueryMetadataException(QueryPlugin.Util.getString("ambiguous_procedure", name)); //$NON-NLS-1$
}
result = storedProcedureInfo;
}
}
-
- if (result == null) {
- throw new QueryMetadataException(fullyQualifiedProcedureName+NOT_EXISTS_MESSAGE);
- }
-
- return result;
- }
+ return result;
+ }
/**
* Method to convert the parameter type returned from a ProcedureParameterRecord
@@ -1085,4 +1107,9 @@
Table table = (Table)metadataID;
return table.getPrimaryKey();
}
+
+ @Override
+ public QueryMetadataInterface getDesignTimeMetadata() {
+ return new TransformationMetadata(store, functionLibrary);
+ }
}
\ No newline at end of file
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-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -83,7 +83,7 @@
if (query == null) {
try {
query = QueryParser.getQueryParser().parseCommand(queryNode.getQuery());
- QueryResolver.resolveWithBindingMetadata(query, env.getGlobalMetadata(), queryNode, true);
+ QueryResolver.resolveWithBindingMetadata(query, env.getGlobalMetadata().getDesignTimeMetadata(), queryNode, true);
} catch (TeiidException e) {
throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0054", new Object[]{queryNode.getGroupName(), queryNode.getQuery()})); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -22,7 +22,7 @@
package org.teiid.query.processor.proc;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_SQL;
+import static org.teiid.query.analysis.AnalysisRecord.*;
import java.util.Collections;
import java.util.HashMap;
@@ -162,7 +162,7 @@
parentProcCommand.getVirtualGroup(), metadata);
}
- QueryResolver.resolveCommand(command, metadata);
+ QueryResolver.resolveCommand(command, metadata.getDesignTimeMetadata());
validateDynamicCommand(procEnv, command);
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -98,7 +98,7 @@
try {
subCommand = parser.parseUpdateProcedure(plan);
} catch(QueryParserException e) {
- throw new QueryResolverException(e, "ERR.015.008.0045", QueryPlugin.Util.getString("ERR.015.008.0045", group)); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new QueryResolverException(e, "ERR.015.008.0045", QueryPlugin.Util.getString("ERR.015.008.0045", group, procCommand.getClass().getSimpleName())); //$NON-NLS-1$ //$NON-NLS-2$
}
return subCommand;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -119,7 +119,7 @@
cupCommand.setProjectedSymbols(proc.getProjectedSymbols());
}
}
- resolveCommand(command, proc.getGroup(), proc.getType(), metadata);
+ resolveCommand(command, proc.getGroup(), proc.getType(), metadata.getDesignTimeMetadata());
return command;
}
@@ -427,6 +427,7 @@
String cacheString, QueryMetadataInterface qmi) throws TeiidComponentException,
QueryMetadataException, QueryResolverException,
QueryValidatorException {
+ qmi = qmi.getDesignTimeMetadata();
Command result = (Command)qmi.getFromMetadataCache(virtualGroup.getMetadataID(), "transformation/" + cacheString); //$NON-NLS-1$
if (result != null) {
result = (Command)result.clone();
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -71,6 +71,10 @@
if(!exitsingGroups.isEmpty()) {
throw new QueryResolverException(QueryPlugin.Util.getString("TempTableResolver.table_already_exists", group.getName())); //$NON-NLS-1$
}
+ if (metadata.getMetadata().hasProcedure(group.getName())) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("TempTableResolver.table_already_exists", group.getName())); //$NON-NLS-1$
+ }
+
//now we will be more specific for temp groups
TempMetadataID id = metadata.getMetadataStore().getTempGroupID(group.getName());
if (id != null && !metadata.isTemporaryTable(id)) {
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-03-02 20:28:34 UTC (rev 2958)
@@ -114,7 +114,7 @@
ERR.015.008.0041= Expected value of type ''{0}'' but ''{1}'' is of type ''{2}'' and no implicit conversion is available.
ERR.015.008.0042= Element ''{0}'' in ORDER BY is ambiguous and may refer to more than one element of SELECT clause.
ERR.015.008.0043= Element ''{0}'' in ORDER BY was not found in SELECT clause.
-ERR.015.008.0045= Failed parsing insert plan for {0}
+ERR.015.008.0045= Failed parsing {1} plan for {0}
ERR.015.008.0046= The symbol {0} may only be used once in the FROM clause.
ERR.015.008.0047= The symbol {0} refers to a group not defined in the FROM clause.
ERR.015.008.0049= Bindings must be specified
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -52,8 +52,9 @@
private DQPCore core;
@Before public void setUp() throws Exception {
- DQPWorkContext context = FakeMetadataFactory.buildWorkContext(FakeMetadataFactory.exampleBQTCached(), FakeMetadataFactory.exampleBQTVDB());
+ DQPWorkContext context = FakeMetadataFactory.buildWorkContext(FakeMetadataFactory.exampleBQT());
context.getVDB().getModel("BQT3").setVisible(false); //$NON-NLS-1$
+ context.getVDB().getModel("VQT").setVisible(false); //$NON-NLS-1$
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
@@ -159,6 +160,14 @@
}
/**
+ * Ensures that VQT visibility does not affect the view query
+ */
+ @Test public void testViewVisibility() throws Exception {
+ String sql = "SELECT * FROM VQT.SmallA_2589g"; //$NON-NLS-1$
+ helpExecute(sql, "a"); //$NON-NLS-1$
+ }
+
+ /**
* Tests whether an exception result is sent when an exception occurs
* @since 4.3
*/
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -22,8 +22,7 @@
package org.teiid.query.processor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
@@ -66,6 +65,7 @@
@Before public void setUp() {
tempStore = new TempTableStore("1"); //$NON-NLS-1$
metadata = new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), tempStore.getMetadataStore());
+ metadata.setSession(true);
FakeDataManager fdm = new FakeDataManager();
TestProcessor.sampleData1(fdm);
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
@@ -286,7 +286,16 @@
execute("create local temporary table x (e1 serial, e2 integer not null, primary key (e1))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
execute("insert into x (e2) values ((select null))", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
}
-
+
+ /**
+ * If the session metadata is still visible, then the procedure will fail due to the conflicting
+ * definitions of temp_table
+ */
+ @Test public void testSessionResolving() throws Exception {
+ execute("create local temporary table temp_table (column1 integer)", new List[] {Arrays.asList(0)});
+ execute("exec pm1.vsp60()", new List[] {Arrays.asList("First"), Arrays.asList("Second"), Arrays.asList("Third")});
+ }
+
private void sampleTable() throws Exception {
execute("create local temporary table x (e1 string, e2 integer, primary key (e1, e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
execute("insert into x (e2, e1) values (3, 'b')", new List[] {Arrays.asList(1)}); //$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-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -2338,6 +2338,11 @@
String sql = "CREATE LOCAL TEMPORARY TABLE pm1.g1 (column1 string)"; //$NON-NLS-1$
helpResolveException(sql, "Cannot create temporary table \"pm1.g1\". Local temporary tables must be created with unqualified names."); //$NON-NLS-1$
}
+
+ @Test public void testProcedureConflict() {
+ String sql = "create local temporary table MMSP6 (e1 string, e2 integer)"; //$NON-NLS-1$
+ helpResolveException(sql, RealMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
+ }
@Test public void testCreatePk() {
String sql = "CREATE LOCAL TEMPORARY TABLE foo (column1 string, column2 integer, primary key (column1, column2))"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -83,6 +83,10 @@
return CACHED_AGGREGATES;
}
+ public static DQPWorkContext buildWorkContext(TransformationMetadata metadata) {
+ return buildWorkContext(metadata, metadata.getVdbMetaData());
+ }
+
public static DQPWorkContext buildWorkContext(QueryMetadataInterface metadata, VDBMetaData vdb) {
DQPWorkContext workContext = new DQPWorkContext();
SessionMetadata session = new SessionMetadata();
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-03-02 19:37:19 UTC (rev 2957)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2011-03-02 20:28:34 UTC (rev 2958)
@@ -117,7 +117,7 @@
QueryNode vqtn2589f = new QueryNode("VQT.SmallA_2589f", "SELECT * FROM VQT.SmallA_2589"); //$NON-NLS-1$ //$NON-NLS-2$
Table vqtg2589f = createVirtualGroup("SmallA_2589f", vqt, vqtn2589f); //$NON-NLS-1$
- QueryNode vqtn2589g = new QueryNode("VQT.SmallA_2589g", "SELECT * FROM VQT.SmallA_2589b"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode vqtn2589g = new QueryNode("VQT.SmallA_2589g", "SELECT * FROM SmallA_2589b"); //$NON-NLS-1$ //$NON-NLS-2$
Table vqtg2589g = createVirtualGroup("SmallA_2589g", vqt, vqtn2589g); //$NON-NLS-1$
QueryNode vqtn2589h = new QueryNode("VQT.SmallA_2589h", "SELECT VQT.SmallA_2589.* FROM VQT.SmallA_2589 INNER JOIN BQT1.SmallB ON VQT.SmallA_2589.StringKey = SmallB.StringKey"); //$NON-NLS-1$ //$NON-NLS-2$
13 years, 10 months
teiid SVN: r2957 - trunk/client/src/main/java/org/teiid/jdbc.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-03-02 14:37:19 -0500 (Wed, 02 Mar 2011)
New Revision: 2957
Modified:
trunk/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
Log:
TEIID-1481: adding parserURL to connect method to grab the extra properties from the URL.
Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidDriver.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidDriver.java 2011-03-02 16:26:09 UTC (rev 2956)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidDriver.java 2011-03-02 19:37:19 UTC (rev 2957)
@@ -93,6 +93,7 @@
//don't modify the original
info = PropertiesUtils.clone(info);
}
+ parseURL(url, info);
if (conn == ConnectionType.Embedded) {
return EmbeddedProfile.connect(url, info);
}
13 years, 10 months
teiid SVN: r2956 - in trunk/engine/src: main/java/org/teiid/query/resolver/util and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-03-02 11:26:09 -0500 (Wed, 02 Mar 2011)
New Revision: 2956
Removed:
trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
Log:
TEIID-1483 consolidating resolving code with designer by refining the symbol optimization logic
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -29,11 +29,14 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.Assertion;
import org.teiid.dqp.internal.process.Request;
import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
@@ -445,6 +448,18 @@
QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
+
+ //ensure that null types match the view
+ List<ElementSymbol> symbols = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
+ List<SingleElementSymbol> projectedSymbols = result.getProjectedSymbols();
+ Assertion.assertTrue(symbols.size() == projectedSymbols.size(), "View " + virtualGroup + " does not have the correct number of projected symbols"); //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < projectedSymbols.size(); i++) {
+ SingleElementSymbol projectedSymbol = projectedSymbols.get(i);
+ if (projectedSymbol.getType() != DataTypeManager.DefaultDataClasses.NULL) {
+ continue;
+ }
+ ResolverUtil.setSymbolType(projectedSymbol, symbols.get(i).getType());
+ }
qmi.addToMetadataCache(virtualGroup.getMetadataID(), "transformation/" + cacheString, result.clone()); //$NON-NLS-1$
}
return result;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -56,6 +56,7 @@
import org.teiid.query.optimizer.relational.rules.RuleChooseJoinStrategy;
import org.teiid.query.optimizer.relational.rules.RuleRaiseAccess;
import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.FromClause;
@@ -637,38 +638,41 @@
if(!DataTypeManager.DefaultDataClasses.NULL.equals(symbol.getType()) && symbol.getType() != null) {
continue;
}
- if(symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
- Class replacement = DataTypeManager.DefaultDataClasses.STRING;
-
- if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
- ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
- Expression expr = exprSymbol.getExpression();
-
- if(expr instanceof Constant) {
- exprSymbol.setExpression(new Constant(null, replacement));
- } else if (expr instanceof AbstractCaseExpression) {
- ((AbstractCaseExpression)expr).setType(replacement);
- } else if (expr instanceof ScalarSubquery) {
- ((ScalarSubquery)expr).setType(replacement);
- } else {
- try {
- ResolverUtil.setDesiredType(expr, replacement, symbol);
- } catch (QueryResolverException e) {
- //cannot happen
- }
- }
- } else if(symbol instanceof ElementSymbol) {
- ElementSymbol elementSymbol = (ElementSymbol)symbol;
- Class elementType = elementSymbol.getType();
- if(elementType != null && elementType.equals(DataTypeManager.DefaultDataClasses.NULL)) {
- elementSymbol.setType(replacement);
- }
- }
+ setSymbolType(symbol, DataTypeManager.DefaultDataClasses.STRING);
}
}
+
+ public static void setSymbolType(SingleElementSymbol symbol,
+ Class<?> replacement) {
+ if(symbol instanceof AliasSymbol) {
+ symbol = ((AliasSymbol)symbol).getSymbol();
+ }
+ if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
+ ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
+ Expression expr = exprSymbol.getExpression();
+
+ if(expr instanceof Constant) {
+ exprSymbol.setExpression(new Constant(null, replacement));
+ } else if (expr instanceof AbstractCaseExpression) {
+ ((AbstractCaseExpression)expr).setType(replacement);
+ } else if (expr instanceof ScalarSubquery) {
+ ((ScalarSubquery)expr).setType(replacement);
+ } else {
+ try {
+ ResolverUtil.setDesiredType(expr, replacement, symbol);
+ } catch (QueryResolverException e) {
+ //cannot happen
+ }
+ }
+ } else if(symbol instanceof ElementSymbol) {
+ ElementSymbol elementSymbol = (ElementSymbol)symbol;
+ Class elementType = elementSymbol.getType();
+ if(elementType != null && elementType.equals(DataTypeManager.DefaultDataClasses.NULL)) {
+ elementSymbol.setType(replacement);
+ }
+ }
+ }
/**
*
@@ -723,7 +727,7 @@
}
- private static boolean nameMatchesGroup(String groupContext,
+ public static boolean nameMatchesGroup(String groupContext,
String fullName) {
//if there is a name match, make sure that it is the full name or a proper qualifier
if (fullName.endsWith(groupContext)) {
@@ -1091,5 +1095,16 @@
}
return result;
}
+
+ /**
+ * This method will convert all elements in a command to their fully qualified name.
+ * @param command Command to convert
+ */
+ public static void fullyQualifyElements(Command command) {
+ Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(command, false, true);
+ for (ElementSymbol element : elements) {
+ element.setDisplayFullyQualified(true);
+ }
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -70,6 +70,7 @@
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.ElementSymbol.DisplayMode;
public class ResolverVisitor extends LanguageVisitor {
@@ -84,12 +85,23 @@
}
}
+ private static ThreadLocal<Boolean> determinePartialName = new ThreadLocal<Boolean>() {
+ protected Boolean initialValue() {
+ return false;
+ }
+ };
+
+ public static void setFindShortName(boolean enabled) {
+ determinePartialName.set(enabled);
+ }
+
private Collection<GroupSymbol> groups;
private GroupContext externalContext;
protected QueryMetadataInterface metadata;
private TeiidComponentException componentException;
private QueryResolverException resolverException;
private Map<Function, QueryResolverException> unresolvedFunctions;
+ private boolean findShortName;
/**
* Constructor for ResolveElementsVisitor.
@@ -100,6 +112,7 @@
this.groups = internalGroups;
this.externalContext = externalContext;
this.metadata = metadata;
+ this.findShortName = determinePartialName.get();
}
public void setGroups(Collection<GroupSymbol> groups) {
@@ -110,21 +123,23 @@
try {
resolveElementSymbol(obj);
} catch(QueryMetadataException e) {
- handleUnresolvedElement(obj, e.getMessage());
+ handleException(handleUnresolvedElement(obj, e.getMessage()));
} catch(TeiidComponentException e) {
handleException(e);
- }
+ } catch (QueryResolverException e) {
+ handleException(e);
+ }
}
- private void handleUnresolvedElement(ElementSymbol symbol, String description) {
+ private QueryResolverException handleUnresolvedElement(ElementSymbol symbol, String description) {
UnresolvedSymbolDescription usd = new UnresolvedSymbolDescription(symbol.toString(), description);
QueryResolverException e = new QueryResolverException(usd.getDescription());
e.setUnresolvedSymbols(Arrays.asList(usd));
- handleException(e);
+ return e;
}
private void resolveElementSymbol(ElementSymbol elementSymbol)
- throws QueryMetadataException, TeiidComponentException {
+ throws TeiidComponentException, QueryResolverException {
// already resolved
if(elementSymbol.getMetadataID() != null) {
@@ -139,9 +154,25 @@
String elementShortName = metadata.getShortElementName(potentialID);
if (groupContext != null) {
groupContext = groupContext.toUpperCase();
+ try {
+ if (findShortName && internalResolveElementSymbol(elementSymbol, null, elementShortName, groupContext)) {
+ elementSymbol.setDisplayMode(DisplayMode.SHORT_OUTPUT_NAME);
+ return;
+ }
+ } catch (QueryResolverException e) {
+ //ignore
+ } catch (QueryMetadataException e) {
+ //ignore
+ }
}
- boolean isExternal = false;
+ internalResolveElementSymbol(elementSymbol, groupContext, elementShortName, null);
+ }
+
+ private boolean internalResolveElementSymbol(ElementSymbol elementSymbol,
+ String groupContext, String elementShortName, String expectedGroupContext)
+ throws TeiidComponentException, QueryResolverException {
+ boolean isExternal = false;
boolean groupMatched = false;
GroupContext root = null;
@@ -183,14 +214,16 @@
resolveAgainstGroups(shortCanonicalName, matchedGroups, matches);
if (matches.size() > 1) {
- if (isExternal && matches.size() == 2
- && ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))
- || (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)))) {
- matches.remove();
- } else {
- handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
- return;
+ if (isExternal && matches.size() == 2) {
+ if ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))) {
+ matches.removeLast();
+ break;
+ } else if (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)) {
+ matches.removeFirst();
+ break;
+ }
}
+ throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
}
if (matches.size() == 1) {
@@ -204,11 +237,9 @@
if (matches.isEmpty()) {
if (groupMatched) {
- handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0054", elementSymbol)); //$NON-NLS-1$
- } else {
- handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0051", elementSymbol)); //$NON-NLS-1$
+ throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0054", elementSymbol)); //$NON-NLS-1$
}
- return;
+ throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0051", elementSymbol)); //$NON-NLS-1$
}
ElementMatch match = matches.getFirst();
@@ -216,6 +247,9 @@
ElementSymbol resolvedSymbol = match.element;
GroupSymbol resolvedGroup = match.group;
String oldName = elementSymbol.getOutputName();
+ if (expectedGroupContext != null && !ResolverUtil.nameMatchesGroup(expectedGroupContext, resolvedGroup.getCanonicalName())) {
+ return false;
+ }
if (isExternal //convert input to inputs
&& isScalar(resolvedSymbol, ProcedureReservedWords.INPUT)) {
resolvedSymbol = new ElementSymbol(ProcedureReservedWords.INPUTS + ElementSymbol.SEPARATOR + elementShortName);
@@ -234,7 +268,8 @@
elementSymbol.setGroupSymbol(resolvedGroup);
elementSymbol.setName(resolvedSymbol.getName());
elementSymbol.setOutputName(oldName);
- }
+ return true;
+ }
private boolean isScalar(ElementSymbol resolvedSymbol, String group) throws QueryMetadataException, TeiidComponentException {
return metadata.isScalarGroup(resolvedSymbol.getGroupSymbol().getMetadataID())
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -1,253 +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.util;
-
-import java.util.*;
-
-import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.query.metadata.*;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.visitor.CommandCollectorVisitor;
-import org.teiid.query.sql.visitor.ElementCollectorVisitor;
-import org.teiid.query.sql.visitor.GroupCollectorVisitor;
-
-
-/**
- * <p>The ElementSymbolOptimizer can be used to modify the appearance of the elements in a command. The operations will
- * be performed on the command and all embedded subcommands, but not any further than that. This
- * class should only be used on commands that have been resolved, as unresolved commands
- * do not contain enough metadata to determine the proper fully qualified or optimized
- * element form.</p>
- */
-public class ElementSymbolOptimizer {
-
- /**
- * Can't construct
- * @see java.lang.Object#Object()
- */
- private ElementSymbolOptimizer() {
- }
-
- /**
- * Get a command and all it's embedded commands recursively
- * @param command Command to start from
- * @param commandList Collected commands
- */
- private static void getExposedCommands(Command command, List commandList) {
- // Handle Unions
- if (command instanceof SetQuery){
- SetQuery setQuery = (SetQuery)command;
- for (QueryCommand setQueryCommand : setQuery.getQueryCommands()) {
- getExposedCommands(setQueryCommand, commandList);
- }
- } else {
- commandList.add(command);
-
- List subCommands = CommandCollectorVisitor.getCommands(command);
- if(subCommands != null && subCommands.size() > 0) {
- for(int i=0; i<subCommands.size(); i++) {
- Command subCommand = (Command) subCommands.get(i);
- getExposedCommands(subCommand, commandList);
- }
- }
- }
- }
-
- /**
- * This method will convert all elements in a command to their fully qualified name.
- * @param command Command to convert
- */
- public static void fullyQualifyElements(Command command) {
- // Determine commands to fully qualify
- List commandsToQualify = new ArrayList();
- getExposedCommands(command, commandsToQualify);
-
- for(int i=0; i<commandsToQualify.size(); i++) {
- Command currentCommand = (Command) commandsToQualify.get(i);
- Collection elements = ElementCollectorVisitor.getElements(currentCommand, false);
- Iterator elementIter = elements.iterator();
- while(elementIter.hasNext()) {
- ElementSymbol element = (ElementSymbol) elementIter.next();
-
- fullyQualifyElement(element);
- }
- }
- }
-
- /**
- * Method fullyQualifyElement.
- * @param element
- */
- private static void fullyQualifyElement(ElementSymbol element) {
- element.setDisplayFullyQualified(true);
- }
-
-
-
- /**
- * This method will convert all elements in a command to their shortest possible unambiguous name.
- * @param command Command to convert
- */
- public static void optimizeElements(Command command, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException{
-
- // Determine commands to optimize
- List commandsToOptimize = new ArrayList();
- getExposedCommands(command, commandsToOptimize);
-
- for(int i=0; i<commandsToOptimize.size(); i++) {
- Command currentCommand = (Command) commandsToOptimize.get(i);
- TempMetadataAdapter facade = new TempMetadataAdapter(metadata, new TempMetadataStore(currentCommand.getTemporaryMetadata()));
- Collection externalGroups = currentCommand.getAllExternalGroups();
- Collection groups = GroupCollectorVisitor.getGroups(currentCommand, false);
-
- optimizeElements(currentCommand, groups, externalGroups, facade);
- }
- }
-
- private static boolean isXMLCommand(Command command, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException{
- // Check groups
- Collection groups = GroupCollectorVisitor.getGroups(command, true);
- if(groups.size() != 1) {
- return false;
- }
-
- // Check group symbol
- GroupSymbol group = (GroupSymbol) groups.iterator().next();
-
- // check if it is an XML group
- if (metadata.isXMLGroup(group.getMetadataID())){
- return true;
- }
-
- return false;
- }
-
- /**
- * Method optimizeElements.
- * @param command
- * @param elements
- * @param groups
- * @param externalGroups
- * @param facade
- */
- private static void optimizeElements(
- Command command,
- Collection groups,
- Collection externalGroups,
- QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
-
- switch(command.getType()) {
- case Command.TYPE_INSERT:
- case Command.TYPE_UPDATE:
- case Command.TYPE_DELETE:
-// optimizeUpdateCommand(command, groups, externalGroups, metadata);
- case Command.TYPE_STORED_PROCEDURE:
-// optimizeStoredProcedure(command, groups, externalGroups, metadata);
- case Command.TYPE_QUERY:
- // check for XML
- optimizeCommand(command, groups, externalGroups, metadata);
- break;
-
- case Command.TYPE_UPDATE_PROCEDURE:
- // for now do nothing
- break;
- }
- }
-
- /**
- * Method optimizeCommand. XML Commands are not currently optimized.
- * @param command
- * @param groups
- * @param externalGroups
- * @param metadata
- */
- private static void optimizeCommand(
- Command command,
- Collection groups,
- Collection externalGroups,
- QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
-
- if (isXMLCommand(command, metadata)){
- return;
- }
-
- final boolean REMOVE_DUPLICATES = false;
- Collection elements = ElementCollectorVisitor.getElements(command, REMOVE_DUPLICATES);
- Map shortNameMap = mapShortNamesToGroups(groups, externalGroups, metadata);
-
- Iterator i = elements.iterator();
- while (i.hasNext()) {
- ElementSymbol element = (ElementSymbol)i.next();
- String elementFullName = metadata.getFullName(element.getMetadataID());
- String shortNameKey = metadata.getShortElementName(elementFullName).toUpperCase();
- Set groupSet = (Set)shortNameMap.get(shortNameKey);
- if (groupSet != null && groupSet.size() <= 1){
- element.setDisplayFullyQualified(false);
- }
- }
- }
-
- /**
- * Return a Map of String element (or parameter) short names to
- * Set of GroupSymbols that have an element with that name
- * @param groups from Command
- * @param externalGroups from Command
- * @param metadata
- * @return Map of String element (or parameter) short names to
- * Set of GroupSymbols that have an element with that name
- */
- private static Map mapShortNamesToGroups(Collection groups, Collection externalGroups, QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
-
- Map result = new HashMap();
- Collection allGroups = new ArrayList(groups);
- allGroups.addAll(externalGroups);
-
- Iterator i = allGroups.iterator();
- while (i.hasNext()) {
- GroupSymbol group = (GroupSymbol)i.next();
- Iterator elemIDs = metadata.getElementIDsInGroupID(group.getMetadataID()).iterator();
- while (elemIDs.hasNext()) {
- ElementSymbol element = new ElementSymbol(metadata.getFullName(elemIDs.next()));
- String shortNameKey = element.getShortName().toUpperCase();
- Set groupSet = (Set)result.get(shortNameKey);
- if (groupSet == null){
- groupSet = new HashSet();
- result.put(shortNameKey, groupSet);
- }
- groupSet.add(group);
- }
- }
-
- return result;
- }
-}
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -26,6 +26,7 @@
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
@@ -35,7 +36,6 @@
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.util.ElementSymbolOptimizer;
import org.teiid.query.unittest.FakeMetadataFactory;
@@ -43,7 +43,7 @@
public Command helpResolve(String sql) {
Command cmd = TestResolver.helpResolve(sql, FakeMetadataFactory.example1Cached(), AnalysisRecord.createNonRecordingRecord());
- ElementSymbolOptimizer.fullyQualifyElements(cmd);
+ ResolverUtil.fullyQualifyElements(cmd);
return cmd;
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java 2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java 2011-03-02 16:26:09 UTC (rev 2956)
@@ -32,6 +32,8 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.FakeMetadataFactory;
@@ -56,11 +58,16 @@
}
public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected) throws QueryMetadataException, TeiidComponentException, QueryParserException, QueryResolverException {
- Command command = helpResolve(sql, metadata);
- ElementSymbolOptimizer.optimizeElements(command, metadata);
- String actual = command.toString();
-
- assertEquals("Expected different optimized string", expected, actual); //$NON-NLS-1$
+ try {
+ ResolverVisitor.setFindShortName(true);
+ Command command = helpResolve(sql, metadata);
+ String actual = command.toString();
+
+ assertEquals("Expected different optimized string", expected, actual); //$NON-NLS-1$
+ }
+ finally {
+ ResolverVisitor.setFindShortName(false);
+ }
}
/** Can be optimized */
@@ -98,7 +105,7 @@
public void testOptimize6() throws Exception {
helpTestOptimize("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(pm1.g2.e2) FROM pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1)", //$NON-NLS-1$
FakeMetadataFactory.example1Cached(),
- "SELECT e1, e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(pm1.g2.e2) FROM pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1)"); //$NON-NLS-1$
+ "SELECT e1, e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(e2) FROM pm1.g2 WHERE pm1.g1.e1 = e1)"); //$NON-NLS-1$
}
/** alias */
@@ -116,7 +123,7 @@
public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String expected) throws QueryParserException, QueryResolverException, TeiidComponentException {
Command command = helpResolve(sql, metadata);
- ElementSymbolOptimizer.fullyQualifyElements(command);
+ ResolverUtil.fullyQualifyElements(command);
String actual = command.toString();
assertEquals("Expected different fully qualified string", expected, actual); //$NON-NLS-1$
13 years, 10 months
teiid SVN: r2955 - in trunk: client/src/main/java/org/teiid/client/metadata and 9 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-03-01 16:25:23 -0500 (Tue, 01 Mar 2011)
New Revision: 2955
Modified:
trunk/api/src/main/java/org/teiid/translator/TypeFacility.java
trunk/client/src/main/java/org/teiid/client/metadata/ResultsMetadataDefaults.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/FunctionModifier.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/db2/TestDB2SqlTranslator.java
trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
Log:
TEIID-1487 TEIID-1483 refining null type handling logic and binding handling
Modified: trunk/api/src/main/java/org/teiid/translator/TypeFacility.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/TypeFacility.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/api/src/main/java/org/teiid/translator/TypeFacility.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -34,6 +34,7 @@
import org.teiid.core.types.ClobType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.JDBCSQLTypeInfo;
+import org.teiid.core.types.NullType;
import org.teiid.core.types.XMLType;
import org.teiid.core.util.TimestampWithTimezone;
@@ -60,6 +61,7 @@
public static final Class<BlobType> BLOB = DataTypeManager.DefaultDataClasses.BLOB;
public static final Class<ClobType> CLOB = DataTypeManager.DefaultDataClasses.CLOB;
public static final Class<XMLType> XML = DataTypeManager.DefaultDataClasses.XML;
+ public static final Class<NullType> NULL = DataTypeManager.DefaultDataClasses.NULL;
}
public static final class RUNTIME_NAMES {
Modified: trunk/client/src/main/java/org/teiid/client/metadata/ResultsMetadataDefaults.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/metadata/ResultsMetadataDefaults.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/client/src/main/java/org/teiid/client/metadata/ResultsMetadataDefaults.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -44,9 +44,9 @@
public static final String UPDATE_COLUMN = "count"; //$NON-NLS-1$
/** Maximum display size for the data type (Class -> Integer) */
- private static final Map MAX_DISPLAY_SIZE = new HashMap(21, 1.0f);
+ private static final Map<String, Integer> MAX_DISPLAY_SIZE = new HashMap<String, Integer>();
/** Default precision for a data type (String -> Integer) */
- private static final Map DEFAULT_PRECISION = new HashMap(21, 1.0f);
+ private static final Map<String, Integer> DEFAULT_PRECISION = new HashMap<String, Integer>();
static {
MAX_DISPLAY_SIZE.put(DataTypeManager.DefaultDataTypes.BIG_DECIMAL, new Integer(22));
@@ -68,6 +68,7 @@
MAX_DISPLAY_SIZE.put(DataTypeManager.DefaultDataTypes.TIME, new Integer(8));
MAX_DISPLAY_SIZE.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new Integer(29));
MAX_DISPLAY_SIZE.put(DataTypeManager.DefaultDataTypes.XML, new Integer(Integer.MAX_VALUE));
+ MAX_DISPLAY_SIZE.put(DataTypeManager.DefaultDataTypes.NULL, 4);
/* NOTE1
* For non-numeric columns (BLOB, BOOLEAN, CHAR, CLOB, DATE, OBJECT, STRING, TIME, TIMESTAMP, XML),
@@ -92,22 +93,23 @@
DEFAULT_PRECISION.put(DataTypeManager.DefaultDataTypes.TIME, new Integer(8));
DEFAULT_PRECISION.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new Integer(29));
DEFAULT_PRECISION.put(DataTypeManager.DefaultDataTypes.XML, new Integer(Integer.MAX_VALUE));
+ DEFAULT_PRECISION.put(DataTypeManager.DefaultDataTypes.NULL, 1);
}
- public static Integer getMaxDisplaySize(Class dataTypeClass) {
- return (Integer)MAX_DISPLAY_SIZE.get(DataTypeManager.getDataTypeName(dataTypeClass));
+ public static Integer getMaxDisplaySize(Class<?> dataTypeClass) {
+ return MAX_DISPLAY_SIZE.get(DataTypeManager.getDataTypeName(dataTypeClass));
}
public static Integer getMaxDisplaySize(String typeName) {
- return (Integer)MAX_DISPLAY_SIZE.get(typeName);
+ return MAX_DISPLAY_SIZE.get(typeName);
}
- public static Integer getDefaultPrecision(Class dataTypeClass) {
- return (Integer)DEFAULT_PRECISION.get(DataTypeManager.getDataTypeName(dataTypeClass));
+ public static Integer getDefaultPrecision(Class<?> dataTypeClass) {
+ return DEFAULT_PRECISION.get(DataTypeManager.getDataTypeName(dataTypeClass));
}
public static Integer getDefaultPrecision(String typeName) {
- return (Integer)DEFAULT_PRECISION.get(typeName);
+ return DEFAULT_PRECISION.get(typeName);
}
/** Uninstantiable */
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/FunctionModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/FunctionModifier.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/FunctionModifier.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -61,28 +61,30 @@
public static final int BLOB = 15;
public static final int CLOB = 16;
public static final int XML = 17;
+ public static final int NULL = 18;
private static final Map<Class<?>, Integer> typeMap = new HashMap<Class<?>, Integer>();
static {
- typeMap.put(TypeFacility.RUNTIME_TYPES.STRING, new Integer(STRING));
- typeMap.put(TypeFacility.RUNTIME_TYPES.CHAR, new Integer(CHAR));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BOOLEAN, new Integer(BOOLEAN));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BYTE, new Integer(BYTE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.SHORT, new Integer(SHORT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.INTEGER, new Integer(INTEGER));
- typeMap.put(TypeFacility.RUNTIME_TYPES.LONG, new Integer(LONG));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, new Integer(BIGINTEGER));
- typeMap.put(TypeFacility.RUNTIME_TYPES.FLOAT, new Integer(FLOAT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.DOUBLE, new Integer(DOUBLE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL, new Integer(BIGDECIMAL));
- typeMap.put(TypeFacility.RUNTIME_TYPES.DATE, new Integer(DATE));
- typeMap.put(TypeFacility.RUNTIME_TYPES.TIME, new Integer(TIME));
- typeMap.put(TypeFacility.RUNTIME_TYPES.TIMESTAMP, new Integer(TIMESTAMP));
- typeMap.put(TypeFacility.RUNTIME_TYPES.OBJECT, new Integer(OBJECT));
- typeMap.put(TypeFacility.RUNTIME_TYPES.BLOB, new Integer(BLOB));
- typeMap.put(TypeFacility.RUNTIME_TYPES.CLOB, new Integer(CLOB));
- typeMap.put(TypeFacility.RUNTIME_TYPES.XML, new Integer(XML));
+ typeMap.put(TypeFacility.RUNTIME_TYPES.STRING, STRING);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.CHAR, CHAR);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BOOLEAN, BOOLEAN);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BYTE, BYTE);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.SHORT, SHORT);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.INTEGER, INTEGER);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.LONG, LONG);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, BIGINTEGER);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.FLOAT, FLOAT);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.DOUBLE, DOUBLE);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL, BIGDECIMAL);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.DATE, DATE);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.TIME, TIME);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.TIMESTAMP, TIMESTAMP);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.OBJECT, OBJECT);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.BLOB, BLOB);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.CLOB, CLOB);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.XML, XML);
+ typeMap.put(TypeFacility.RUNTIME_TYPES.NULL, NULL);
}
public static int getCode(Class<?> source) {
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -35,10 +35,10 @@
import org.teiid.language.Literal;
import org.teiid.language.Comparison.Operator;
import org.teiid.language.Join.JoinType;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.AliasModifier;
import org.teiid.translator.jdbc.ConvertModifier;
@@ -140,7 +140,11 @@
if (selectSymbol.getExpression() instanceof Literal) {
Literal literal = (Literal)selectSymbol.getExpression();
if (literal.getValue() == null) {
- selectSymbol.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), literal, TypeFacility.getDataTypeName(literal.getType())));
+ String type = TypeFacility.RUNTIME_NAMES.INTEGER;
+ if (literal.getType() != TypeFacility.RUNTIME_TYPES.NULL) {
+ type = TypeFacility.getDataTypeName(literal.getType());
+ }
+ selectSymbol.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), literal, type));
}
}
}
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/db2/TestDB2SqlTranslator.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/db2/TestDB2SqlTranslator.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/db2/TestDB2SqlTranslator.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -22,7 +22,7 @@
package org.teiid.translator.jdbc.db2;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,8 +31,8 @@
import org.teiid.cdk.unittest.FakeTranslationFactory;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.Command;
+import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.ExecutionContext;
import org.teiid.translator.jdbc.TranslatedCommand;
import org.teiid.translator.jdbc.TranslationHelper;
@@ -114,6 +114,16 @@
input,
output);
}
+
+ @Test
+ public void testSelectNullLiteral1() throws Exception {
+ String input = "select x, intkey from (select null as x, intkey from BQT1.Smalla) y "; //$NON-NLS-1$
+ String output = "SELECT y.x, y.intkey FROM (SELECT cast(NULL AS integer) AS x, SmallA.IntKey FROM SmallA) AS y"; //$NON-NLS-1$
+
+ helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
+ input,
+ output);
+ }
/**
* Test the translator's ability to rewrite the LOCATE() function in a form
Modified: trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -45,7 +45,7 @@
// Initial state
private String groupName;
private String query;
- private List bindings; // optional - construct if needed
+ private List<String> bindings; // optional - construct if needed
// After parsing and resolution
private Command command;
@@ -91,7 +91,7 @@
*/
public void addBinding(String binding) {
if(this.bindings == null) {
- this.bindings = new ArrayList();
+ this.bindings = new ArrayList<String>();
}
this.bindings.add(binding);
}
@@ -100,7 +100,7 @@
* Get list of bindings.
* @return bindings
*/
- public List getBindings() {
+ public List<String> getBindings() {
return this.bindings;
}
@@ -108,8 +108,8 @@
* Set all of the bindings (existing are dropped)
* @param bindings New bindings
*/
- public void setBindings(List bindings) {
- this.bindings = new ArrayList(bindings);
+ public void setBindings(List<String> bindings) {
+ this.bindings = new ArrayList<String>(bindings);
}
/**
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-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -82,7 +83,7 @@
if (query == null) {
try {
query = QueryParser.getQueryParser().parseCommand(queryNode.getQuery());
- QueryResolver.resolveWithBindingMetadata(query, env.getGlobalMetadata(), queryNode);
+ QueryResolver.resolveWithBindingMetadata(query, env.getGlobalMetadata(), queryNode, true);
} catch (TeiidException e) {
throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0054", new Object[]{queryNode.getGroupName(), queryNode.getQuery()})); //$NON-NLS-1$
}
@@ -187,7 +188,7 @@
}
static List<ElementSymbol> getBindingsReferences(LanguageObject object, Collection<ElementSymbol> allBindings) {
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
+ List<ElementSymbol> elements = new LinkedList<ElementSymbol>();
ElementCollectorVisitor visitor = new ElementCollectorVisitor(elements);
DeepPreOrderNavigator.doVisit(object, visitor);
for (Iterator<ElementSymbol> i = elements.iterator(); i.hasNext();) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -29,7 +29,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
@@ -149,14 +148,14 @@
case Command.TYPE_QUERY:
QueryNode queryNode = metadata.getVirtualPlan(metadata.getGroupID(container.getCanonicalName()));
- return resolveWithBindingMetadata(currentCommand, metadata, queryNode);
+ return resolveWithBindingMetadata(currentCommand, metadata, queryNode, false);
case Command.TYPE_INSERT:
case Command.TYPE_UPDATE:
case Command.TYPE_DELETE:
case Command.TYPE_STORED_PROCEDURE:
ProcedureContainerResolver.findChildCommandMetadata(currentCommand, container, type, metadata);
}
- return resolveCommand(currentCommand, metadata, true);
+ return resolveCommand(currentCommand, metadata, false);
}
/**
@@ -167,13 +166,11 @@
* be marked as external references.
*/
public static TempMetadataStore resolveWithBindingMetadata(Command currentCommand,
- QueryMetadataInterface metadata, QueryNode queryNode)
+ QueryMetadataInterface metadata, QueryNode queryNode, boolean replaceBindings)
throws TeiidComponentException, QueryResolverException {
Map<ElementSymbol, ElementSymbol> symbolMap = null;
if (queryNode.getBindings() != null && queryNode.getBindings().size() > 0) {
symbolMap = new HashMap<ElementSymbol, ElementSymbol>();
- // GroupSymbol (name form) for InputSet
- GroupSymbol inputSetSymbol = new GroupSymbol(ProcedureReservedWords.INPUT);
// Create ElementSymbols for each InputParameter
final List<ElementSymbol> elements = new ArrayList<ElementSymbol>(queryNode.getBindings().size());
@@ -189,6 +186,7 @@
elementSymbol.setIsExternalReference(true);
if (!positional) {
symbolMap.put(new ElementSymbol(ProcedureReservedWords.INPUT + ElementSymbol.SEPARATOR + name), (ElementSymbol)elementSymbol.clone());
+ symbolMap.put(new ElementSymbol(ProcedureReservedWords.INPUTS + ElementSymbol.SEPARATOR + name), (ElementSymbol)elementSymbol.clone());
elementSymbol.setName(name);
}
elements.add(elementSymbol);
@@ -210,19 +208,16 @@
DeepPostOrderNavigator.doVisit(currentCommand, emv);
} else {
TempMetadataStore rootExternalStore = new TempMetadataStore();
- rootExternalStore.addTempGroup(inputSetSymbol.getName(), elements);
- currentCommand.addExternalGroupToContext(inputSetSymbol);
-
- Map tempMetadata = currentCommand.getTemporaryMetadata();
- if(tempMetadata == null) {
- currentCommand.setTemporaryMetadata(rootExternalStore.getData());
- } else {
- tempMetadata.putAll(rootExternalStore.getData());
- }
+
+ GroupContext externalGroups = new GroupContext();
+
+ ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUT, rootExternalStore, externalGroups, elements);
+ ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUTS, rootExternalStore, externalGroups, elements);
+ QueryResolver.setChildMetadata(currentCommand, rootExternalStore.getData(), externalGroups);
}
}
- TempMetadataStore result = resolveCommand(currentCommand, metadata, true);
- if (symbolMap != null && !symbolMap.isEmpty()) {
+ TempMetadataStore result = resolveCommand(currentCommand, metadata, false);
+ if (replaceBindings && symbolMap != null && !symbolMap.isEmpty()) {
ExpressionMappingVisitor emv = new ExpressionMappingVisitor(symbolMap);
emv.setClone(true);
DeepPostOrderNavigator.doVisit(currentCommand, emv);
@@ -445,9 +440,9 @@
bindings = qnode.getBindings();
}
if (bindings != null && !bindings.isEmpty()) {
- QueryResolver.resolveCommand(result, virtualGroup, Command.TYPE_QUERY, qmi);
+ QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
} else {
- QueryResolver.resolveCommand(result, qmi);
+ QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
qmi.addToMetadataCache(virtualGroup.getMetadataID(), "transformation/" + cacheString, result.clone()); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import org.teiid.api.exception.query.QueryMetadataException;
@@ -62,10 +61,9 @@
QueryResolver.setChildMetadata(firstCommand, setQuery);
QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false);
- List firstProject = firstCommand.getProjectedSymbols();
+ List<SingleElementSymbol> firstProject = firstCommand.getProjectedSymbols();
List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
- for (Iterator j = firstProject.iterator(); j.hasNext();) {
- SingleElementSymbol symbol = (SingleElementSymbol)j.next();
+ for (SingleElementSymbol symbol : firstProject) {
firstProjectTypes.add(symbol.getType());
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -183,8 +183,14 @@
resolveAgainstGroups(shortCanonicalName, matchedGroups, matches);
if (matches.size() > 1) {
- handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
- return;
+ if (isExternal && matches.size() == 2
+ && ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))
+ || (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)))) {
+ matches.remove();
+ } else {
+ handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
+ return;
+ }
}
if (matches.size() == 1) {
@@ -211,8 +217,7 @@
GroupSymbol resolvedGroup = match.group;
String oldName = elementSymbol.getOutputName();
if (isExternal //convert input to inputs
- && metadata.isScalarGroup(resolvedSymbol.getGroupSymbol().getMetadataID())
- && ProcedureReservedWords.INPUT.equals(groupContext)) {
+ && isScalar(resolvedSymbol, ProcedureReservedWords.INPUT)) {
resolvedSymbol = new ElementSymbol(ProcedureReservedWords.INPUTS + ElementSymbol.SEPARATOR + elementShortName);
resolveElementSymbol(resolvedSymbol);
oldName = resolvedSymbol.getOutputName();
@@ -230,6 +235,11 @@
elementSymbol.setName(resolvedSymbol.getName());
elementSymbol.setOutputName(oldName);
}
+
+ private boolean isScalar(ElementSymbol resolvedSymbol, String group) throws QueryMetadataException, TeiidComponentException {
+ return metadata.isScalarGroup(resolvedSymbol.getGroupSymbol().getMetadataID())
+ && group.equals(resolvedSymbol.getGroupSymbol().getCanonicalName());
+ }
private void resolveAgainstGroups(String elementShortName,
Collection<GroupSymbol> matchedGroups, LinkedList<ElementMatch> matches) throws QueryMetadataException,
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-03-01 21:12:17 UTC (rev 2954)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-03-01 21:25:23 UTC (rev 2955)
@@ -234,7 +234,7 @@
QueryNode qn = new QueryNode("x", sql);
qn.setBindings(bindings);
// resolve
- QueryResolver.resolveWithBindingMetadata(command, metadata, qn);
+ QueryResolver.resolveWithBindingMetadata(command, metadata, qn, true);
CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
DeepPreOrderNavigator.doVisit(command, vis);
13 years, 10 months
teiid SVN: r2953 - in trunk/client/src/main: resources/org/teiid/jdbc and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-03-01 16:04:09 -0500 (Tue, 01 Mar 2011)
New Revision: 2953
Modified:
trunk/client/src/main/java/org/teiid/net/socket/SocketUtil.java
trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
Log:
TEIID-1488 changed the assertion to a warning, which will allow for a later error if a suite cannot be negotiated.
Modified: trunk/client/src/main/java/org/teiid/net/socket/SocketUtil.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/socket/SocketUtil.java 2011-03-01 14:57:25 UTC (rev 2952)
+++ trunk/client/src/main/java/org/teiid/net/socket/SocketUtil.java 2011-03-01 21:04:09 UTC (rev 2953)
@@ -34,6 +34,7 @@
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.Properties;
+import java.util.logging.Logger;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
@@ -42,7 +43,6 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
-import org.teiid.core.util.Assertion;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.jdbc.JDBCPlugin;
@@ -54,6 +54,7 @@
* ssl connection
*/
public class SocketUtil {
+ private static Logger logger = Logger.getLogger(SocketUtil.class.getName());
static final String TRUSTSTORE_PASSWORD = "org.teiid.ssl.trustStorePassword"; //$NON-NLS-1$
public static final String TRUSTSTORE_FILENAME = "org.teiid.ssl.trustStore"; //$NON-NLS-1$
@@ -71,6 +72,7 @@
public static class SSLSocketFactory {
private boolean isAnon;
+ private boolean warned;
private javax.net.ssl.SSLSocketFactory factory;
public SSLSocketFactory(SSLContext context, boolean isAnon) {
@@ -81,8 +83,9 @@
public synchronized Socket getSocket() throws IOException {
SSLSocket result = (SSLSocket)factory.createSocket();
result.setUseClientMode(true);
- if (isAnon) {
- addCipherSuite(result, ANON_CIPHER_SUITE);
+ if (isAnon && !addCipherSuite(result, ANON_CIPHER_SUITE) && !warned) {
+ warned = true;
+ logger.warning(JDBCPlugin.Util.getString("SocketUtil.anon_not_available")); //$NON-NLS-1$
}
return result;
}
@@ -131,8 +134,10 @@
return getSSLContext(keystore, password, truststore, truststorePassword, algorithm, keystoreType, protocol);
}
- public static void addCipherSuite(SSLSocket engine, String cipherSuite) {
- Assertion.assertTrue(Arrays.asList(engine.getSupportedCipherSuites()).contains(cipherSuite));
+ public static boolean addCipherSuite(SSLSocket engine, String cipherSuite) {
+ if (!Arrays.asList(engine.getSupportedCipherSuites()).contains(cipherSuite)) {
+ return false;
+ }
String[] suites = engine.getEnabledCipherSuites();
@@ -142,6 +147,7 @@
newSuites[suites.length] = cipherSuite;
engine.setEnabledCipherSuites(newSuites);
+ return true;
}
public static SSLContext getAnonSSLContext() throws IOException, GeneralSecurityException {
Modified: trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
===================================================================
--- trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2011-03-01 14:57:25 UTC (rev 2952)
+++ trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2011-03-01 21:04:09 UTC (rev 2953)
@@ -142,6 +142,7 @@
SocketServerConnection.closed=Server connection is closed
SocketHelper.keystore_not_found=Key store ''{0}'' was not found.
+SocketUtil.anon_not_available=The anonymous cipher suite TLS_DH_anon_WITH_AES_128_CBC_SHA could not be added. Anonymous SSL connections will fail.
MMURL.INVALID_FORMAT=The required socket url format is mm[s]://server1:port1[,server2:port2]
TeiidURL.invalid_ipv6_hostport=The IPv6 host:port ''{0}'' is not valid. {1}
13 years, 10 months
teiid SVN: r2952 - in trunk: engine/src/main/java/org/teiid/query/optimizer/xml and 7 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-03-01 09:57:25 -0500 (Tue, 01 Mar 2011)
New Revision: 2952
Removed:
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/ReferenceBindingReplacerVisitor.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java
Modified:
trunk/client/src/main/java/org/teiid/net/TeiidURL.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
Log:
TEIID-1483 consolidating resolving code with designer, allowing named bindings to work in xml planning logic
Modified: trunk/client/src/main/java/org/teiid/net/TeiidURL.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/TeiidURL.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/client/src/main/java/org/teiid/net/TeiidURL.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -117,7 +117,7 @@
if (StringUtil.startsWithIgnoreCase(serverURL, SECURE_PROTOCOL)) {
usingSSL = true;
} else if (!StringUtil.startsWithIgnoreCase(serverURL, DEFAULT_PROTOCOL)) {
- throw new IllegalArgumentException(INVALID_FORMAT_SERVER);
+ throw new MalformedURLException(INVALID_FORMAT_SERVER);
}
appServerURL = serverURL;
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-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -25,20 +25,20 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
@@ -49,11 +49,13 @@
import org.teiid.query.sql.lang.FromClause;
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.Reference;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
import org.teiid.query.util.CommandContext;
@@ -74,38 +76,21 @@
* @throws QueryPlannerException If an error occurred
* @since 4.3
*/
- static Command getQuery(QueryNode queryNode) throws QueryPlannerException {
+ static Command getQuery(QueryNode queryNode, XMLPlannerEnvironment env) throws QueryPlannerException {
Command query = queryNode.getCommand();
if (query == null) {
try {
- query = QueryParser.getQueryParser().parseCommand(queryNode.getQuery());
- } catch (QueryParserException e) {
+ query = QueryParser.getQueryParser().parseCommand(queryNode.getQuery());
+ QueryResolver.resolveWithBindingMetadata(query, env.getGlobalMetadata(), queryNode);
+ } catch (TeiidException e) {
throw new QueryPlannerException(e, QueryPlugin.Util.getString("ERR.015.004.0054", new Object[]{queryNode.getGroupName(), queryNode.getQuery()})); //$NON-NLS-1$
- }
+ }
}
return query;
}
/**
- * Resolve a command using the metadata in the planner environment.
- * @param query The query to resolve
- * @param planEnv The planner environment
- * @throws TeiidComponentException
- * @throws QueryPlannerException
- * @since 4.3
- */
- static void resolveQuery(Command query, TempMetadataAdapter metadata)
- throws TeiidComponentException, QueryPlannerException {
- // Run resolver
- try {
- QueryResolver.resolveCommand(query, metadata);
- } catch(QueryResolverException e) {
- throw new QueryPlannerException(e, e.getMessage());
- }
- }
-
- /**
* Rewrite a command using the metadata in the planner environment.
* @param query The query to rewrite
* @param planEnv The planner environment
@@ -177,21 +162,43 @@
throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
QueryNode queryNode = QueryUtil.getQueryNode(groupName, planEnv.getGlobalMetadata());
- Command command = QueryUtil.getQuery(queryNode);
+ Command command = QueryUtil.getQuery(queryNode, planEnv);
return command;
}
- static void handleBindings(LanguageObject object, QueryNode planNode, XMLPlannerEnvironment planEnv)
- throws QueryMetadataException, TeiidComponentException {
-
- List parsedBindings = QueryResolver.parseBindings(planNode);
+ static void markBindingsAsNonExternal(LanguageObject object,
+ Collection<ElementSymbol> allBindings) {
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
+ ElementCollectorVisitor visitor = new ElementCollectorVisitor(elements);
+ DeepPreOrderNavigator.doVisit(object, visitor);
+ for (Iterator<ElementSymbol> i = elements.iterator(); i.hasNext();) {
+ ElementSymbol elementSymbol = i.next();
+ if (allBindings.contains(elementSymbol)) {
+ elementSymbol.setIsExternalReference(false);
+ elementSymbol.setMetadataID(null);
+ }
+ }
+ }
- if (!parsedBindings.isEmpty()) {
- //use ReferenceBindingReplacer Visitor
- ReferenceBindingReplacerVisitor.replaceReferences(object, parsedBindings);
- }
- }
+ static Collection<ElementSymbol> getBindingElements(QueryNode queryNode) throws TeiidComponentException {
+ HashSet<ElementSymbol> set = new HashSet<ElementSymbol>();
+ ElementCollectorVisitor.getElements(QueryResolver.parseBindings(queryNode), set);
+ return set;
+ }
+ static List<ElementSymbol> getBindingsReferences(LanguageObject object, Collection<ElementSymbol> allBindings) {
+ List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
+ ElementCollectorVisitor visitor = new ElementCollectorVisitor(elements);
+ DeepPreOrderNavigator.doVisit(object, visitor);
+ for (Iterator<ElementSymbol> i = elements.iterator(); i.hasNext();) {
+ ElementSymbol elementSymbol = i.next();
+ if (!elementSymbol.isExternalReference() || !allBindings.contains(elementSymbol)) {
+ i.remove();
+ }
+ }
+ return elements;
+ }
+
static Map createSymbolMap(GroupSymbol oldGroup, final String newGroup, Collection projectedElements) {
HashMap symbolMap = new HashMap();
symbolMap.put(oldGroup, new GroupSymbol(newGroup));
@@ -205,11 +212,11 @@
}
- static List getReferences(Command command) {
- List boundList = new ArrayList();
+ static List<Reference> getReferences(Command command) {
+ List<Reference> boundList = new ArrayList<Reference>();
- for (Iterator refs = ReferenceCollectorVisitor.getReferences(command).iterator(); refs.hasNext();) {
- Reference ref = (Reference) refs.next();
+ for (Iterator<Reference> refs = ReferenceCollectorVisitor.getReferences(command).iterator(); refs.hasNext();) {
+ Reference ref = refs.next();
Expression expr = ref.getExpression();
if (!(expr instanceof ElementSymbol)){
continue;
@@ -222,5 +229,6 @@
boundList.add(ref);
}
return boundList;
- }
+ }
+
}
Deleted: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/ReferenceBindingReplacerVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/ReferenceBindingReplacerVisitor.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/ReferenceBindingReplacerVisitor.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -1,83 +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.optimizer.xml;
-
-import java.util.List;
-
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
-import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.Reference;
-import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
-
-
-/**
- * <p>This visitor class will traverse a language object tree, find any Reference
- * objects, and replace them with the corresponding parsed Expression which is the
- * Reference's binding. The List of parsed bindings must contain Expressions, and
- * of course the number and order of the bindings must match up with the number
- * and order of the References that are in the Language Object.</p>
- *
- * <p>The easiest way to use this visitor is to call the static methods which create
- * the visitor and run it.
- * The public visit() methods should NOT be called directly.</p>
- */
-public class ReferenceBindingReplacerVisitor extends ExpressionMappingVisitor {
-
- private List parsedBindingExpressions;
-
- /**
- * Construct a new visitor with the default collection type, which is a
- * {@link java.util.HashSet}.
- */
- public ReferenceBindingReplacerVisitor(List parsedBindingExpressions) {
- super(null);
- this.parsedBindingExpressions = parsedBindingExpressions;
- }
-
- public Expression replaceExpression(Expression element) {
- if (!(element instanceof Reference)) {
- return element;
- }
-
- Reference reference = (Reference)element;
-
- return (Expression)parsedBindingExpressions.get(reference.getIndex());
- }
-
- /**
- * Helper to quickly get the references from obj in the references collection
- * @param obj Language object
- * @param elements Collection to collect references in
- */
- public static final void replaceReferences(LanguageObject obj, List parsedBindingExpressions) {
- if (parsedBindingExpressions == null || parsedBindingExpressions.isEmpty()) {
- return;
- }
-
- ReferenceBindingReplacerVisitor visitor = new ReferenceBindingReplacerVisitor(parsedBindingExpressions);
- DeepPreOrderNavigator.doVisit(obj, visitor);
- }
-
-}
-
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -31,7 +31,6 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
-import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.mapping.relational.QueryNode;
@@ -56,7 +55,6 @@
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
-import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -112,23 +110,23 @@
//create the command off of the unresolved group symbol
Query baseQuery = QueryUtil.wrapQuery(new UnaryFromClause(new GroupSymbol(newGroup)), newGroup);
baseQuery.getSelect().clearSymbols();
- for (Iterator i = ResolverUtil.resolveElementsInGroup(groupSymbol, planEnv.getGlobalMetadata()).iterator(); i.hasNext();) {
- SingleElementSymbol ses = (SingleElementSymbol)i.next();
+ for (Iterator<ElementSymbol> i = ResolverUtil.resolveElementsInGroup(groupSymbol, planEnv.getGlobalMetadata()).iterator(); i.hasNext();) {
+ ElementSymbol ses = i.next();
baseQuery.getSelect().addSymbol(new ElementSymbol(newGroup + SingleElementSymbol.SEPARATOR + ses.getShortName()));
}
rsInfo.setCommand(baseQuery);
QueryNode modifiedNode = QueryUtil.getQueryNode(newGroup, planEnv.getGlobalMetadata());
- Command command = QueryUtil.getQuery(modifiedNode);
+ Command command = QueryUtil.getQuery(modifiedNode, planEnv);
MappingSourceNode parent = sourceNode.getParentSourceNode();
-
+ Collection<ElementSymbol> bindings = QueryUtil.getBindingElements(modifiedNode);
// root source nodes do not have any inputset criteria on them; so there is no use in
// going through the raising the criteria.
// if the original query is not a select.. we are out of luck. we can expand on this later
// versions. make ure bindings are only to parent.
- if (parent == null || !canRaiseInputset(command) || !areBindingsOnlyToNode(modifiedNode, parent)) {
+ if (parent == null || !canRaiseInputset(command, bindings) || !areBindingsOnlyToNode(modifiedNode, parent)) {
return;
}
@@ -136,18 +134,16 @@
// criteria.
Query transformationQuery = (Query)command;
- QueryUtil.resolveQuery(transformationQuery, planEnv.getGlobalMetadata());
-
Criteria criteria = transformationQuery.getCriteria();
Criteria nonInputsetCriteria = null;
Criteria inputSetCriteria = null;
- for (Iterator i = Criteria.separateCriteriaByAnd(criteria).iterator(); i.hasNext();) {
- Criteria conjunct = (Criteria) i.next();
+ for (Iterator<Criteria> i = Criteria.separateCriteriaByAnd(criteria).iterator(); i.hasNext();) {
+ Criteria conjunct = i.next();
// collect references in the criteria; if there are references; then this is
// set by inputset criteria
- Collection references = ReferenceCollectorVisitor.getReferences(conjunct);
+ Collection<ElementSymbol> references = QueryUtil.getBindingsReferences(conjunct, bindings);
if (references.isEmpty()) {
nonInputsetCriteria = Criteria.combineCriteria(nonInputsetCriteria, conjunct);
}
@@ -176,9 +172,7 @@
QueryNode relationalNode = new QueryNode(newGroup, SQLStringVisitor.getSQLString(transformationQuery));
planEnv.addQueryNodeToMetadata(newGroupSymbol.getMetadataID(), relationalNode);
- // this is the simple form of the planned query preplan stage. set the command
- // with newly found criteria.
- QueryUtil.handleBindings(inputSetCriteria, modifiedNode, planEnv);
+ QueryUtil.markBindingsAsNonExternal(inputSetCriteria, bindings);
baseQuery.setCriteria(inputSetCriteria);
rsInfo.setCriteriaRaised(true);
@@ -232,7 +226,7 @@
* set names in a mapping document.
*/
private GroupSymbol createAlternateGroup(GroupSymbol oldSymbol, MappingSourceNode sourceNode)
- throws QueryMetadataException, TeiidComponentException, QueryResolverException, QueryPlannerException {
+ throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
// get elements in the old group
List elements = ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
@@ -277,7 +271,7 @@
}
ElementSymbol es = (ElementSymbol)ses;
if (!useName) {
- bindings.add(sourceNode.getMappedSymbol(es).getName());
+ bindings.add(sourceNode.getMappedSymbol(es).toString());
} else {
bindings.add(new AliasSymbol(name, sourceNode.getMappedSymbol(es)).toString());
}
@@ -286,7 +280,7 @@
}
}
- private boolean canRaiseInputset(Command command) {
+ private boolean canRaiseInputset(Command command, Collection<ElementSymbol> bindings) throws TeiidComponentException {
// check to see if this is query.
if (!(command instanceof Query)) {
return false;
@@ -303,7 +297,7 @@
//just throw away order by
query.setOrderBy(null);
- Collection references = ReferenceCollectorVisitor.getReferences(query);
+ List<ElementSymbol> references = QueryUtil.getBindingsReferences(query, bindings);
query.setCriteria(crit);
@@ -321,17 +315,21 @@
throws QueryMetadataException, TeiidComponentException {
String groupName = newGroupSymbol.getName();
- Collection elementsInCriteria = ElementCollectorVisitor.getElements(criteria, true);
+ Collection<ElementSymbol> elementsInCriteria = ElementCollectorVisitor.getElements(criteria, true);
Map mappedElements = new HashMap();
List projectedSymbols = transformationQuery.getProjectedSymbols();
boolean addedProjectedSymbol = false;
- for (Iterator i = elementsInCriteria.iterator(); i.hasNext();) {
+ for (Iterator<ElementSymbol> i = elementsInCriteria.iterator(); i.hasNext();) {
- final ElementSymbol symbol = (ElementSymbol)i.next();
+ final ElementSymbol symbol = i.next();
+ if (symbol.isExternalReference()) {
+ continue;
+ }
+
if (projectedSymbols.contains(symbol)) {
mappedElements.put(symbol, new ElementSymbol(groupName + ElementSymbol.SEPARATOR + symbol.getShortName()));
continue;
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -53,6 +53,7 @@
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.relational.RelationalNode;
import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
@@ -203,13 +204,13 @@
}
static void prepareQuery(MappingSourceNode sourceNode, XMLPlannerEnvironment planEnv, QueryCommand rsQuery)
- throws TeiidComponentException, QueryPlannerException {
+ throws TeiidComponentException, QueryResolverException {
Collection externalGroups = getExternalGroups(sourceNode);
rsQuery.setExternalGroupContexts(new GroupContext(null, externalGroups));
- QueryUtil.resolveQuery(rsQuery, planEnv.getGlobalMetadata());
+ QueryResolver.resolveCommand(rsQuery, planEnv.getGlobalMetadata());
}
private static Collection getExternalGroups(MappingSourceNode sourceNode) {
@@ -291,7 +292,7 @@
ResultSetInfo childRsInfo = rsNode.getResultSetInfo();
QueryNode planNode = QueryUtil.getQueryNode(childRsInfo.getResultSetName(), planEnv.getGlobalMetadata());
- Command command = QueryUtil.getQuery(planNode);
+ Command command = QueryUtil.getQuery(planNode, planEnv);
String inlineViewName = planEnv.getAliasName(childRsInfo.getResultSetName());
@@ -338,8 +339,6 @@
throw new QueryPlannerException(QueryPlugin.Util.getString("XMLQueryPlanner.cannot_plan", rsInfo.getCriteria())); //$NON-NLS-1$
}
- QueryUtil.handleBindings(command, planNode, planEnv);
-
Query subQuery = QueryUtil.wrapQuery(new SubqueryFromClause(inlineViewName, command), inlineViewName);
currentQuery.setCriteria(Criteria.combineCriteria(currentQuery.getCriteria(), new ExistsCriteria(subQuery)));
@@ -359,13 +358,13 @@
QueryUtil.rewriteQuery(contextQuery, planEnv.getGlobalMetadata(), planEnv.context);
//selectively replace correlated references with their actual element symbols
- List bindings = QueryUtil.getReferences(contextQuery);
+ List<Reference> bindings = QueryUtil.getReferences(contextQuery);
QueryNode modifiedNode = new QueryNode(rsInfo.getResultSetName(), null);
modifiedNode.setCommand(contextQuery);
- for (Iterator i = bindings.iterator(); i.hasNext();) {
- Reference ref = (Reference)i.next();
+ for (Iterator<Reference> i = bindings.iterator(); i.hasNext();) {
+ Reference ref = i.next();
modifiedNode.addBinding(ref.getExpression().toString());
}
@@ -393,9 +392,10 @@
* @param groupName
* @param planEnv
* @return {@link GroupSymbol} the temptable which has been planned.
+ * @throws QueryResolverException
*/
static void planStagingTable(String groupName, XMLPlannerEnvironment planEnv)
- throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
+ throws QueryPlannerException, QueryMetadataException, TeiidComponentException, QueryResolverException {
ResultSetInfo rsInfo = planEnv.getStagingTableResultsInfo(groupName);
@@ -410,9 +410,10 @@
* This method takes given query and adds the "into" symbol to query and resoves it
* and registers it with planner env as the staging table. Also, builds a unload query
* to unload the staging table.
+ * @throws QueryResolverException
*/
static boolean planStagaingQuery(boolean implicit, String srcGroupName, String stageGroupName, Query query, XMLPlannerEnvironment planEnv)
- throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
+ throws QueryPlannerException, QueryMetadataException, TeiidComponentException, QueryResolverException {
GroupSymbol srcGroup = QueryUtil.createResolvedGroup(srcGroupName, planEnv.getGlobalMetadata());
@@ -421,7 +422,7 @@
query.setInto(new Into(intoGroupSymbol));
- QueryUtil.resolveQuery(query, planEnv.getGlobalMetadata());
+ QueryResolver.resolveCommand(query, planEnv.getGlobalMetadata());
Command cmd = QueryUtil.rewriteQuery(query, planEnv.getGlobalMetadata(), planEnv.context);
@@ -493,7 +494,7 @@
String unloadName = planEnv.unLoadResultName(stageGroupName);
ResultSetInfo rsUnloadInfo = planEnv.getStagingTableResultsInfo(unloadName);
Command command = wrapStagingTableUnloadQuery(intoGroupSymbol);
- QueryUtil.resolveQuery(command, planEnv.getGlobalMetadata());
+ QueryResolver.resolveCommand(command, planEnv.getGlobalMetadata());
command = QueryUtil.rewriteQuery(command, planEnv.getGlobalMetadata(), planEnv.context);
plan = optimizePlan(command, planEnv);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -26,6 +26,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.query.mapping.relational.QueryNode;
@@ -85,7 +86,7 @@
}
static boolean stagePlannedQuery(MappingSourceNode sourceNode, XMLPlannerEnvironment planEnv)
- throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
+ throws QueryPlannerException, QueryMetadataException, TeiidComponentException, QueryResolverException {
Option option = planEnv.xmlCommand.getOption();
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -56,7 +56,6 @@
import org.teiid.query.resolver.command.UpdateProcedureResolver;
import org.teiid.query.resolver.command.UpdateResolver;
import org.teiid.query.resolver.command.XMLQueryResolver;
-import org.teiid.query.resolver.util.BindVariableVisitor;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.ProcedureReservedWords;
@@ -69,12 +68,15 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.symbol.AliasSymbol;
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.Reference;
import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.validator.ValidationVisitor;
@@ -147,8 +149,7 @@
case Command.TYPE_QUERY:
QueryNode queryNode = metadata.getVirtualPlan(metadata.getGroupID(container.getCanonicalName()));
- addBindingMetadata(currentCommand, metadata, queryNode);
- break;
+ return resolveWithBindingMetadata(currentCommand, metadata, queryNode);
case Command.TYPE_INSERT:
case Command.TYPE_UPDATE:
case Command.TYPE_DELETE:
@@ -158,15 +159,24 @@
return resolveCommand(currentCommand, metadata, true);
}
- static void addBindingMetadata(Command currentCommand,
+ /**
+ * Bindings are a poor mans input parameters. They are represented in legacy metadata
+ * by ElementSymbols and placed positionally into the command or by alias symbols
+ * and matched by names. After resolving bindings will be replaced with their
+ * referenced symbols (input names will not be used) and those symbols will
+ * be marked as external references.
+ */
+ public static TempMetadataStore resolveWithBindingMetadata(Command currentCommand,
QueryMetadataInterface metadata, QueryNode queryNode)
throws TeiidComponentException, QueryResolverException {
+ Map<ElementSymbol, ElementSymbol> symbolMap = null;
if (queryNode.getBindings() != null && queryNode.getBindings().size() > 0) {
+ symbolMap = new HashMap<ElementSymbol, ElementSymbol>();
// GroupSymbol (name form) for InputSet
GroupSymbol inputSetSymbol = new GroupSymbol(ProcedureReservedWords.INPUT);
// Create ElementSymbols for each InputParameter
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>(queryNode.getBindings().size());
+ final List<ElementSymbol> elements = new ArrayList<ElementSymbol>(queryNode.getBindings().size());
boolean positional = true;
for (SingleElementSymbol ses : parseBindings(queryNode)) {
String name = ses.getName();
@@ -176,13 +186,28 @@
}
ElementSymbol elementSymbol = (ElementSymbol)ses;
ResolverVisitor.resolveLanguageObject(elementSymbol, metadata);
+ elementSymbol.setIsExternalReference(true);
if (!positional) {
+ symbolMap.put(new ElementSymbol(ProcedureReservedWords.INPUT + ElementSymbol.SEPARATOR + name), (ElementSymbol)elementSymbol.clone());
elementSymbol.setName(name);
}
elements.add(elementSymbol);
}
if (positional) {
- BindVariableVisitor.bindReferences(currentCommand, elements);
+ ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
+ @Override
+ public Expression replaceExpression(Expression element) {
+ if (!(element instanceof Reference)) {
+ return element;
+ }
+ Reference ref = (Reference)element;
+ if (!ref.isPositional()) {
+ return ref;
+ }
+ return (ElementSymbol)elements.get(ref.getIndex()).clone();
+ }
+ };
+ DeepPostOrderNavigator.doVisit(currentCommand, emv);
} else {
TempMetadataStore rootExternalStore = new TempMetadataStore();
rootExternalStore.addTempGroup(inputSetSymbol.getName(), elements);
@@ -196,6 +221,13 @@
}
}
}
+ TempMetadataStore result = resolveCommand(currentCommand, metadata, true);
+ if (symbolMap != null && !symbolMap.isEmpty()) {
+ ExpressionMappingVisitor emv = new ExpressionMappingVisitor(symbolMap);
+ emv.setClone(true);
+ DeepPostOrderNavigator.doVisit(currentCommand, emv);
+ }
+ return result;
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -110,8 +110,12 @@
// for this map will either be the String names of the parameters or
// the Integer indices, as entered in the user query
Map<Object, Expression> inputExpressions = new HashMap<Object, Expression>();
+ int adjustIndex = 0;
for (SPParameter param : oldParams) {
if(param.getExpression() == null) {
+ if (param.getParameterType() == SPParameter.RESULT_SET) {
+ adjustIndex--; //If this was already resolved, just pretend the result set param doesn't exist
+ }
continue;
}
if (namedParameters && param.getParameterType() != SPParameter.RETURN_VALUE) {
@@ -119,7 +123,7 @@
throw new QueryResolverException(QueryPlugin.Util.getString("ExecResolver.duplicate_named_params", param.getName().toUpperCase())); //$NON-NLS-1$
}
} else {
- inputExpressions.put(param.getIndex(), param.getExpression());
+ inputExpressions.put(param.getIndex() + adjustIndex, param.getExpression());
}
}
Deleted: trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -1,109 +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.resolver.util;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.client.metadata.ParameterInfo;
-import org.teiid.core.util.ArgCheck;
-import org.teiid.query.QueryPlugin;
-import org.teiid.query.sql.LanguageObject;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Reference;
-
-
-/**
- * <p>Given a LanguageObject containing References and the List of String binding
- * expressions from a query transformation, this visitor will parse and resolve
- * each binding and set the resolved expression on the appropriate Reference,
- * making sure to match up the correct binding with the correct Reference.
- * The Reference is fully resolved after this happens.</p>
- *
- * <p>Optionally, a Map can be built up which maps the String virtual group to
- * a List of Reference objects which have bindings to an element of the
- * virtual group key. This may be useful to have on hand the Reference objects
- * which are dependent on the changing tuples of a virtual group during query
- * processing.</p>
- */
-public class BindVariableVisitor extends LanguageVisitor {
-
- private List<ElementSymbol> bindings;
-
- /**
- * Constructor
- * @param bindings List of String binding expressions from query
- * transformation node
- */
- public BindVariableVisitor(List<ElementSymbol> bindings) {
- ArgCheck.isNotNull(bindings, QueryPlugin.Util.getString("ERR.015.008.0049")); //$NON-NLS-1$
-
- this.bindings = bindings;
- }
-
- /**
- * Visit a Reference object and bind it based on the bindings
- * @see org.teiid.query.sql.LanguageVisitor#visit(Reference)
- */
- public void visit(Reference obj) {
- bindReference(obj);
- }
-
- private void bindReference(Reference obj) {
- int index = obj.getIndex();
-
- ElementSymbol binding = bindings.get(index);
- obj.setExpression(binding);
- }
-
- public void visit(StoredProcedure storedProcedure){
- //collect reference for physical stored procedure
- Iterator<SPParameter> paramsIter = storedProcedure.getParameters().iterator();
- while(paramsIter.hasNext()){
- SPParameter param = paramsIter.next();
- if(param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT){
- if(param.getExpression() instanceof Reference){
- bindReference((Reference)param.getExpression());
- }
- }
- }
- }
-
- /**
- * Convenient static method for using this visitor
- * @param obj LanguageObject which has References to be bound
- * @param bindings List of String binding expressions from query
- * transformation node
- * @param boundReferencesMap Map to be filled with String group name to List of References
- */
- public static void bindReferences(LanguageObject obj, List<ElementSymbol> bindings) {
-
- BindVariableVisitor visitor = new BindVariableVisitor(bindings);
- DeepPreOrderNavigator.doVisit(obj, visitor);
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -28,8 +28,6 @@
import java.util.LinkedList;
import java.util.Map;
-import net.sf.saxon.query.QueryReader;
-
import org.teiid.core.util.Assertion;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.AbstractSetCriteria;
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -1102,11 +1102,11 @@
"SELECT 1 FROM pm1.g2" } ); //$NON-NLS-1$
}
- @Test public void testPushMatchCritWithReference() {
+ @Test public void testPushMatchCritWithReference() throws Exception {
List bindings = new ArrayList();
bindings.add("pm1.g2.e1"); //$NON-NLS-1$
helpPlan("select e1 FROM pm1.g1 WHERE e1 LIKE ?", example1(), bindings, null, //$NON-NLS-1$
- new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 LIKE ?" }, true ); //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 LIKE PM1.G2.e1" }, ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
}
@Test public void testDefect6517() {
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-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -157,9 +157,9 @@
FakeMetadataObject rs = FakeMetadataFactory.createVirtualGroup("xmltest.group.items", xmltest, rsQuery); //$NON-NLS-1$
// Created 2nd virtual group w/ nested result set & binding
- QueryNode rsQuery2 = new QueryNode("xmltest.suppliers", "SELECT concat(stock.suppliers.supplierNum, '') as supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = ?"); //$NON-NLS-1$ //$NON-NLS-2$
+ QueryNode rsQuery2 = new QueryNode("xmltest.suppliers", "SELECT concat(stock.suppliers.supplierNum, '') as supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = input.x"); //$NON-NLS-1$ //$NON-NLS-2$
//QueryNode rsQuery2 = new QueryNode("xmltest.suppliers", "SELECT stock.suppliers.supplierNum, supplierName, supplierZipCode FROM stock.suppliers, stock.item_supplier WHERE stock.suppliers.supplierNum = stock.item_supplier.supplierNum AND stock.item_supplier.itemNum = ?");
- rsQuery2.addBinding("xmltest.group.items.itemNum"); //$NON-NLS-1$
+ rsQuery2.addBinding("xmltest.group.items.itemNum as x"); //$NON-NLS-1$
FakeMetadataObject rs2 = FakeMetadataFactory.createVirtualGroup("xmltest.suppliers", xmltest, rsQuery2); //$NON-NLS-1$
// Created virtual group w/ nested result set & binding
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-02-28 20:23:19 UTC (rev 2951)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-03-01 14:57:25 UTC (rev 2952)
@@ -90,7 +90,6 @@
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.FunctionCollectorVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
-import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
import org.teiid.query.unittest.FakeMetadataFacade;
import org.teiid.query.unittest.FakeMetadataFactory;
import org.teiid.query.unittest.FakeMetadataObject;
@@ -235,8 +234,7 @@
QueryNode qn = new QueryNode("x", sql);
qn.setBindings(bindings);
// resolve
- QueryResolver.addBindingMetadata(command, metadata, qn);
- QueryResolver.resolveCommand(command, metadata);
+ QueryResolver.resolveWithBindingMetadata(command, metadata, qn);
CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
DeepPreOrderNavigator.doVisit(command, vis);
@@ -831,28 +829,30 @@
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "expr" }); //$NON-NLS-1$ //$NON-NLS-2$
helpCheckElements(resolvedQuery.getCriteria(),
- new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
- new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
+ new String[] { "pm1.g1.e1", "pm1.g2.e2" }, //$NON-NLS-1$
+ new String[] { "pm1.g1.e1", "pm1.g2.e2" } ); //$NON-NLS-1$
}
@Test public void testResolveParametersInsert() throws Exception {
- List bindings = new ArrayList();
- bindings.add("pm1.g2.e1"); //$NON-NLS-1$
+ List<String> bindings = Arrays.asList("pm1.g2.e1"); //$NON-NLS-1$
helpResolveWithBindings("INSERT INTO pm1.g1 (e1) VALUES (?)", metadata, bindings); //$NON-NLS-1$
}
@Test public void testResolveParametersExec() throws Exception {
- List bindings = new ArrayList();
- bindings.add("pm1.g2.e1"); //$NON-NLS-1$
+ List<String> bindings = Arrays.asList("pm1.g2.e1"); //$NON-NLS-1$
Query resolvedQuery = (Query)helpResolveWithBindings("SELECT * FROM (exec pm1.sq2(?)) as a", metadata, bindings); //$NON-NLS-1$
- //verify the type of the reference is resolved
- List refs = ReferenceCollectorVisitor.getReferences(resolvedQuery);
- Reference ref = (Reference)refs.get(0);
- assertNotNull(ref.getType());
+ StoredProcedure sp = (StoredProcedure)((SubqueryFromClause)resolvedQuery.getFrom().getClauses().get(0)).getCommand();
+ assertEquals(String.class, sp.getInputParameters().get(0).getExpression().getType());
}
+
+ @Test public void testResolveParametersExecNamed() throws Exception {
+ List<String> bindings = Arrays.asList("pm1.g2.e1 as x"); //$NON-NLS-1$
+
+ helpResolveWithBindings("SELECT * FROM (exec pm1.sq2(input.x)) as a", metadata, bindings); //$NON-NLS-1$
+ }
@Test public void testUseNonExistentAlias() {
helpResolveException("SELECT portfoliob.e1 FROM ((pm1.g1 AS portfoliob JOIN pm1.g2 AS portidentb ON portfoliob.e1 = portidentb.e1) RIGHT OUTER JOIN pm1.g3 AS identifiersb ON portidentb.e1 = 'ISIN' and portidentb.e2 = identifiersb.e2) RIGHT OUTER JOIN pm1.g1 AS issuesb ON a.identifiersb.e1 = issuesb.e1"); //$NON-NLS-1$
13 years, 10 months