Author: shawkins
Date: 2009-04-22 16:03:21 -0400 (Wed, 22 Apr 2009)
New Revision: 828
Added:
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestResultsMetadataWithProvider.java
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestStaticMetadataProvider.java
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestExpressionMappingVisitor.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
Log:
TEIID-526, TEIID-527 ensuring that the user command is unmodified and eliminating the
duplicate node conversion logic
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -49,17 +49,17 @@
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.GroupBy;
+import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.QueryCommand;
+import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.navigator.PostOrderNavigator;
-import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
@@ -206,96 +206,58 @@
}
} else if(type == NodeConstants.Types.PROJECT) {
- List<SingleElementSymbol> elements = (List<SingleElementSymbol>)
node.getProperty(NodeConstants.Info.PROJECT_COLS);
-
- for (int i = 0; i < elements.size(); i++) {
- SingleElementSymbol symbol = elements.get(i);
- SingleElementSymbol mappedSymbol = convertSingleElementSymbol(symbol,
symbolMap, true);
- elements.set(i, mappedSymbol);
-
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(mappedSymbol, groups);
- }
+ List<SingleElementSymbol> projectedSymbols =
(List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.PROJECT_COLS);
+ Select select = new Select(projectedSymbols);
+ ExpressionMappingVisitor.mapExpressions(select, symbolMap);
+ node.setProperty(NodeConstants.Info.PROJECT_COLS, select.getSymbols());
+ if (newGroup == null) {
+ GroupsUsedByElementsVisitor.getGroups(select, groups);
}
-
} else if(type == NodeConstants.Types.JOIN) {
// Convert join criteria property
List<Criteria> joinCrits = (List<Criteria>)
node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
- if(joinCrits != null) {
- for (int i = 0; i < joinCrits.size(); i++) {
- Criteria crit = joinCrits.get(i);
- crit = convertCriteria(crit, symbolMap);
-
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(crit, groups);
- }
- joinCrits.set(i, crit);
- }
+ if(joinCrits != null && !joinCrits.isEmpty()) {
+ Criteria crit = new CompoundCriteria(joinCrits);
+ crit = convertCriteria(crit, symbolMap);
+ if (crit instanceof CompoundCriteria) {
+ node.setProperty(NodeConstants.Info.JOIN_CRITERIA,
((CompoundCriteria)crit).getCriteria());
+ } else {
+ joinCrits = new ArrayList<Criteria>();
+ joinCrits.add(crit);
+ node.setProperty(NodeConstants.Info.JOIN_CRITERIA, joinCrits);
+ }
+ if (newGroup == null) {
+ GroupsUsedByElementsVisitor.getGroups(crit, groups);
+ }
}
convertAccessPatterns(symbolMap, node);
} else if(type == NodeConstants.Types.SORT) {
- List<SingleElementSymbol> elements = (List<SingleElementSymbol>)
node.getProperty(NodeConstants.Info.SORT_ORDER);
-
- for (int i = 0; i < elements.size(); i++) {
- SingleElementSymbol symbol = elements.get(i);
- SingleElementSymbol mappedSymbol = convertSingleElementSymbol(symbol,
symbolMap, true);
- elements.set(i, mappedSymbol);
-
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(mappedSymbol, groups);
- }
+ List<SingleElementSymbol> sortCols =
(List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.SORT_ORDER);
+ OrderBy orderBy = new OrderBy(sortCols);
+ ExpressionMappingVisitor.mapExpressions(orderBy, symbolMap);
+ node.setProperty(NodeConstants.Info.SORT_ORDER, orderBy.getVariables());
+ if (newGroup == null) {
+ GroupsUsedByElementsVisitor.getGroups(orderBy, groups);
}
-
} else if(type == NodeConstants.Types.GROUP) {
- // Grouping columns
- List groupCols = (List) node.getProperty(NodeConstants.Info.GROUP_COLS);
- if(groupCols != null) {
- List newGroupCols = new ArrayList(groupCols.size());
- Iterator groupIter = groupCols.iterator();
- while(groupIter.hasNext()) {
- SingleElementSymbol groupCol = (SingleElementSymbol)
groupIter.next();
- Expression mappedCol = convertSingleElementSymbol(groupCol,
symbolMap, false);
- newGroupCols.add( mappedCol );
-
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(mappedCol, groups);
- }
- }
- node.setProperty(NodeConstants.Info.GROUP_COLS, newGroupCols);
+ List<SingleElementSymbol> groupCols =
(List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.GROUP_COLS);
+ if (groupCols != null) {
+ GroupBy groupBy= new GroupBy(groupCols);
+ ExpressionMappingVisitor.mapExpressions(groupBy, symbolMap);
+ node.setProperty(NodeConstants.Info.GROUP_COLS, groupBy.getSymbols());
+ if (newGroup == null) {
+ GroupsUsedByElementsVisitor.getGroups(groupCols, groups);
+ }
}
} else if (type == NodeConstants.Types.SOURCE || type ==
NodeConstants.Types.ACCESS) {
convertAccessPatterns(symbolMap, node);
}
}
- static SingleElementSymbol convertSingleElementSymbol(SingleElementSymbol symbol, Map
symbolMap, boolean shouldAlias) {
-
- // Preserve old "short name" of alias by aliasing
- String name = symbol.getShortName();
+ private static Expression convertExpression(Expression expression, Map symbolMap) {
- Expression mappedExpression = convertExpression(SymbolMap.getExpression(symbol),
symbolMap);
-
- // Convert symbol using symbol map
- SingleElementSymbol mappedSymbol = null;
-
- if(!(mappedExpression instanceof SingleElementSymbol)) {
- mappedSymbol = new ExpressionSymbol(name, mappedExpression);
- } else {
- mappedSymbol = (SingleElementSymbol)mappedExpression;
- }
-
- // Re-alias to maintain name if necessary
- if(shouldAlias && (mappedSymbol instanceof ExpressionSymbol ||
!mappedSymbol.getShortCanonicalName().equals(name.toUpperCase()))) {
- mappedSymbol = new AliasSymbol(name, mappedSymbol);
- }
-
- return mappedSymbol;
- }
-
- static Expression convertExpression(Expression expression, Map symbolMap) {
-
if (expression == null || expression instanceof Constant) {
return expression;
}
@@ -318,20 +280,16 @@
}
}
- ExpressionMappingVisitor emv = new ExpressionMappingVisitor(symbolMap);
+ ExpressionMappingVisitor.mapExpressions(expression, symbolMap);
- PreOrderNavigator.doVisit(expression, emv);
-
return expression;
}
static Criteria convertCriteria(Criteria criteria, final Map symbolMap)
throws QueryPlannerException {
- ExpressionMappingVisitor emv = new ExpressionMappingVisitor(symbolMap);
+ ExpressionMappingVisitor.mapExpressions(criteria, symbolMap);
- PostOrderNavigator.doVisit(criteria, emv);
-
// Simplify criteria if possible
try {
return QueryRewriter.rewriteCriteria(criteria, null, null, null);
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -49,15 +49,10 @@
import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
import com.metamatrix.query.resolver.util.ResolverVisitor;
-import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.GroupBy;
import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -68,7 +63,6 @@
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -141,6 +135,7 @@
/**
* Attempt to push the group node below one or more joins, manipulating the parent
plan as necessary. This may involve
* modifying symbols in parent nodes (to account for staged aggregates).
+ * @throws QueryPlannerException
*
* @since 4.2
*/
@@ -149,7 +144,7 @@
Set<AggregateSymbol> allAggregates,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder) throws
MetaMatrixComponentException,
- QueryMetadataException {
+ QueryMetadataException,
QueryPlannerException {
Map<PlanNode, List<SingleElementSymbol>> aggregateMap =
createNodeMapping(groupNode, allAggregates);
Map<PlanNode, List<SingleElementSymbol>> groupingMap =
createNodeMapping(groupNode, groupingExpressions);
@@ -220,7 +215,7 @@
private void stageAggregates(PlanNode groupNode,
QueryMetadataInterface metadata,
Set<SingleElementSymbol> stagedGroupingSymbols,
- List<SingleElementSymbol> aggregates) throws
MetaMatrixComponentException {
+ List<SingleElementSymbol> aggregates) throws
MetaMatrixComponentException, QueryPlannerException {
//remove any aggregates that are computed over a group by column
Set<Expression> expressions = new HashSet<Expression>();
for (SingleElementSymbol expression : stagedGroupingSymbols) {
@@ -414,74 +409,19 @@
return aggMap;
}
- static void mapExpressions(PlanNode node, Map<? extends Expression, ? extends
Expression> exprMap) {
- PlanNode current = node;
+ static void mapExpressions(PlanNode node, Map<? extends Expression, ? extends
Expression> exprMap)
+ throws QueryPlannerException {
- while (current != null) {
+ while (node != null) {
+ FrameUtil.convertNode(node, null, null, exprMap);
- // Convert expressions from correlated subquery references;
- // currently only for SELECT or PROJECT nodes
- SymbolMap refs =
(SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (refs != null){
- for (Map.Entry<ElementSymbol, Expression> ref :
refs.asUpdatableMap().entrySet()) {
- Expression expr = ref.getValue();
- Expression mappedExpr = exprMap.get(expr);
- if (mappedExpr != null) {
- ref.setValue(mappedExpr);
- } else {
- ExpressionMappingVisitor.mapExpressions(ref.getValue(),
exprMap);
- }
- }
- }
-
- switch (current.getType()) {
- case NodeConstants.Types.SELECT: {
- Criteria crit =
(Criteria)current.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- ExpressionMappingVisitor.mapExpressions(crit, exprMap);
- break;
- }
- case NodeConstants.Types.PROJECT: {
- List<SingleElementSymbol> projectedSymbols =
(List<SingleElementSymbol>)current.getProperty(NodeConstants.Info.PROJECT_COLS);
- Select select = new Select(projectedSymbols);
- ExpressionMappingVisitor.mapExpressions(select, exprMap);
- current.setProperty(NodeConstants.Info.PROJECT_COLS,
select.getSymbols());
- break;
- }
- case NodeConstants.Types.SOURCE: {
- PlanNode projectNode = NodeEditor.findNodePreOrder(current,
NodeConstants.Types.PROJECT);
- List<SingleElementSymbol> projectedSymbols =
(List<SingleElementSymbol>)projectNode.getProperty(NodeConstants.Info.PROJECT_COLS);
- SymbolMap symbolMap =
SymbolMap.createSymbolMap(current.getGroups().iterator().next(), projectedSymbols);
- current.setProperty(NodeConstants.Info.SYMBOL_MAP, symbolMap);
+ switch (node.getType()) {
+ case NodeConstants.Types.SOURCE:
+ case NodeConstants.Types.GROUP:
return;
- }
- case NodeConstants.Types.SORT: {
- List<SingleElementSymbol> sortCols =
(List<SingleElementSymbol>)current.getProperty(NodeConstants.Info.SORT_ORDER);
- OrderBy orderBy = new OrderBy(sortCols);
- ExpressionMappingVisitor.mapExpressions(orderBy, exprMap);
- current.setProperty(NodeConstants.Info.PROJECT_COLS,
orderBy.getVariables());
- break;
- }
- case NodeConstants.Types.JOIN: {
- List joinCriteria =
(List)current.getProperty(NodeConstants.Info.JOIN_CRITERIA);
- if (joinCriteria != null) {
- CompoundCriteria crit = new CompoundCriteria(joinCriteria);
- ExpressionMappingVisitor.mapExpressions(crit, exprMap);
- current.setProperty(NodeConstants.Info.JOIN_CRITERIA,
crit.getCriteria());
- }
- break;
- }
- case NodeConstants.Types.GROUP: {
- List<SingleElementSymbol> groupCols =
(List<SingleElementSymbol>)current.getProperty(NodeConstants.Info.GROUP_COLS);
- if (groupCols != null) {
- GroupBy groupBy= new GroupBy(groupCols);
- ExpressionMappingVisitor.mapExpressions(groupBy, exprMap);
- current.setProperty(NodeConstants.Info.GROUP_COLS,
groupBy.getSymbols());
- }
- return;
- }
}
- current = current.getParent();
+ node = node.getParent();
}
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -53,11 +53,9 @@
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.util.ErrorMessageKeys;
/**
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -104,7 +104,7 @@
replacmentSymbol = new ExpressionSymbol(ses.getName(), replacement);
}
- if (alias && createAliases() &&
!replacmentSymbol.getShortName().equals(ses.getShortName())) {
+ if (alias && createAliases() &&
!replacmentSymbol.getShortCanonicalName().equals(ses.getShortCanonicalName())) {
replacmentSymbol = new AliasSymbol(ses.getShortName(),
replacmentSymbol);
}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -73,7 +73,6 @@
*/
public class MetaDataProcessor {
-
// Resources
private MetadataService metadataService;
private DQPCore requestManager;
@@ -118,10 +117,18 @@
if(multiModels != null && multiModels.size() > 0) {
this.metadata = new MultiSourceMetadataWrapper(this.metadata, multiModels);
}
+
+ RequestWorkItem workItem = null;
+ try {
+ workItem = requestManager.getRequestWorkItem(requestID);
+ } catch (MetaMatrixProcessingException e) {
+ if (preparedSql == null) {
+ throw e;
+ }
+ }
TempTableStore tempTableStore = null;
if(tempTableStoresHolder != null) {
- RequestWorkItem workItem = requestManager.safeGetWorkItem(requestID);
if (workItem != null) {
tempTableStore =
tempTableStoresHolder.getTempTableStore(workContext.getConnectionID());
}
@@ -130,9 +137,8 @@
metadata = new TempMetadataAdapter(this.metadata,
tempTableStore.getMetadataStore());
}
- if(preparedSql == null) {
- RequestWorkItem workItem = requestManager.getRequestWorkItem(requestID);
- return getMetadataForCommand(workItem.getOriginalCommand());
+ if(workItem != null) {
+ return getMetadataForCommand(workItem.getOriginalCommand());
}
return obtainMetadataForPreparedSql(preparedSql, workContext,
allowDoubleQuotedVariable);
}
@@ -147,9 +153,7 @@
if (((Query)originalCommand).getIsXML()) {
columnMetadata = new Map[1];
columnMetadata[0] =
createXMLColumnMetadata((Query)originalCommand);
- } else if (((Query)originalCommand).getInto() != null) {
- columnMetadata = null;
- } else {
+ } else if (((Query)originalCommand).getInto() == null) {
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
} else {
@@ -164,7 +168,6 @@
case Command.TYPE_DELETE:
case Command.TYPE_CREATE:
case Command.TYPE_DROP:
- columnMetadata = null;
break;
case Command.TYPE_XQUERY:
columnMetadata = new Map[1];
@@ -216,8 +219,7 @@
if(plan != null) {
command = plan.getCommand();
} else {
- QueryParser parser = QueryParser.getQueryParser();
- command = parser.parseCommand(sql, info);
+ command = QueryParser.getQueryParser().parseCommand(sql, info);
QueryResolver.resolveCommand(command, Collections.EMPTY_MAP, false,
this.metadata, AnalysisRecord.createNonRecordingRecord());
}
return getMetadataForCommand(command);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -84,9 +84,6 @@
handleCallableStatement(command);
super.resolveCommand(command);
-
- //save the command in it's present form so that it can be validated later
- prepPlan.setCommand((Command) command.clone());
}
/**
@@ -150,26 +147,24 @@
}
ProcessorPlan cachedPlan = prepPlan.getPlan();
- Command command = prepPlan.getCommand();
if (cachedPlan == null) {
prepPlan.setRewritenCommand(super.generatePlan());
-
if (!this.addedLimit) { //TODO: this is a little problematic
+ prepPlan.setCommand(this.userCommand);
// Defect 13751: Clone the plan in its current state (i.e. before processing)
so that it can be used for later queries
prepPlan.setPlan((ProcessorPlan)processPlan.clone());
prepPlan.setAnalysisRecord(analysisRecord);
this.prepPlanCache.putPreparedPlan(id,
this.context.isSessionFunctionEvaluated(), prepPlan);
}
- command = prepPlan.getCommand();
} else {
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Query exist in
cache: ", sqlQuery }); //$NON-NLS-1$
processPlan = (ProcessorPlan)cachedPlan.clone();
//already in cache. obtain the values from cache
analysisRecord = prepPlan.getAnalysisRecord();
- this.userCommand = command;
- createCommandContext(command);
+ this.userCommand = prepPlan.getCommand();
+ createCommandContext();
}
if (requestMsg.isPreparedBatchUpdate()) {
@@ -178,7 +173,7 @@
List<Reference> params = prepPlan.getReferences();
List<?> values = requestMsg.getParameterValues();
- resolveAndValidateParameters(command, params, values);
+ resolveAndValidateParameters(this.userCommand, params, values);
}
return prepPlan.getRewritenCommand();
}
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 2009-04-22
18:58:59 UTC (rev 827)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -235,22 +236,22 @@
}
}
- protected void createCommandContext(Command command) throws QueryValidatorException
{
+ protected void createCommandContext() throws QueryValidatorException {
boolean returnsResultSet = false;
this.returnsUpdateCount = true;
- if(command instanceof Query) {
- Query query = (Query)command;
+ if(userCommand instanceof Query) {
+ Query query = (Query)userCommand;
returnsResultSet = query.getInto() == null;
returnsUpdateCount = !returnsResultSet;
- } else if (command instanceof SetQuery) {
+ } else if (userCommand instanceof SetQuery) {
returnsResultSet = true;
returnsUpdateCount = false;
- } else if (command instanceof XQuery) {
+ } else if (userCommand instanceof XQuery) {
returnsResultSet = true;
returnsUpdateCount = false;
- } else if (command instanceof StoredProcedure) {
+ } else if (userCommand instanceof StoredProcedure) {
returnsUpdateCount = false;
- StoredProcedure proc = (StoredProcedure)command;
+ StoredProcedure proc = (StoredProcedure)userCommand;
returnsResultSet = proc.returnsResultSet();
}
if (this.requestMsg.getRequireResultSet() != null &&
this.requestMsg.getRequireResultSet() != returnsResultSet) {
@@ -276,8 +277,8 @@
workContext.getVdbName(),
workContext.getVdbVersion(),
props,
- useProcDebug(command),
- collectNodeStatistics(command));
+ useProcDebug(userCommand),
+ collectNodeStatistics(userCommand));
this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
this.context.setConnectorBatchSize(bufferManager.getConnectorBatchSize());
this.context.setStreamingBatchSize(chunkSize);
@@ -308,7 +309,14 @@
if (this.tempTableStore != null) {
QueryResolver.setChildMetadata(command,
tempTableStore.getMetadataStore().getData(), null);
}
+ //ensure that the user command is distinct from the processing command
+ //rewrite and planning may alter options, symbols, etc.
+
+ //TODO clone after the resolve - but that doesn't currently work for exec
resolving
+ this.userCommand = (Command)command.clone();
+ QueryResolver.resolveCommand(this.userCommand, Collections.emptyMap(), false,
metadata, analysisRecord);
+
QueryResolver.resolveCommand(command, metadata, analysisRecord);
}
@@ -369,7 +377,7 @@
}
}
- protected void createProcessor() throws MetaMatrixComponentException {
+ protected void createProcessor(Command processingCommand) throws
MetaMatrixComponentException {
TransactionContext tc = null;
@@ -388,7 +396,7 @@
if(ExecutionProperties.AUTO_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())){
startAutoWrapTxn = true;
- } else if ( userCommand.updatingModelCount(metadata) > 1) {
+ } else if ( processingCommand.updatingModelCount(metadata) > 1) {
if
(ExecutionProperties.AUTO_WRAP_OPTIMISTIC.equals(requestMsg.getTxnAutoWrapMode())){
String msg =
DQPPlugin.Util.getString("Request.txn_needed_wrong_mode", requestId);
//$NON-NLS-1$
throw new MetaMatrixComponentException(msg);
@@ -467,14 +475,12 @@
resolveCommand(command);
- createCommandContext(command);
+ createCommandContext();
validateQuery(command, true);
validateQueryValues(command);
- this.userCommand = command;
-
command = QueryRewriter.rewrite(command, null, metadata, context);
/*
@@ -590,13 +596,13 @@
initMetadata();
- generatePlan();
+ Command processingCommand = generatePlan();
validateEntitlement(userCommand);
setSchemasForXMLPlan(userCommand, metadata);
- createProcessor();
+ createProcessor(processingCommand);
}
public QueryProcessor createQueryProcessor(String query, String recursionGroup,
CommandContext commandContext) throws MetaMatrixProcessingException,
MetaMatrixComponentException {
@@ -641,16 +647,7 @@
if (authSvc.checkingEntitlements()) {
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(
this.workContext.getConnectionID(), authSvc);
- if (command.getType() == Command.TYPE_XQUERY) {
- // validate its first level children
- Iterator iter = command.getSubCommands().iterator();
- while (iter.hasNext()) {
- validateWithVisitor(visitor, this.metadata,
- (Command) iter.next(), true);
- }
- } else {
- validateWithVisitor(visitor, this.metadata, command, true);
- }
+ validateWithVisitor(visitor, this.metadata, command, true);
} else if (workContext.getUserName().equals(
AuthorizationService.DEFAULT_WSDL_USERNAME)) {
if (command.getType() == Command.TYPE_STORED_PROCEDURE &&
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -684,7 +684,7 @@
dqpWorkContext.getUserName(),
dqpWorkContext.getVdbName(),
dqpWorkContext.getVdbVersion(),
- (originalCommand != null ? originalCommand.toString() : null ),
+ requestMsg.getCommandString(),
-1);
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -359,7 +359,7 @@
Constant expectedConst = new Constant(new Double(10.0));
assertEquals("Did not get expected constant value for SqrtLeft in root node of
plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() //
should be a AliasSymbol containing an expression
+ ((ExpressionSymbol)elem.get(8)).getExpression() // should be a AliasSymbol
containing an expression
);
}
@@ -427,7 +427,7 @@
Constant expectedConst = new Constant(new Double(10.0));
assertEquals("Did not get expected constant value for SqrtLeft in root node of
plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() //
should be a AliasSymbol containing an expression
+ ((ExpressionSymbol) elem.get(8)).getExpression() // should be a AliasSymbol
containing an expression
);
assertEquals("Did not get expected constant value for SqrtTop in root node of
plan: ", //$NON-NLS-1$
expectedConst,
Modified:
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestExpressionMappingVisitor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestExpressionMappingVisitor.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestExpressionMappingVisitor.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -23,6 +23,7 @@
package com.metamatrix.query.sql.visitor;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.CompareCriteria;
+import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
@@ -163,4 +165,22 @@
helpTest(TestSearchedCaseExpression.example(3), map, mapped);
}
+ /**
+ * We do not need to create an alias if the canonical short names match
+ */
+ public void testSelectAlias() {
+ ElementSymbol x = new ElementSymbol("y.x"); //$NON-NLS-1$
+ ElementSymbol y = new ElementSymbol("z.X"); //$NON-NLS-1$
+
+ HashMap map = new HashMap();
+ map.put(x, y);
+
+ LanguageObject toMap = new Select(Arrays.asList(x));
+
+ ExpressionMappingVisitor.mapExpressions(toMap, map);
+
+ assertEquals("Did not get expected mapped expression", "SELECT
z.X", toMap.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
}
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -152,7 +152,7 @@
// Initialize components
ApplicationEnvironment env = new ApplicationEnvironment();
env.bindService(DQPServiceNames.VDB_SERVICE, vdbService);
- MetaDataProcessor mdProc = new MetaDataProcessor(mdSvc, null, prepPlanCache, env,
null);
+ MetaDataProcessor mdProc = new MetaDataProcessor(mdSvc, new DQPCore(),
prepPlanCache, env, null);
DQPWorkContext workContext = new DQPWorkContext();
workContext.setVdbName("MyVDB"); //$NON-NLS-1$
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-04-22
18:58:59 UTC (rev 827)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -50,6 +50,7 @@
import com.metamatrix.query.processor.FakeDataManager;
import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.TestProcessor;
+import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataFactory;
@@ -218,9 +219,9 @@
workContext.setSessionToken(new SessionToken(new MetaMatrixSessionID(conn),
"foo")); //$NON-NLS-1$
PreparedStatementRequest serverRequest = new
PreparedStatementRequest(prepPlanCache) {
@Override
- protected void createProcessor()
+ protected void createProcessor(Command processingCommand)
throws MetaMatrixComponentException {
- //don't bother
+
}
};
FakeApplicationEnvironment env = new FakeApplicationEnvironment(metadata,
"example1", "1", "pm1", "1", "BINDING");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
Added:
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestResultsMetadataWithProvider.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestResultsMetadataWithProvider.java
(rev 0)
+++
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestResultsMetadataWithProvider.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -0,0 +1,74 @@
+/*
+ * 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 com.metamatrix.jdbc;
+
+import java.util.Map;
+
+import org.teiid.dqp.internal.process.MetaDataProcessor;
+
+import junit.framework.TestCase;
+
+
+/**
+ */
+public class TestResultsMetadataWithProvider extends TestCase {
+
+ /**
+ * Constructor for TestResultsMetadataWithProvider.
+ * @param name
+ */
+ public TestResultsMetadataWithProvider(String name) {
+ super(name);
+ }
+
+ public StaticMetadataProvider exampleProvider() throws Exception {
+ MetaDataProcessor processor = new MetaDataProcessor(null, null, null, null,
null);
+ Map col1 = processor.getDefaultColumn("vdb", "1",
"table", "col1", String.class); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+ Map col2 = processor.getDefaultColumn("vdb", "1",
"table", "col2", Integer.class); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+
+ Map[] columnMetadata = new Map[] {
+ col1, col2
+ };
+
+ StaticMetadataProvider provider =
StaticMetadataProvider.createWithData(columnMetadata, 0);
+ return provider;
+ }
+
+ public void test1() throws Exception {
+ ResultsMetadataWithProvider rmd = new
ResultsMetadataWithProvider(exampleProvider());
+
+ assertEquals(false, rmd.isAutoIncrement(1));
+ assertEquals(false, rmd.isCaseSensitive(1));
+ assertEquals(false, rmd.isCurrency(1));
+ assertEquals(true, rmd.isDefinitelyWritable(1));
+ assertEquals(false, rmd.isReadOnly(1));
+ assertEquals(true, rmd.isSearchable(1));
+ assertEquals(true, rmd.isSigned(1));
+ assertEquals(true, rmd.isWritable(1));
+ assertEquals(null, rmd.getCatalogName(1));
+ assertEquals("vdb", rmd.getSchemaName(1)); //$NON-NLS-1$
+ assertEquals("table", rmd.getTableName(1)); //$NON-NLS-1$
+ assertEquals("col1", rmd.getColumnName(1)); //$NON-NLS-1$
+ assertEquals("string", rmd.getColumnTypeName(1)); //$NON-NLS-1$
+ }
+}
Property changes on:
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestResultsMetadataWithProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestStaticMetadataProvider.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestStaticMetadataProvider.java
(rev 0)
+++
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestStaticMetadataProvider.java 2009-04-22
20:03:21 UTC (rev 828)
@@ -0,0 +1,108 @@
+/*
+ * 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 com.metamatrix.jdbc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.teiid.dqp.internal.process.MetaDataProcessor;
+
+import com.metamatrix.dqp.metadata.ResultsMetadataConstants;
+
+/**
+ */
+public class TestStaticMetadataProvider extends TestCase {
+
+ /**
+ * Constructor for TestStaticMetadataProvider.
+ * @param name
+ */
+ public TestStaticMetadataProvider(String name) {
+ super(name);
+ }
+
+ private StaticMetadataProvider example1() throws Exception {
+ MetaDataProcessor processor = new MetaDataProcessor(null, null, null, null,
null);
+ Map[] columnMetadata = new Map[] {
+ processor.getDefaultColumn("vdb", "1", "table",
"c1", String.class), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ processor.getDefaultColumn("vdb", "1", "table",
"c2", Integer.class) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ };
+
+ return StaticMetadataProvider.createWithData(columnMetadata, 0);
+ }
+
+ public void testMetadata() throws Exception {
+ StaticMetadataProvider provider = example1();
+ assertEquals(2, provider.getColumnCount());
+
+ for(int i=0; i<provider.getColumnCount(); i++) {
+ assertNotNull(provider.getValue(i,
ResultsMetadataConstants.VIRTUAL_DATABASE_NAME));
+ assertNotNull(provider.getValue(i,
ResultsMetadataConstants.VIRTUAL_DATABASE_VERSION));
+ assertNotNull(provider.getValue(i, ResultsMetadataConstants.GROUP_NAME));
+ assertNotNull(provider.getValue(i, ResultsMetadataConstants.ELEMENT_NAME));
+
+ }
+ }
+
+ public void testGetStringValue() throws Exception {
+ Integer property = ResultsMetadataConstants.VIRTUAL_DATABASE_NAME;
+ String value = "vdb"; //$NON-NLS-1$
+
+ Map columnMetadata = new HashMap();
+ columnMetadata.put(property, value);
+
+ StaticMetadataProvider md = StaticMetadataProvider.createWithData(new Map[]
{columnMetadata}, 0);
+
+ String actualValue = md.getStringValue(0, property);
+ assertEquals(value, actualValue);
+ }
+
+ public void testGetIntValue() throws Exception {
+ Integer property = ResultsMetadataConstants.VIRTUAL_DATABASE_NAME;
+ Integer value = new Integer(10); //$NON-NLS-1$
+
+ Map columnMetadata = new HashMap();
+ columnMetadata.put(property, value);
+
+ StaticMetadataProvider md = StaticMetadataProvider.createWithData(new Map[]
{columnMetadata}, 0);
+
+ int actualValue = md.getIntValue(0, property);
+ assertEquals(10, actualValue);
+ }
+
+ public void testGetBooleanValue() throws Exception {
+ Integer property = ResultsMetadataConstants.VIRTUAL_DATABASE_NAME;
+ Boolean value = Boolean.TRUE; //$NON-NLS-1$
+
+ Map columnMetadata = new HashMap();
+ columnMetadata.put(property, value);
+
+ StaticMetadataProvider md = StaticMetadataProvider.createWithData(new Map[]
{columnMetadata}, 0);
+
+ boolean actualValue = md.getBooleanValue(0, property);
+ assertEquals(true, actualValue);
+ }
+
+}
Property changes on:
trunk/test-integration/src/test/java/com/metamatrix/jdbc/TestStaticMetadataProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain