Author: shawkins
Date: 2011-02-28 15:23:19 -0500 (Mon, 28 Feb 2011)
New Revision: 2951
Modified:
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/parser/QueryParser.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/DeleteResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1483 consolidating resolving code with designer
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
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/xml/QueryUtil.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -183,9 +182,9 @@
}
static void handleBindings(LanguageObject object, QueryNode planNode,
XMLPlannerEnvironment planEnv)
- throws QueryResolverException, QueryPlannerException, QueryMetadataException,
TeiidComponentException {
+ throws QueryMetadataException, TeiidComponentException {
- List parsedBindings = parseBindings(planNode, planEnv);
+ List parsedBindings = QueryResolver.parseBindings(planNode);
if (!parsedBindings.isEmpty()) {
//use ReferenceBindingReplacer Visitor
@@ -193,24 +192,6 @@
}
}
- static List parseBindings(QueryNode planNode, XMLPlannerEnvironment planEnv) throws
TeiidComponentException {
- Collection bindingsCol = planNode.getBindings();
- if (bindingsCol == null) {
- return Collections.EMPTY_LIST;
- }
-
- List parsedBindings = new ArrayList(bindingsCol.size());
- for (Iterator bindings=bindingsCol.iterator(); bindings.hasNext();) {
- try {
- ElementSymbol binding =
(ElementSymbol)QueryParser.getQueryParser().parseExpression((String)bindings.next());
- parsedBindings.add(binding);
- } catch (QueryParserException err) {
- throw new TeiidComponentException(err);
- }
- }
- return parsedBindings;
- }
-
static Map createSymbolMap(GroupSymbol oldGroup, final String newGroup, Collection
projectedElements) {
HashMap symbolMap = new HashMap();
symbolMap.put(oldGroup, new GroupSymbol(newGroup));
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
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/xml/SourceNodePlannerVisitor.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -43,6 +43,7 @@
import org.teiid.query.mapping.xml.ResultSetInfo;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
@@ -193,12 +194,16 @@
private boolean areBindingsOnlyToNode(QueryNode modifiedNode, MappingSourceNode
sourceNode)
throws TeiidComponentException {
- List bindings = QueryUtil.parseBindings(modifiedNode, planEnv);
+ List<SingleElementSymbol> bindings =
QueryResolver.parseBindings(modifiedNode);
String nodeStr = (sourceNode.getActualResultSetName() +
ElementSymbol.SEPARATOR).toUpperCase();
- for (Iterator i = bindings.iterator(); i.hasNext();) {
- ElementSymbol binding = (ElementSymbol)i.next();
+ for (Iterator<SingleElementSymbol> i = bindings.iterator(); i.hasNext();)
{
+ SingleElementSymbol ses = i.next();
+ if (ses instanceof AliasSymbol) {
+ ses = ((AliasSymbol)ses).getSymbol();
+ }
+ ElementSymbol binding = (ElementSymbol)ses;
if (!binding.getCanonicalName().startsWith(nodeStr)) {
return false;
@@ -259,12 +264,23 @@
static void mapBindings(MappingSourceNode sourceNode,
QueryNode oldQueryNode,
- QueryNode modifiedNode) {
+ QueryNode modifiedNode) throws TeiidComponentException {
if (oldQueryNode.getBindings() != null) {
- List bindings = new ArrayList();
- for (Iterator i = oldQueryNode.getBindings().iterator(); i.hasNext();) {
- String binding = (String)i.next();
- bindings.add(sourceNode.getMappedSymbol(new
ElementSymbol(binding)).getName());
+ List<String> bindings = new ArrayList<String>();
+ for (Iterator<SingleElementSymbol> i =
QueryResolver.parseBindings(oldQueryNode).iterator(); i.hasNext();) {
+ SingleElementSymbol ses = i.next();
+ String name = ses.getName();
+ boolean useName = false;
+ if (ses instanceof AliasSymbol) {
+ ses = ((AliasSymbol)ses).getSymbol();
+ useName = true;
+ }
+ ElementSymbol es = (ElementSymbol)ses;
+ if (!useName) {
+ bindings.add(sourceNode.getMappedSymbol(es).getName());
+ } else {
+ bindings.add(new AliasSymbol(name,
sourceNode.getMappedSymbol(es)).toString());
+ }
}
modifiedNode.setBindings(bindings);
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2011-02-28 15:56:45
UTC (rev 2950)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2011-02-28 20:23:19
UTC (rev 2951)
@@ -30,6 +30,7 @@
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
/**
* <p>Converts a SQL-string to an object version of a query. This
@@ -215,7 +216,27 @@
}
return result;
}
+
+ public SingleElementSymbol parseSelectExpression(String sql) throws
QueryParserException {
+ if(sql == null) {
+ throw new
IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr"));
//$NON-NLS-1$
+ }
+ ParseInfo dummyInfo = new ParseInfo();
+
+ SingleElementSymbol result = null;
+ try{
+ result = getSqlParser(sql).selectExpression(dummyInfo);
+
+ } catch(ParseException pe) {
+ throw convertParserException(pe);
+
+ } catch(TokenMgrError tme) {
+ throw handleTokenMgrError(tme);
+ }
+ return result;
+ }
+
private QueryParserException handleTokenMgrError(TokenMgrError tme) {
// LogManager.logError( LogConstants.CTX_QUERY_PARSER, tme, new Object[]
{"Exception parsing: ", sql} );
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -29,6 +29,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
@@ -36,6 +37,7 @@
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.StoredProcedureInfo;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.metadata.TempMetadataStore;
@@ -45,11 +47,9 @@
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.Delete;
import org.teiid.query.sql.lang.GroupContext;
-import org.teiid.query.sql.lang.Insert;
import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.proc.TriggerAction;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -101,46 +101,6 @@
throw new QueryResolverException(e, "ERR.015.008.0045",
QueryPlugin.Util.getString("ERR.015.008.0045", group)); //$NON-NLS-1$
//$NON-NLS-2$
}
- if(subCommand instanceof CreateUpdateProcedureCommand){
- CreateUpdateProcedureCommand cupCommand =
(CreateUpdateProcedureCommand)subCommand;
- //if the subcommand is virtual stored procedure, it must have the same
- //projected symbol as its parent.
- if(!cupCommand.isUpdateProcedure()){
- cupCommand.setProjectedSymbols(procCommand.getProjectedSymbols());
- }
-
- cupCommand.setVirtualGroup(procCommand.getGroup());
- cupCommand.setUserCommand(procCommand);
- } else if (subCommand instanceof TriggerAction) {
- TriggerAction ta = (TriggerAction)subCommand;
- ta.setView(procCommand.getGroup());
- TempMetadataAdapter tma = new TempMetadataAdapter(metadata, new
TempMetadataStore());
- ta.setTemporaryMetadata(tma.getMetadataStore().getData());
- GroupContext externalGroups = ta.getExternalGroupContexts();
- //TODO: it seems easier to just inline the handling here rather than have
each of the resolvers check for trigger actions
- List<ElementSymbol> viewElements =
ResolverUtil.resolveElementsInGroup(ta.getView(), metadata);
- if (procCommand instanceof Update || procCommand instanceof Insert) {
- addChanging(tma.getMetadataStore(), externalGroups, viewElements);
- ProcedureContainerResolver.addScalarGroup(SQLConstants.Reserved.NEW,
tma.getMetadataStore(), externalGroups, viewElements, false);
- }
- if (procCommand instanceof Update || procCommand instanceof Delete) {
- ProcedureContainerResolver.addScalarGroup(SQLConstants.Reserved.OLD,
tma.getMetadataStore(), externalGroups, viewElements, false);
- }
- QueryResolver.setChildMetadata(subCommand, tma.getMetadataStore().getData(),
externalGroups);
- QueryResolver.resolveCommand(subCommand, metadata);
- return ta;
- }
-
- //find the childMetadata using a clean metadata store
- TempMetadataStore childMetadata = new TempMetadataStore();
- QueryMetadataInterface resolveMetadata = new TempMetadataAdapter(metadata,
childMetadata);
-
- GroupContext externalGroups = findChildCommandMetadata(procCommand,
childMetadata, resolveMetadata);
-
- QueryResolver.setChildMetadata(subCommand, childMetadata.getData(),
externalGroups);
-
- QueryResolver.resolveCommand(subCommand, metadata);
-
return subCommand;
}
@@ -157,52 +117,7 @@
GroupSymbol group) throws TeiidComponentException,
QueryMetadataException,
QueryResolverException;
- /**
- * Find all metadata defined by this command for it's children. This metadata
should be collected
- * in the childMetadata object. Typical uses of this are for stored queries that
define parameter
- * variables valid in subcommands. only used for inserts, updates, and deletes
- * @param metadata Metadata access
- * @param command The command to find metadata on
- * @param childMetadata The store to collect child metadata in
- * @throws QueryMetadataException If there is a metadata problem
- * @throws QueryResolverException If the query cannot be resolved
- * @throws TeiidComponentException If there is an internal error
- */
- public GroupContext findChildCommandMetadata(ProcedureContainer container,
TempMetadataStore discoveredMetadata, QueryMetadataInterface metadata)
- throws QueryMetadataException, QueryResolverException, TeiidComponentException {
- // get the group on the delete statement
- GroupSymbol group = container.getGroup();
- // proceed further if it is a virtual group
-
- return createChildMetadata(discoveredMetadata, metadata, group);
- }
-
- static GroupContext createChildMetadata(
- TempMetadataStore discoveredMetadata,
- QueryMetadataInterface metadata, GroupSymbol group)
- throws QueryMetadataException, TeiidComponentException {
- GroupContext externalGroups = new GroupContext();
-
- //Look up elements for the virtual group
- List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(group,
metadata);
-
- // Create the INPUT variables
- List<ElementSymbol> inputElments = new
ArrayList<ElementSymbol>(elements.size());
- for(int i=0; i<elements.size(); i++) {
- ElementSymbol virtualElmnt = elements.get(i);
- ElementSymbol inputElement = (ElementSymbol)virtualElmnt.clone();
- inputElments.add(inputElement);
- }
-
- addScalarGroup(ProcedureReservedWords.INPUT, discoveredMetadata, externalGroups,
inputElments, false);
- addScalarGroup(ProcedureReservedWords.INPUTS, discoveredMetadata, externalGroups,
inputElments, false);
-
- // Switch type to be boolean for all CHANGING variables
- addChanging(discoveredMetadata, externalGroups, elements);
- return externalGroups;
- }
-
- private static void addChanging(TempMetadataStore discoveredMetadata,
+ public static void addChanging(TempMetadataStore discoveredMetadata,
GroupContext externalGroups, List<ElementSymbol> elements) {
List<ElementSymbol> changingElements = new
ArrayList<ElementSymbol>(elements.size());
for(int i=0; i<elements.size(); i++) {
@@ -340,5 +255,81 @@
variables.setMetadataID(tid);
return variables;
}
+
+ /**
+ * Set the appropriate "external" metadata for the given command
+ */
+ public static void findChildCommandMetadata(Command currentCommand,
+ GroupSymbol container, int type, QueryMetadataInterface metadata)
+ throws QueryMetadataException, TeiidComponentException {
+ //find the childMetadata using a clean metadata store
+ TempMetadataStore childMetadata = new TempMetadataStore();
+ TempMetadataAdapter tma = new TempMetadataAdapter(metadata, childMetadata);
+ GroupContext externalGroups = new GroupContext();
+
+ if (currentCommand instanceof TriggerAction) {
+ TriggerAction ta = (TriggerAction)currentCommand;
+ ta.setView(container);
+ //TODO: it seems easier to just inline the handling here rather than have each of
the resolvers check for trigger actions
+ List<ElementSymbol> viewElements =
ResolverUtil.resolveElementsInGroup(ta.getView(), metadata);
+ if (type == Command.TYPE_UPDATE || type == Command.TYPE_INSERT) {
+ ProcedureContainerResolver.addChanging(tma.getMetadataStore(), externalGroups,
viewElements);
+ ProcedureContainerResolver.addScalarGroup(SQLConstants.Reserved.NEW,
tma.getMetadataStore(), externalGroups, viewElements, false);
+ }
+ if (type == Command.TYPE_UPDATE || type == Command.TYPE_DELETE) {
+ ProcedureContainerResolver.addScalarGroup(SQLConstants.Reserved.OLD,
tma.getMetadataStore(), externalGroups, viewElements, false);
+ }
+ } else if (currentCommand instanceof CreateUpdateProcedureCommand) {
+ CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)currentCommand;
+ cupc.setVirtualGroup(container);
+
+ if (type == Command.TYPE_STORED_PROCEDURE) {
+ StoredProcedureInfo info =
metadata.getStoredProcedureInfoForProcedure(container.getCanonicalName());
+ // Create temporary metadata that defines a group based on either the stored
proc
+ // name or the stored query name - this will be used later during planning
+ String procName = metadata.getFullName(info.getProcedureID());
+
+ // Look through parameters to find input elements - these become child
metadata
+ List<ElementSymbol> tempElements = new
ArrayList<ElementSymbol>(info.getParameters().size());
+ boolean[] updatable = new boolean[info.getParameters().size()];
+ int i = 0;
+ for (SPParameter param : info.getParameters()) {
+ if(param.getParameterType() != ParameterInfo.RESULT_SET) {
+ ElementSymbol symbol = param.getParameterSymbol();
+ tempElements.add(symbol);
+ updatable[i++] = param.getParameterType() != ParameterInfo.IN;
+ }
+ }
+
+ ProcedureContainerResolver.addScalarGroup(procName, childMetadata,
externalGroups, tempElements, updatable);
+ } else if (type != Command.TYPE_DELETE) {
+ createInputChangingMetadata(childMetadata, tma, container, externalGroups);
+ }
+ }
+
+ QueryResolver.setChildMetadata(currentCommand, childMetadata.getData(),
externalGroups);
+ }
+
+ static void createInputChangingMetadata(
+ TempMetadataStore discoveredMetadata,
+ QueryMetadataInterface metadata, GroupSymbol group, GroupContext externalGroups)
+ throws QueryMetadataException, TeiidComponentException {
+ //Look up elements for the virtual group
+ List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(group,
metadata);
+
+ // Create the INPUT variables
+ List<ElementSymbol> inputElments = new
ArrayList<ElementSymbol>(elements.size());
+ for(int i=0; i<elements.size(); i++) {
+ ElementSymbol virtualElmnt = elements.get(i);
+ ElementSymbol inputElement = (ElementSymbol)virtualElmnt.clone();
+ inputElments.add(inputElement);
+ }
+
+ ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUT,
discoveredMetadata, externalGroups, inputElments, false);
+ ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.INPUTS,
discoveredMetadata, externalGroups, inputElments, false);
+
+ // Switch type to be boolean for all CHANGING variables
+ ProcedureContainerResolver.addChanging(discoveredMetadata, externalGroups,
elements);
+ }
}
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
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -22,9 +22,11 @@
package org.teiid.query.resolver;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -57,6 +59,7 @@
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;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.From;
@@ -66,9 +69,12 @@
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.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.SingleElementSymbol;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.validator.ValidationVisitor;
@@ -96,7 +102,21 @@
public static Command expandCommand(ProcedureContainer proc, QueryMetadataInterface
metadata, AnalysisRecord analysisRecord) throws QueryResolverException,
QueryMetadataException, TeiidComponentException {
ProcedureContainerResolver cr = (ProcedureContainerResolver)chooseResolver(proc,
metadata);
- return cr.expandCommand(proc, metadata, analysisRecord);
+ Command command = cr.expandCommand(proc, metadata, analysisRecord);
+ if (command == null) {
+ return null;
+ }
+ if (command instanceof CreateUpdateProcedureCommand) {
+ CreateUpdateProcedureCommand cupCommand = (CreateUpdateProcedureCommand)command;
+ cupCommand.setUserCommand(proc);
+ //if the subcommand is virtual stored procedure, it must have the same
+ //projected symbol as its parent.
+ if(!cupCommand.isUpdateProcedure()){
+ cupCommand.setProjectedSymbols(proc.getProjectedSymbols());
+ }
+ }
+ resolveCommand(command, proc.getGroup(), proc.getType(), metadata);
+ return command;
}
/**
@@ -117,6 +137,93 @@
return resolveCommand(command, metadata, true);
}
+ /**
+ * Resolve a command in a given type container and type context.
+ * @param type The {@link Command} type
+ */
+ public static TempMetadataStore resolveCommand(Command currentCommand, GroupSymbol
container, int type, QueryMetadataInterface metadata) throws QueryResolverException,
TeiidComponentException {
+ ResolverUtil.resolveGroup(container, metadata);
+ switch (type) {
+ case Command.TYPE_QUERY:
+ QueryNode queryNode =
metadata.getVirtualPlan(metadata.getGroupID(container.getCanonicalName()));
+
+ addBindingMetadata(currentCommand, metadata, queryNode);
+ break;
+ 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);
+ }
+
+ static void addBindingMetadata(Command currentCommand,
+ QueryMetadataInterface metadata, QueryNode queryNode)
+ throws TeiidComponentException, QueryResolverException {
+ if (queryNode.getBindings() != null && queryNode.getBindings().size() > 0)
{
+ // 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());
+ boolean positional = true;
+ for (SingleElementSymbol ses : parseBindings(queryNode)) {
+ String name = ses.getName();
+ if (ses instanceof AliasSymbol) {
+ ses = ((AliasSymbol)ses).getSymbol();
+ positional = false;
+ }
+ ElementSymbol elementSymbol = (ElementSymbol)ses;
+ ResolverVisitor.resolveLanguageObject(elementSymbol, metadata);
+ if (!positional) {
+ elementSymbol.setName(name);
+ }
+ elements.add(elementSymbol);
+ }
+ if (positional) {
+ BindVariableVisitor.bindReferences(currentCommand, elements);
+ } 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());
+ }
+ }
+ }
+ }
+
+ /**
+ * 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.
+ * @param planNode
+ * @return
+ * @throws TeiidComponentException
+ */
+ public static List<SingleElementSymbol> parseBindings(QueryNode planNode)
throws TeiidComponentException {
+ Collection<String> bindingsCol = planNode.getBindings();
+ if (bindingsCol == null) {
+ return Collections.emptyList();
+ }
+
+ List<SingleElementSymbol> parsedBindings = new
ArrayList<SingleElementSymbol>(bindingsCol.size());
+ for (Iterator<String> bindings=bindingsCol.iterator(); bindings.hasNext();)
{
+ try {
+ SingleElementSymbol binding =
QueryParser.getQueryParser().parseSelectExpression(bindings.next());
+ parsedBindings.add(binding);
+ } catch (QueryParserException err) {
+ throw new TeiidComponentException(err);
+ }
+ }
+ return parsedBindings;
+ }
+
public static TempMetadataStore resolveCommand(Command currentCommand,
QueryMetadataInterface metadata, boolean resolveNullLiterals)
throws QueryResolverException, TeiidComponentException {
@@ -295,7 +402,7 @@
result = (Command)result.clone();
} else {
result = qnode.getCommand();
-
+ List bindings = null;
if (result == null) {
try {
result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
@@ -303,33 +410,17 @@
throw new QueryResolverException(e, "ERR.015.008.0011",
QueryPlugin.Util.getString("ERR.015.008.0011", qnode.getGroupName()));
//$NON-NLS-1$ //$NON-NLS-2$
}
- //Handle bindings and references
- List bindings = qnode.getBindings();
- if (bindings != null){
- BindVariableVisitor.bindReferences(result, bindings, qmi);
- }
+ bindings = qnode.getBindings();
}
- QueryResolver.resolveCommand(result, qmi);
+ if (bindings != null && !bindings.isEmpty()) {
+ QueryResolver.resolveCommand(result, virtualGroup, Command.TYPE_QUERY,
qmi);
+ } else {
+ QueryResolver.resolveCommand(result, qmi);
+ }
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
qmi.addToMetadataCache(virtualGroup.getMetadataID(), "transformation/"
+ cacheString, result.clone()); //$NON-NLS-1$
}
return result;
}
- public static void buildExternalGroups(Map<GroupSymbol, List<ElementSymbol>>
externalMetadata, Command currentCommand) {
- TempMetadataStore rootExternalStore = new TempMetadataStore();
- for(Map.Entry<GroupSymbol, List<ElementSymbol>> entry :
externalMetadata.entrySet()) {
- GroupSymbol group = entry.getKey();
- List<ElementSymbol> elements = entry.getValue();
- rootExternalStore.addTempGroup(group.getName(), elements);
- currentCommand.addExternalGroupToContext(group);
- }
- Map tempMetadata = currentCommand.getTemporaryMetadata();
- if(tempMetadata == null) {
- currentCommand.setTemporaryMetadata(rootExternalStore.getData());
- } else {
- tempMetadata.putAll(rootExternalStore.getData());
- }
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/DeleteResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/DeleteResolver.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/DeleteResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -30,14 +30,11 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
-import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.resolver.ProcedureContainerResolver;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.GroupContext;
-import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -74,12 +71,4 @@
return metadata.getDeletePlan(group.getMetadataID());
}
- @Override
- public GroupContext findChildCommandMetadata(ProcedureContainer container,
- TempMetadataStore discoveredMetadata, QueryMetadataInterface metadata) throws
QueryMetadataException,
- QueryResolverException, TeiidComponentException {
- //defect 16451: don't expose input and changing variables to delete procedures
- return null;
- }
-
}
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
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -50,7 +50,6 @@
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
@@ -221,36 +220,6 @@
storedProcedureCommand.setGroup(procGroup);
}
- @Override
- public GroupContext findChildCommandMetadata(ProcedureContainer container,
- TempMetadataStore discoveredMetadata, QueryMetadataInterface metadata) throws
QueryMetadataException,
- QueryResolverException, TeiidComponentException {
-
- StoredProcedure storedProcedureCommand = (StoredProcedure) container;
-
- // Create temporary metadata that defines a group based on either the stored
proc
- // name or the stored query name - this will be used later during planning
- String procName = metadata.getFullName(storedProcedureCommand.getProcedureID());
-
- GroupContext context = new GroupContext();
-
- // Look through parameters to find input elements - these become child metadata
- List<ElementSymbol> tempElements = new
ArrayList<ElementSymbol>(storedProcedureCommand.getParameters().size());
- boolean[] updatable = new
boolean[storedProcedureCommand.getParameters().size()];
- int i = 0;
- for (SPParameter param : storedProcedureCommand.getParameters()) {
- if(param.getParameterType() != ParameterInfo.RESULT_SET) {
- ElementSymbol symbol = param.getParameterSymbol();
- tempElements.add(symbol);
- updatable[i++] = param.getParameterType() != ParameterInfo.IN;
- }
- }
-
- ProcedureContainerResolver.addScalarGroup(procName, discoveredMetadata, context,
tempElements, updatable);
-
- return context;
- }
-
/**
* @see
org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command,
org.teiid.query.metadata.TempMetadataAdapter)
*/
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -148,11 +148,7 @@
QueryResolver.setChildMetadata(queryExpression, query);
- try {
- QueryResolver.resolveCommand(queryExpression, metadata.getMetadata(),
false);
- } catch (TeiidException err) {
- throw new TeiidRuntimeException(err);
- }
+ QueryResolver.resolveCommand(queryExpression, metadata.getMetadata(),
false);
if (!discoveredGroups.add(obj.getGroupSymbol())) {
throw new
QueryResolverException(QueryPlugin.Util.getString("SimpleQueryResolver.duplicate_with",
obj.getGroupSymbol())); //$NON-NLS-1$
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -86,30 +86,12 @@
// virtual group on procedure
GroupSymbol virtualGroup = procCommand.getVirtualGroup();
-
- // not set by user command resolver in case of modeler
- if(virtualGroup == null) {
- for (GroupSymbol groupSymbol : procCommand.getAllExternalGroups()) {
- String groupName = groupSymbol.getName();
- if(!groupName.equalsIgnoreCase(ProcedureReservedWords.INPUT) &&
- !groupName.equalsIgnoreCase(ProcedureReservedWords.INPUTS) &&
- !groupName.equalsIgnoreCase(ProcedureReservedWords.CHANGING) ) {
- // set the groupSymbol on the procedure
- ResolverUtil.resolveGroup(groupSymbol, metadata);
- procCommand.setVirtualGroup(groupSymbol);
- virtualGroup = groupSymbol;
- break;
- }
- }
- } else if (!metadata.isVirtualGroup(virtualGroup.getMetadataID())) {
+
+ if (!metadata.isVirtualGroup(virtualGroup.getMetadataID())) {
+ //if this is a compensating procedure, just return
return;
}
- // If still haven't found virtual group, the external metadata is bad
- if(virtualGroup == null) {
- throw new QueryResolverException("ERR.015.008.0012",
QueryPlugin.Util.getString("ERR.015.008.0012")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
ResolveVirtualGroupCriteriaVisitor.resolveCriteria(procCommand, virtualGroup,
metadata);
// get a symbol map between virtual elements and the elements that define
@@ -215,19 +197,16 @@
if (subCommand instanceof StoredProcedure) {
StoredProcedure sp = (StoredProcedure)subCommand;
for (SPParameter param : sp.getParameters()) {
- if (!(param.getExpression() instanceof ElementSymbol)) {
- continue;
- }
switch (param.getParameterType()) {
case ParameterInfo.OUT:
case ParameterInfo.RETURN_VALUE:
- if (param.getExpression() instanceof ElementSymbol &&
!metadata.elementSupports(((ElementSymbol)param.getExpression()).getMetadataID(),
SupportConstants.Element.UPDATE)) {
+ if (!isAssignable(metadata, param)) {
throw new
QueryResolverException(QueryPlugin.Util.getString("UpdateProcedureResolver.only_variables",
param.getExpression())); //$NON-NLS-1$
}
sp.setCallableStatement(true);
break;
case ParameterInfo.INOUT:
- if (param.getExpression() instanceof ElementSymbol &&
!metadata.elementSupports(((ElementSymbol)param.getExpression()).getMetadataID(),
SupportConstants.Element.UPDATE)) {
+ if (!isAssignable(metadata, param)) {
continue;
}
sp.setCallableStatement(true);
@@ -347,6 +326,16 @@
}
}
+ private boolean isAssignable(TempMetadataAdapter metadata, SPParameter param)
+ throws TeiidComponentException, QueryMetadataException {
+ if (!(param.getExpression() instanceof ElementSymbol)) {
+ return false;
+ }
+ ElementSymbol symbol = (ElementSymbol)param.getExpression();
+
+ return metadata.elementSupports(symbol.getMetadataID(),
SupportConstants.Element.UPDATE);
+ }
+
private TempMetadataStore resolveEmbeddedCommand(TempMetadataAdapter metadata,
GroupContext groupContext,
Command cmd) throws TeiidComponentException,
QueryResolverException {
Modified:
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
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/util/BindVariableVisitor.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -22,27 +22,18 @@
package org.teiid.query.resolver.util;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.client.metadata.ParameterInfo;
-import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.ArgCheck;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.parser.QueryParser;
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.Expression;
-import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
@@ -61,47 +52,19 @@
*/
public class BindVariableVisitor extends LanguageVisitor {
- private List bindings;
- private QueryMetadataInterface metadata;
+ private List<ElementSymbol> bindings;
- private TeiidComponentException componentException;
- private QueryResolverException resolverException;
-
/**
* Constructor
* @param bindings List of String binding expressions from query
* transformation node
- * @param metadata source of metadata
*/
- public BindVariableVisitor(List bindings, QueryMetadataInterface metadata) {
+ public BindVariableVisitor(List<ElementSymbol> bindings) {
ArgCheck.isNotNull(bindings, QueryPlugin.Util.getString("ERR.015.008.0049"));
//$NON-NLS-1$
this.bindings = bindings;
- this.metadata = metadata;
}
- public TeiidComponentException getComponentException() {
- return this.componentException;
- }
-
- public QueryResolverException getResolverException() {
- return this.resolverException;
- }
-
- private void handleException(TeiidComponentException e) {
- this.componentException = e;
-
- // Abort the validation process
- setAbort(true);
- }
-
- private void handleException(QueryResolverException e) {
- this.resolverException = e;
-
- // Abort the validation process
- setAbort(true);
- }
-
/**
* Visit a Reference object and bind it based on the bindings
* @see org.teiid.query.sql.LanguageVisitor#visit(Reference)
@@ -113,25 +76,15 @@
private void bindReference(Reference obj) {
int index = obj.getIndex();
- String binding = (String) bindings.get(index);
- try {
- bindReference(obj, binding);
- } catch(QueryParserException e) {
- handleException(new
QueryResolverException(QueryPlugin.Util.getString("ERR.015.008.0022"),
e.getMessage())); //$NON-NLS-1$
- } catch(QueryMetadataException e) {
- handleException(new TeiidComponentException(e, e.getMessage()));
- } catch(QueryResolverException e) {
- handleException(e);
- } catch(TeiidComponentException e) {
- handleException(e);
- }
+ ElementSymbol binding = bindings.get(index);
+ obj.setExpression(binding);
}
public void visit(StoredProcedure storedProcedure){
//collect reference for physical stored procedure
- Iterator paramsIter = storedProcedure.getParameters().iterator();
+ Iterator<SPParameter> paramsIter =
storedProcedure.getParameters().iterator();
while(paramsIter.hasNext()){
- SPParameter param = (SPParameter)paramsIter.next();
+ SPParameter param = paramsIter.next();
if(param.getParameterType() == ParameterInfo.IN || param.getParameterType()
== ParameterInfo.INOUT){
if(param.getExpression() instanceof Reference){
bindReference((Reference)param.getExpression());
@@ -140,48 +93,17 @@
}
}
- private void bindReference(Reference reference, String binding)
- throws QueryParserException, QueryResolverException,
- QueryMetadataException, TeiidComponentException {
-
- // Parse and resolve ref
- Expression expr = QueryParser.getQueryParser().parseExpression(binding);
-
- if(!(expr instanceof ElementSymbol)) {
- throw new QueryResolverException("ERR.015.008.0025",
QueryPlugin.Util.getString("ERR.015.008.0025", expr)); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
- ElementSymbol element = (ElementSymbol) expr;
-
- GroupSymbol groupSymbol = new
GroupSymbol(metadata.getGroupName(element.getName()));
- ResolverUtil.resolveGroup(groupSymbol, metadata);
-
- ResolverVisitor.resolveLanguageObject(element, Arrays.asList(groupSymbol),
metadata);
-
- reference.setExpression(element);
- }
-
/**
* 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 metadata source of metadata
* @param boundReferencesMap Map to be filled with String group name to List of
References
*/
- public static void bindReferences(LanguageObject obj, List bindings,
QueryMetadataInterface metadata)
- throws QueryResolverException, TeiidComponentException {
+ public static void bindReferences(LanguageObject obj, List<ElementSymbol>
bindings) {
- BindVariableVisitor visitor = new BindVariableVisitor(bindings, metadata);
+ BindVariableVisitor visitor = new BindVariableVisitor(bindings);
DeepPreOrderNavigator.doVisit(obj, visitor);
-
- if(visitor.getComponentException() != null) {
- throw visitor.getComponentException();
- }
-
- if(visitor.getResolverException() != null) {
- throw visitor.getResolverException();
- }
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2011-02-28
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/StoredProcedure.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -188,18 +188,18 @@
return null;
}
- public List getResultSetColumns(){
+ public List<ElementSymbol> getResultSetColumns(){
SPParameter resultSetParameter = getResultSetParameter();
if(resultSetParameter != null){
- List result = new LinkedList();
- for (Iterator i = resultSetParameter.getResultSetColumns().iterator();
i.hasNext();) {
- ElementSymbol symbol = (ElementSymbol)((ElementSymbol)i.next()).clone();
+ List<ElementSymbol> result = new LinkedList<ElementSymbol>();
+ for (Iterator<ElementSymbol> i =
resultSetParameter.getResultSetColumns().iterator(); i.hasNext();) {
+ ElementSymbol symbol = (ElementSymbol)i.next().clone();
symbol.setGroupSymbol(getGroup());
result.add(symbol);
}
return result;
}
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
public void acceptVisitor(LanguageVisitor visitor) {
Modified:
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/main/java/org/teiid/query/sql/proc/CreateUpdateProcedureCommand.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -33,7 +33,9 @@
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -233,7 +235,14 @@
//user may have not entered any query yet
return Collections.EMPTY_LIST;
}
- setProjectedSymbols(this.resultsCommand.getProjectedSymbols());
+ List<? extends SingleElementSymbol> symbols =
this.resultsCommand.getProjectedSymbols();
+ if (this.resultsCommand instanceof StoredProcedure) {
+ StoredProcedure sp = (StoredProcedure)this.resultsCommand;
+ if (sp.isCallableStatement()) {
+ symbols = sp.getResultSetColumns();
+ }
+ }
+ setProjectedSymbols(symbols);
return this.projectedSymbols;
}
this.projectedSymbols = Command.getUpdateCommandSymbol();
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-02-28 15:56:45
UTC (rev 2950)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2011-02-28 20:23:19
UTC (rev 2951)
@@ -93,7 +93,6 @@
ERR.015.008.0009= {1} is not allowed on the view {0}: a procedure must be defined to
handle the {1}.
ERR.015.008.0010= INSERT statement must have the same number of elements and values
specified. This statement has {0} elements and {1} values.
ERR.015.008.0011= Error parsing query plan transformation for {0}
-ERR.015.008.0012= Unable to resolve update procedure as the virtual group context is
ambiguous.
ERR.015.008.0013= Error parsing query plan transformation for {0}
ERR.015.008.0015= Unknown statement type: {0}
ERR.015.008.0019= Unable to resolve element: {0}
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
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -74,7 +74,7 @@
import org.teiid.query.processor.relational.UnionAllNode;
import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.resolver.util.BindVariableVisitor;
+import org.teiid.query.resolver.TestResolver;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -196,11 +196,14 @@
public static Command helpGetCommand(String sql, QueryMetadataInterface md, List
bindings) throws TeiidComponentException, TeiidProcessingException {
if(DEBUG) System.out.println("\n####################################\n" +
sql); //$NON-NLS-1$
- Command command = QueryParser.getQueryParser().parseCommand(sql);
+ Command command = null;
+ if (bindings != null && !bindings.isEmpty()) {
+ command = TestResolver.helpResolveWithBindings(sql, md, bindings);
+ } else {
+ command = QueryParser.getQueryParser().parseCommand(sql);
+ QueryResolver.resolveCommand(command, md);
+ }
- // resolve
- QueryResolver.resolveCommand(command, md);
-
ValidatorReport repo = Validator.validate(command, md);
Collection failures = new ArrayList();
@@ -209,11 +212,6 @@
fail("Exception during validation (" + repo); //$NON-NLS-1$
}
- // bind variables
- if(bindings != null) {
- BindVariableVisitor.bindReferences(command, bindings, md);
- }
-
// rewrite
command = QueryRewriter.rewrite(command, md, new CommandContext());
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -25,8 +25,6 @@
import static org.junit.Assert.*;
import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.junit.Test;
@@ -41,12 +39,8 @@
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.parser.QueryParser;
-import org.teiid.query.resolver.ProcedureContainerResolver;
-import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.GroupContext;
import org.teiid.query.sql.lang.Insert;
import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.proc.AssignmentStatement;
@@ -101,27 +95,6 @@
}
}
- public static Map getProcedureExternalMetadata(GroupSymbol virtualGroup,
QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
- Map externalMetadata = new HashMap();
-
- //TODO: it doesn't seem like these should be in the
- List<ElementSymbol> elements =
ResolverUtil.resolveElementsInGroup(virtualGroup, metadata);
- externalMetadata.put(virtualGroup, elements);
-
- TempMetadataStore tms = new TempMetadataStore();
-
- TempMetadataAdapter tma = new TempMetadataAdapter(metadata, tms);
-
- GroupContext gc = ProcedureContainerResolver.createChildMetadata(tms, metadata,
virtualGroup);
-
- for (GroupSymbol symbol : gc.getAllGroups()) {
- externalMetadata.put(symbol, ResolverUtil.resolveElementsInGroup(symbol, tma));
- }
-
- return externalMetadata;
- }
-
@Test public void testDefect13029_CorrectlySetUpdateProcedureTempGroupIDs() throws
Exception {
StringBuffer proc = new StringBuffer("CREATE VIRTUAL PROCEDURE")
//$NON-NLS-1$
.append("\nBEGIN") //$NON-NLS-1$
@@ -843,9 +816,7 @@
Command procCommand = QueryParser.getQueryParser().parseCommand(procedure);
GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
- Map externalMetadata = getProcedureExternalMetadata(virtualGroup, metadata);
- QueryResolver.buildExternalGroups(externalMetadata, procCommand);
- QueryResolver.resolveCommand(procCommand, metadata);
+ QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_UPDATE,
metadata);
}
// special variable CHANGING compared against integer no implicit conversion available
@@ -881,9 +852,7 @@
GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
- Map externalMetadata = getProcedureExternalMetadata(virtualGroup, metadata);
- QueryResolver.buildExternalGroups(externalMetadata, procCommand);
- QueryResolver.resolveCommand(procCommand, metadata);
+ QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_INSERT,
metadata);
}
// special variable CHANGING compared against integer no implicit conversion available
@@ -900,9 +869,7 @@
GroupSymbol virtualGroup = new GroupSymbol("vm1.g1"); //$NON-NLS-1$
virtualGroup.setMetadataID(metadata.getGroupID("vm1.g1")); //$NON-NLS-1$
- Map externalMetadata = getProcedureExternalMetadata(virtualGroup, metadata);
- QueryResolver.buildExternalGroups(externalMetadata, procCommand);
- QueryResolver.resolveCommand(procCommand, metadata);
+ QueryResolver.resolveCommand(procCommand, virtualGroup, Command.TYPE_UPDATE,
metadata);
}
// TranslateCriteria on criteria of the if statement
@@ -1046,18 +1013,6 @@
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
- // no user command provided - should throw resolver exception
- @Test public void testCreateUpdateProcedure56() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = 1+ROWS_UPDATED;"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- TestResolver.helpResolveException(procedure,
FakeMetadataFactory.example1Cached(), "Error Code:ERR.015.008.0012 Message:Unable to
resolve update procedure as the virtual group context is ambiguous."); //$NON-NLS-1$
- }
-
@Test public void
testDefect14912_CreateUpdateProcedure57_FunctionWithElementParamInAssignmentStatement() {
// Tests that the function params are resolved before the function for assignment
statements
String procedure = "CREATE PROCEDURE "; //$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-02-28
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -57,7 +57,6 @@
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.optimizer.FakeFunctionMetadataSource;
import org.teiid.query.parser.QueryParser;
-import org.teiid.query.resolver.util.BindVariableVisitor;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.ProcedureReservedWords;
import org.teiid.query.sql.lang.BatchedUpdateCommand;
@@ -228,26 +227,16 @@
return criteria;
}
- private Command helpResolve(String sql, List bindings) {
+ public static Command helpResolveWithBindings(String sql, QueryMetadataInterface
metadata, List bindings) throws QueryResolverException, TeiidComponentException {
// parse
Command command = helpParse(sql);
- // apply bindings
- if(bindings != null) {
- try {
- BindVariableVisitor.bindReferences(command, bindings, metadata);
- } catch(TeiidException e) {
- fail("Exception during binding (" + e.getClass().getName() +
"): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
+ QueryNode qn = new QueryNode("x", sql);
+ qn.setBindings(bindings);
// resolve
- try {
- QueryResolver.resolveCommand(command, metadata);
- } catch(TeiidException e) {
- fail("Exception during resolution (" + e.getClass().getName() +
"): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ QueryResolver.addBindingMetadata(command, metadata, qn);
+ QueryResolver.resolveCommand(command, metadata);
CheckSymbolsAreResolvedVisitor vis = new CheckSymbolsAreResolvedVisitor();
DeepPreOrderNavigator.doVisit(command, vis);
@@ -832,12 +821,12 @@
helpResolveException("SELECT dayofmonth('2002-01-01') FROM pm1.g1",
"Error Code:ERR.015.008.0040 Message:The function
'dayofmonth('2002-01-01')' is a valid function form, but the arguments do
not match a known type signature and cannot be converted using implicit type
conversions."); //$NON-NLS-1$ //$NON-NLS-2$
}
- @Test public void testResolveParameters() {
+ @Test public void testResolveParameters() throws Exception {
List bindings = new ArrayList();
bindings.add("pm1.g2.e1"); //$NON-NLS-1$
bindings.add("pm1.g2.e2"); //$NON-NLS-1$
- Query resolvedQuery = (Query) helpResolve("SELECT pm1.g1.e1, ? FROM pm1.g1
WHERE pm1.g1.e1 = ?", bindings); //$NON-NLS-1$
+ Query resolvedQuery = (Query) helpResolveWithBindings("SELECT pm1.g1.e1, ?
FROM pm1.g1 WHERE pm1.g1.e1 = ?", metadata, bindings); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1",
"expr" }); //$NON-NLS-1$ //$NON-NLS-2$
@@ -847,18 +836,18 @@
}
- @Test public void testResolveParametersInsert() {
+ @Test public void testResolveParametersInsert() throws Exception {
List bindings = new ArrayList();
bindings.add("pm1.g2.e1"); //$NON-NLS-1$
- helpResolve("INSERT INTO pm1.g1 (e1) VALUES (?)", bindings);
//$NON-NLS-1$
+ helpResolveWithBindings("INSERT INTO pm1.g1 (e1) VALUES (?)", metadata,
bindings); //$NON-NLS-1$
}
- @Test public void testResolveParametersExec() {
+ @Test public void testResolveParametersExec() throws Exception {
List bindings = new ArrayList();
bindings.add("pm1.g2.e1"); //$NON-NLS-1$
- Query resolvedQuery = (Query)helpResolve("SELECT * FROM (exec pm1.sq2(?)) as
a", bindings); //$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);
@@ -967,65 +956,6 @@
assertEquals("Did not get expected type",
DataTypeManager.DefaultDataClasses.INTEGER, elem2.getType()); //$NON-NLS-1$
}
- @Test public void testStoredQueryTransformationWithVariable() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("SELECT * FROM
pm1.g1 WHERE pm1.sq5.in1 = 5"); //$NON-NLS-1$
-
- // Construct command metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.in1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.STRING);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- // Verify results
- helpCheckFrom((Query)command, new String[] { "pm1.g1" });
//$NON-NLS-1$
- Collection vars = getVariables(command);
- assertEquals("Did not find variable in resolved query", 1,
vars.size()); //$NON-NLS-1$
- }
-
- @Test public void testStoredQueryTransformationWithVariable2() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("SELECT * FROM
pm1.g1 WHERE in1 = 5"); //$NON-NLS-1$
-
- // Construct command metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.in1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.STRING);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- // Verify results
- helpCheckFrom((Query)command, new String[] { "pm1.g1" });
//$NON-NLS-1$
- Collection vars = getVariables(command);
- assertEquals("Did not find variable in resolved query", 1,
vars.size()); //$NON-NLS-1$
- }
-
- @Test public void testStoredQueryTransformationWithVariable3() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("SELECT * FROM
pm1.g1 WHERE in1 = 5 UNION SELECT * FROM pm1.g1"); //$NON-NLS-1$
-
- // Construct command metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.in1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.STRING);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- // Verify results
- Collection vars = getVariables(command);
- assertEquals("Did not find variable in resolved query", 1,
vars.size()); //$NON-NLS-1$
- }
-
@Test public void testStoredQueryTransformationWithVariable4() throws Exception {
Command command = QueryParser.getQueryParser().parseCommand("EXEC
pm1.sq2(pm1.sq2.in)"); //$NON-NLS-1$
@@ -2231,27 +2161,6 @@
assertFalse(groups.contains(inputSet));
}
- @Test public void testDefect15872() throws Exception {
- String sql = "CREATE VIRTUAL PROCEDURE " //$NON-NLS-1$
- + "BEGIN " //$NON-NLS-1$
- +"SELECT * FROM pm1.g1 where model.table.param=e1; " //$NON-NLS-1$
- +"end "; //$NON-NLS-1$
- Command command = helpParse(sql);
- Map externalMetadata = new HashMap();
- GroupSymbol procGroup = new GroupSymbol("model.table"); //$NON-NLS-1$
- List procPrarms = new ArrayList();
- ElementSymbol param = new ElementSymbol("model.table.param");
//$NON-NLS-1$
- param.setType(String.class);
- procPrarms.add(param);
- externalMetadata.put(procGroup, procPrarms);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
- CreateUpdateProcedureCommand proc = (CreateUpdateProcedureCommand)command;
- Query query = (Query)proc.getSubCommands().get(0);
- ElementSymbol inElement =
(ElementSymbol)((CompareCriteria)query.getCriteria()).getLeftExpression();
- assertNotNull("Input parameter does not have group",
inElement.getGroupSymbol()); //$NON-NLS-1$
- }
-
@Test public void testInputToInputsConversion() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
@@ -2498,26 +2407,6 @@
helpResolve(sql);
}
-
- @Test public void testDefect23342() throws Exception {
- String sql = "CREATE VIRTUAL PROCEDURE " //$NON-NLS-1$
- + "BEGIN " //$NON-NLS-1$
- + "IF (param = '1')" //$NON-NLS-1$
- + " BEGIN " //$NON-NLS-1$
- +"SELECT * FROM pm1.g1 where model.table.param=e1; " //$NON-NLS-1$
- +" END " //$NON-NLS-1$
- +"end "; //$NON-NLS-1$
- Command command = helpParse(sql);
- Map externalMetadata = new HashMap();
- GroupSymbol proc = new GroupSymbol("model.table"); //$NON-NLS-1$
- List procPrarms = new ArrayList();
- ElementSymbol param = new ElementSymbol("model.table.param");
//$NON-NLS-1$
- param.setType(DataTypeManager.DefaultDataClasses.STRING);
- procPrarms.add(param);
- externalMetadata.put(proc, procPrarms);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
- }
@Test public void testBatchedUpdateResolver() throws Exception {
String update1 = "update pm1.g1 set e1 =1"; //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-02-28
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -22,15 +22,10 @@
package org.teiid.query.resolver;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import junit.framework.TestCase;
-import org.teiid.core.types.DataTypeManager;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.parser.QueryParser;
-import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
@@ -43,9 +38,7 @@
import org.teiid.query.sql.util.ElementSymbolOptimizer;
import org.teiid.query.unittest.FakeMetadataFactory;
-import junit.framework.TestCase;
-
public class TestXMLResolver extends TestCase {
public Command helpResolve(String sql) {
@@ -387,26 +380,6 @@
helpResolveException("SELECT * FROM vm1.doc1, vm1.doc2");
//$NON-NLS-1$
}
- public void testXMLQueryWithParam1() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("select * from
xmltest.doc4 where xmltest.doc4.root.node3 = pm1.sq5.in1"); //$NON-NLS-1$
-
- // resolve
- // Construct command metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.in1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.STRING);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
-
- // Verify results
- Collection vars = TestResolver.getVariables(command);
- assertEquals("Did not find variable in resolved query", 1,
vars.size()); //$NON-NLS-1$
- }
-
public void testXMLWithOrderBy1() {
helpResolveException("select * from xmltest.doc4 order by node1");
//$NON-NLS-1$
}
Modified:
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2011-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -27,20 +27,23 @@
import java.util.HashMap;
import java.util.HashSet;
+import junit.framework.TestCase;
+
import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.resolver.TestResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Option;
import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.RealMetadataFactory;
-import junit.framework.TestCase;
-
/**
*
* @author gchadalavadaDec 9, 2002
*/
+@SuppressWarnings("nls")
public class TestCreateUpdateProcedureCommand extends TestCase {
// ################################## FRAMEWORK ################################
@@ -194,4 +197,13 @@
UnitTestUtil.helpTestEquivalence(0, s1, s2);
}
+ public void testProjectedSymbols() {
+ CreateUpdateProcedureCommand cupc = new CreateUpdateProcedureCommand();
+ cupc.setUpdateProcedure(false);
+ StoredProcedure sp = (StoredProcedure)TestResolver.helpResolve("call
TEIIDSP9(p1=>1, p2=>?)", RealMetadataFactory.exampleBQTCached(), null);
+ sp.setCallableStatement(true);
+ cupc.setResultsCommand(sp);
+ assertEquals(1, cupc.getProjectedSymbols().size());
+ }
+
}
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-02-28
15:56:45 UTC (rev 2950)
+++
trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -22,25 +22,20 @@
package org.teiid.query.sql.util;
-import java.util.*;
+import junit.framework.TestCase;
+
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.types.DataTypeManager;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.util.ElementSymbolOptimizer;
import org.teiid.query.unittest.FakeMetadataFactory;
-import junit.framework.*;
-
/**
*/
public class TestElementSymbolOptimizer extends TestCase {
@@ -53,22 +48,15 @@
super(name);
}
- public Command helpResolve(String sql, QueryMetadataInterface metadata, Map
externalMetadata) throws QueryParserException, QueryResolverException,
TeiidComponentException {
+ public Command helpResolve(String sql, QueryMetadataInterface metadata) throws
QueryParserException, QueryResolverException, TeiidComponentException {
Command command = QueryParser.getQueryParser().parseCommand(sql);
- QueryResolver.buildExternalGroups(externalMetadata, command);
QueryResolver.resolveCommand(command, metadata);
return command;
}
-
public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String
expected) throws QueryMetadataException, TeiidComponentException, QueryParserException,
QueryResolverException {
- this.helpTestOptimize(sql, metadata, expected, Collections.EMPTY_MAP);
- }
-
-
- public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String
expected, Map externalMetadata) throws QueryMetadataException, TeiidComponentException,
QueryParserException, QueryResolverException {
- Command command = helpResolve(sql, metadata, externalMetadata);
+ Command command = helpResolve(sql, metadata);
ElementSymbolOptimizer.optimizeElements(command, metadata);
String actual = command.toString();
@@ -127,7 +115,7 @@
}
public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String
expected) throws QueryParserException, QueryResolverException, TeiidComponentException {
- Command command = helpResolve(sql, metadata, Collections.EMPTY_MAP);
+ Command command = helpResolve(sql, metadata);
ElementSymbolOptimizer.fullyQualifyElements(command);
String actual = command.toString();
@@ -163,30 +151,6 @@
FakeMetadataFactory.example1Cached(),
"SELECT e1 FROM (EXEC pm1.sq1()) AS x WHERE e2 =
3"); //$NON-NLS-1$
}
-
- public void testStoredQuerySubquery3() throws Exception {
-
- // Set up external metadata - stored query pm1.sq3 with
- // params in and in2
- Map externalMetadata = new HashMap();
- GroupSymbol gs = new GroupSymbol("SYSTEM.DESCRIBE"); //$NON-NLS-1$
- List<ElementSymbol> elements = new ArrayList<ElementSymbol>(2);
- elements.add(new ElementSymbol("SYSTEM.DESCRIBE.entity"));
//$NON-NLS-1$
- elements.get(0).setType(DataTypeManager.DefaultDataClasses.STRING);
- externalMetadata.put(gs, elements);
-
-
- helpTestOptimize("select nvl(entities.entityType, '') as Description
" + //$NON-NLS-1$
- "from (SELECT 'Model' AS entityType, pm1.g1.e1 AS
entityName FROM pm1.g1 " + //$NON-NLS-1$
- "UNION ALL SELECT 'Group', pm1.g2.e1 FROM pm1.g2)
as entities " + //$NON-NLS-1$
- "WHERE ucase(entities.entityName) =
ucase(SYSTEM.DESCRIBE.entity)", //$NON-NLS-1$
- FakeMetadataFactory.example1Cached(),
- "SELECT nvl(entityType, '') AS Description
" + //$NON-NLS-1$
- "FROM (SELECT 'Model' AS entityType, e1 AS
entityName FROM pm1.g1 " + //$NON-NLS-1$
- "UNION ALL SELECT 'Group', e1 FROM pm1.g2) AS
entities " + //$NON-NLS-1$
- "WHERE ucase(entityName) = ucase(entity)",
//$NON-NLS-1$
- externalMetadata);
- }
public void testOptimizeOrderBy() throws Exception {
helpTestOptimize("SELECT pm1.g1.e1 FROM pm1.g1 order by pm1.g1.e1",
//$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-02-28
15:56:45 UTC (rev 2950)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-02-28
20:23:19 UTC (rev 2951)
@@ -27,12 +27,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.junit.Ignore;
@@ -51,14 +48,11 @@
import org.teiid.query.mapping.xml.MappingDocument;
import org.teiid.query.mapping.xml.MappingElement;
import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.metadata.StoredProcedureInfo;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.unittest.FakeMetadataFacade;
@@ -70,39 +64,6 @@
@SuppressWarnings("nls")
public class TestValidator {
- public static Map getStoredProcedureExternalMetadata(GroupSymbol virtualProc,
QueryMetadataInterface metadata)
- throws QueryMetadataException, TeiidComponentException {
-
- Map externalMetadata = new HashMap();
-
- StoredProcedureInfo info =
metadata.getStoredProcedureInfoForProcedure(virtualProc.getName());
- if(info!=null) {
- virtualProc.setMetadataID(info.getProcedureID());
-
- // List of ElementSymbols - Map Values
- List paramList = info.getParameters();
- Iterator iter = paramList.iterator();
- // Create Symbol List from parameter list
- List symbolList = new ArrayList();
- while(iter.hasNext()) {
- SPParameter param = (SPParameter) iter.next();
- if(param.getParameterType() == ParameterInfo.IN ||
- param.getParameterType() == ParameterInfo.INOUT) {
- // Create Element Symbol
- ElementSymbol eSymbol = new ElementSymbol(param.getName());
- eSymbol.setMetadataID(param);
- eSymbol.setType(param.getClassType());
- symbolList.add(eSymbol);
- }
- }
- // Create external Metadata Map
- externalMetadata = new HashMap();
- externalMetadata.put(virtualProc, symbolList);
- }
-
- return externalMetadata;
- }
-
public static FakeMetadataFacade exampleMetadata() {
// Create metadata objects
FakeMetadataObject modelObj =
FakeMetadataFactory.createPhysicalModel("test"); //$NON-NLS-1$
@@ -320,23 +281,31 @@
// ################################## TEST HELPERS ################################
static Command helpResolve(String sql, QueryMetadataInterface metadata) {
- return helpResolve(sql, metadata, Collections.EMPTY_MAP);
- }
-
- public static Command helpResolve(String sql, QueryMetadataInterface metadata, Map
externalMetadata) {
- Command command = null;
+ Command command = null;
try {
command = QueryParser.getQueryParser().parseCommand(sql);
- QueryResolver.buildExternalGroups(externalMetadata, command);
QueryResolver.resolveCommand(command, metadata);
} catch(Exception e) {
throw new TeiidRuntimeException(e);
}
return command;
- }
+ }
+
+ static Command helpResolve(String sql, GroupSymbol container, int type,
QueryMetadataInterface metadata) {
+ Command command = null;
+
+ try {
+ command = QueryParser.getQueryParser().parseCommand(sql);
+ QueryResolver.resolveCommand(command, container, type, metadata);
+ } catch(Exception e) {
+ throw new TeiidRuntimeException(e);
+ }
+ return command;
+ }
+
static ValidatorReport helpValidate(String sql, String[] expectedStringArray,
QueryMetadataInterface metadata) {
Command command = helpResolve(sql, metadata);
@@ -600,44 +569,6 @@
helpValidate("INSERT INTO test.group (e0) VALUES (null)", new String[]
{"e0"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
- @Test public void testInsert2() throws Exception {
- QueryMetadataInterface metadata = exampleMetadata();
-
- Command command = QueryParser.getQueryParser().parseCommand("INSERT INTO
test.group (e0) VALUES (p1)"); //$NON-NLS-1$
-
- // Create external metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.p1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- helpRunValidator(command, new String[] {}, metadata);
- }
-
- @Test public void testInsert3() throws Exception {
- QueryMetadataInterface metadata = exampleMetadata();
-
- Command command = QueryParser.getQueryParser().parseCommand("INSERT INTO
test.group (e0) VALUES (p1+2)"); //$NON-NLS-1$
-
- // Create external metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.p1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- helpRunValidator(command, new String[] {}, metadata);
- }
-
// non-null, no-default elements not left
@Test public void testInsert4() throws Exception {
QueryMetadataInterface metadata = exampleMetadata1();
@@ -690,43 +621,6 @@
helpValidate("UPDATE test.group SET e0=1, e0=2", new String[]
{"e0"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
- @Test public void testUpdate4() throws Exception {
- QueryMetadataInterface metadata = exampleMetadata();
-
- Command command = QueryParser.getQueryParser().parseCommand("UPDATE
test.group SET e0=p1"); //$NON-NLS-1$
-
- // Create external metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.p1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
-
- helpRunValidator(command, new String[] {}, metadata);
- }
-
- @Test public void testUpdate5() throws Exception {
- QueryMetadataInterface metadata = exampleMetadata();
-
- Command command = QueryParser.getQueryParser().parseCommand("UPDATE
test.group SET e0=p1+2"); //$NON-NLS-1$
-
- // Create external metadata
- GroupSymbol sqGroup = new GroupSymbol("pm1.sq5"); //$NON-NLS-1$
- ArrayList sqParams = new ArrayList();
- ElementSymbol in = new ElementSymbol("pm1.sq5.p1"); //$NON-NLS-1$
- in.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- sqParams.add(in);
- Map externalMetadata = new HashMap();
- externalMetadata.put(sqGroup, sqParams);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
- helpRunValidator(command, new String[] {}, metadata);
- }
-
@Test public void testValidateUpdateElements1() throws Exception {
QueryMetadataInterface metadata = exampleMetadata();
@@ -1605,9 +1499,7 @@
Command command = new QueryParser().parseCommand(procSql);
GroupSymbol group = new GroupSymbol(procName);
- Map externalMetadata = getStoredProcedureExternalMetadata(group, metadata);
- QueryResolver.buildExternalGroups(externalMetadata, command);
- QueryResolver.resolveCommand(command, metadata);
+ QueryResolver.resolveCommand(command, group, Command.TYPE_STORED_PROCEDURE,
metadata);
// Validate
return Validator.validate(command, metadata);
@@ -1718,10 +1610,9 @@
@Test public void testCase4237() {
FakeMetadataFacade metadata = helpCreateCase4237VirtualProcedureMetadata();
- Map externalMetadata = helpCreateCase4237ExternalMetadata(metadata);
String sql = "CREATE VIRTUAL PROCEDURE BEGIN EXEC pm1.sp(vm1.sp.in1);
END"; //$NON-NLS-1$
- Command command = helpResolve(sql, metadata, externalMetadata);
+ Command command = helpResolve(sql, new GroupSymbol("vm1.sp"),
Command.TYPE_STORED_PROCEDURE, metadata);
helpRunValidator(command, new String[0], metadata);
}
@@ -1732,41 +1623,13 @@
@Test public void testCase4237InlineView() {
FakeMetadataFacade metadata = helpCreateCase4237VirtualProcedureMetadata();
- Map externalMetadata = helpCreateCase4237ExternalMetadata(metadata);
String sql = "CREATE VIRTUAL PROCEDURE BEGIN SELECT * FROM (EXEC
pm1.sp(vm1.sp.in1)) AS FOO; END"; //$NON-NLS-1$
- Command command = helpResolve(sql, metadata, externalMetadata);
+ Command command = helpResolve(sql, new GroupSymbol("vm1.sp"),
Command.TYPE_STORED_PROCEDURE, metadata);
helpRunValidator(command, new String[0], metadata);
}
/**
- * Set up external metadata describing the virtual procedure and parameters
- * @param metadata FakeMetadataFacade
- * @return external metadata Map
- */
- private Map helpCreateCase4237ExternalMetadata(FakeMetadataFacade metadata) {
- GroupSymbol sp = new GroupSymbol("vm1.sp");//$NON-NLS-1$
- FakeMetadataObject spObj = metadata.getStore().findObject("vm1.sp",
FakeMetadataObject.PROCEDURE);//$NON-NLS-1$
- sp.setMetadataID(spObj);
- ElementSymbol param = new ElementSymbol("vm1.sp.in1");//$NON-NLS-1$
- List paramIDs = (List)spObj.getProperty(FakeMetadataObject.Props.PARAMS);
- Iterator i = paramIDs.iterator();
- while (i.hasNext()) {
- FakeMetadataObject paramID = (FakeMetadataObject)i.next();
- if (paramID.getProperty(FakeMetadataObject.Props.DIRECTION).equals(new
Integer(ParameterInfo.IN))) {
- param.setMetadataID(paramID);
-
param.setType(DataTypeManager.getDataTypeClass((String)paramID.getProperty(FakeMetadataObject.Props.TYPE)));
- break;
- }
- }
-
- Map externalMetadata = new HashMap();
- externalMetadata.put(sp, Arrays.asList(new ElementSymbol[] { param }));
-
- return externalMetadata;
- }
-
- /**
* Create fake metadata for this case. Need a physical stored procedure and
* a virtual stored procedure which calls the physical one.
* @return