Author: shawkins
Date: 2009-04-27 15:02:50 -0400 (Mon, 27 Apr 2009)
New Revision: 846
Added:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
Removed:
trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
Modified:
trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
Log:
TEIID-535, TEIID-534, TEIID-82 rounding out support for subqueries. They are now
supported in a much broader number of places. Also added a more appropriate check of join
criteria pushdown support.
Modified:
trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java
===================================================================
---
trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/connector-metadata/src/test/java/com/metamatrix/connector/metadata/internal/FakeProcessorDataManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -69,5 +69,10 @@
throws BlockedException, MetaMatrixComponentException {
return null;
}
+
+ @Override
+ public void clearCodeTables() {
+
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -39,24 +39,29 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.types.Sequencable;
import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.core.util.Assertion;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.function.FunctionDescriptor;
import com.metamatrix.query.function.FunctionLibrary;
import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.function.metadata.FunctionMethod;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.AbstractSetCriteria;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
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.DependentSetCriteria;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.IsNullCriteria;
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
+import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
@@ -78,9 +83,10 @@
private final static MatchCriteria.PatternTranslator LIKE_TO_REGEX = new
MatchCriteria.PatternTranslator(".*", ".", REGEX_RESERVED,
'\\'); //$NON-NLS-1$ //$NON-NLS-2$
private Map elements;
- private LookupEvaluator dataMgr;
- private CommandContext context;
+ protected ProcessorDataManager dataMgr;
+ protected CommandContext context;
+
public static boolean evaluate(Criteria criteria) throws CriteriaEvaluationException,
BlockedException, MetaMatrixComponentException {
return new Evaluator(Collections.emptyMap(), null, null).evaluate(criteria,
Collections.emptyList());
}
@@ -89,11 +95,15 @@
return new Evaluator(Collections.emptyMap(), null, null).evaluate(expression,
Collections.emptyList());
}
- public Evaluator(Map elements, LookupEvaluator dataMgr, CommandContext context) {
+ public Evaluator(Map elements, ProcessorDataManager dataMgr, CommandContext context)
{
this.context = context;
this.dataMgr = dataMgr;
this.elements = elements;
}
+
+ public void setContext(CommandContext context) {
+ this.context = context;
+ }
public boolean evaluate(Criteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException,
MetaMatrixComponentException {
@@ -131,34 +141,21 @@
List subCrits = criteria.getCriteria();
Iterator subCritIter = subCrits.iterator();
- if(criteria.getOperator() == CompoundCriteria.AND) {
- Boolean result = Boolean.TRUE;
- while(subCritIter.hasNext()) {
- Criteria subCrit = (Criteria) subCritIter.next();
- Boolean value = evaluateTVL(subCrit, tuple);
- if (value == null) {
- result = null;
- } else if (!value.booleanValue()) {
- return Boolean.FALSE;
- }
- }
- return result;
-
- }
- // CompoundCriteria.OR
- Boolean result = Boolean.FALSE;
+ boolean and = criteria.getOperator() == CompoundCriteria.AND;
+ Boolean result = and?Boolean.TRUE:Boolean.FALSE;
while(subCritIter.hasNext()) {
Criteria subCrit = (Criteria) subCritIter.next();
Boolean value = evaluateTVL(subCrit, tuple);
- if (value == null) {
- result = null;
- continue;
- }
- if (value.booleanValue()) {
- return Boolean.TRUE;
+ if (value == null) {
+ result = null;
+ } else if (!value.booleanValue()) {
+ if (and) {
+ return Boolean.FALSE;
+ }
+ } else if (!and) {
+ return Boolean.TRUE;
}
}
-
return result;
}
@@ -295,7 +292,7 @@
}
}
- public Boolean evaluate(AbstractSetCriteria criteria, List tuple)
+ private Boolean evaluate(AbstractSetCriteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
// Evaluate expression
@@ -315,9 +312,17 @@
ValueIterator valueIter = null;
if (criteria instanceof SetCriteria) {
valueIter = new CollectionValueIterator(((SetCriteria)criteria).getValues());
- } else {
+ } else if (criteria instanceof DependentSetCriteria){
ContextReference ref = (ContextReference)criteria;
valueIter = getContext(criteria).getValueIterator(ref);
+ } else if (criteria instanceof SubquerySetCriteria) {
+ try {
+ valueIter = evaluateSubquery((SubquerySetCriteria)criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
+ } else {
+ Assertion.failed("unknown set criteria type"); //$NON-NLS-1$
}
while(valueIter.hasNext()) {
Object possibleValue = valueIter.next();
@@ -362,7 +367,7 @@
return (value == null ^ criteria.isNegated());
}
- public Boolean evaluate(SubqueryCompareCriteria criteria, List tuple)
+ private Boolean evaluate(SubqueryCompareCriteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException,
MetaMatrixComponentException {
// Evaluate expression
@@ -388,7 +393,12 @@
result = Boolean.TRUE;
}
- ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
while(valueIter.hasNext()) {
Object value = valueIter.next();
@@ -469,9 +479,14 @@
}
public boolean evaluate(ExistsCriteria criteria, List tuple)
- throws BlockedException, MetaMatrixComponentException {
+ throws BlockedException, MetaMatrixComponentException,
CriteriaEvaluationException {
- ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(criteria, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
if(valueIter.hasNext()) {
return true;
}
@@ -617,7 +632,12 @@
throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException
{
Object result = null;
- ValueIterator valueIter =
getContext(scalarSubquery).getValueIterator(scalarSubquery);
+ ValueIterator valueIter;
+ try {
+ valueIter = evaluateSubquery(scalarSubquery, tuple);
+ } catch (MetaMatrixProcessingException e) {
+ throw new ExpressionEvaluationException(e, e.getMessage());
+ }
if(valueIter.hasNext()) {
result = valueIter.next();
if(valueIter.hasNext()) {
@@ -628,12 +648,17 @@
}
return result;
}
+
+ protected ValueIterator evaluateSubquery(SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException, MetaMatrixComponentException {
+ throw new UnsupportedOperationException("Subquery evaluation not possible with a
base Evaluator"); //$NON-NLS-1$
+ }
private CommandContext getContext(LanguageObject expression) throws
MetaMatrixComponentException {
if (context == null) {
throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was
available")); //$NON-NLS-1$
}
return context;
- }
+ }
}
Deleted: trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/LookupEvaluator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.eval;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * @since 5.0
- */
-public interface LookupEvaluator {
-
- /**
- * Lookup a value from a cached code table. If the code table is not loaded, it will
be
- * loaded on the first query. Code tables should be cached based on a combination
of
- * the codeTableName, returnElementName, and keyElementName. If the table is not
loaded,
- * a request will be made and the method should throw a BlockedException.
- *
- * @param context Context for processing
- * @param codeTableName Name of the code table - must be a physical table
- * @param returnElementName Name of the element to be returned in the code table
- * @param keyElementName Name of the key element in the code table
- * @param keyValue Key value to look up
- * @return Return value for the specified key value, or null if not found
- * @throws BlockedException If code table must be loaded
- * @throws MetaMatrixComponentException If an unexpected error occurs
- * @throws MetaMatrixProcessingException
- */
- public abstract Object lookupCodeValue(CommandContext context,
- String codeTableName,
- String returnElementName,
- String keyElementName,
- Object keyValue) throws BlockedException,
- MetaMatrixComponentException,
MetaMatrixProcessingException;
-
-}
\ No newline at end of file
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/proc/ProcedurePlanner.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -46,7 +46,6 @@
import com.metamatrix.query.processor.proc.ExecSqlInstruction;
import com.metamatrix.query.processor.proc.IfInstruction;
import com.metamatrix.query.processor.proc.LoopInstruction;
-import com.metamatrix.query.processor.proc.ProcedureEnvironment;
import com.metamatrix.query.processor.proc.ProcedurePlan;
import com.metamatrix.query.processor.proc.WhileInstruction;
import com.metamatrix.query.processor.program.Program;
@@ -131,9 +130,7 @@
}
// create plan from program and initialized environment
- ProcedureEnvironment env = new ProcedureEnvironment();
- env.getProgramStack().push(programBlock);
- ProcedurePlan plan = new ProcedurePlan(env);
+ ProcedurePlan plan = new ProcedurePlan(programBlock);
// propagate procedure parameters to the plan to allow runtime type checking
ProcedureContainer container =
(ProcedureContainer)((CreateUpdateProcedureCommand) procCommand).getUserCommand();
@@ -144,9 +141,8 @@
plan.setMetadata(metadata);
}
- env.initialize(plan);
-
env.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
-
env.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
+
plan.setUpdateProcedure(((CreateUpdateProcedureCommand)procCommand).isUpdateProcedure());
+
plan.setOutputElements(((CreateUpdateProcedureCommand)procCommand).getProjectedSymbols());
if(debug) {
analysisRecord.println("####################################################");
//$NON-NLS-1$
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -406,6 +406,7 @@
}
// Add groups to crit node
critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(crit));
+
critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(critNode.getCorrelatedReferenceElements()));
return critNode;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -22,7 +22,6 @@
package com.metamatrix.query.optimizer.relational;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -50,8 +49,6 @@
import com.metamatrix.query.processor.relational.DependentAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureAccessNode;
import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
@@ -66,7 +63,6 @@
import com.metamatrix.query.processor.relational.RelationalPlan;
import com.metamatrix.query.processor.relational.SelectNode;
import com.metamatrix.query.processor.relational.SortNode;
-import com.metamatrix.query.processor.relational.SubqueryProcessorUtility;
import com.metamatrix.query.processor.relational.UnionAllNode;
import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
import com.metamatrix.query.resolver.util.ResolverUtil;
@@ -76,9 +72,7 @@
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.ContextReference;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
@@ -191,16 +185,9 @@
} else {
List symbols = (List)
node.getProperty(NodeConstants.Info.PROJECT_COLS);
- SubqueryProcessorUtility spu = createSubqueryProcessor(node);
- if (spu == null) {
- ProjectNode pnode = new ProjectNode(getID());
- processNode = pnode;
- } else {
- DependentProjectNode pnode = new DependentProjectNode(getID(),
spu);
- processNode = pnode;
- }
-
- ((ProjectNode)processNode).setSelectSymbols(symbols);
+ ProjectNode pnode = new ProjectNode(getID());
+ pnode.setSelectSymbols(symbols);
+ processNode = pnode;
}
break;
@@ -323,18 +310,10 @@
case NodeConstants.Types.SELECT:
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- SubqueryProcessorUtility spu = createSubqueryProcessor(node);
- if (spu == null){
- // This is a normal select node
- SelectNode selnode = new SelectNode(getID());
- selnode.setCriteria(crit);
- processNode = selnode;
- } else {
- DependentSelectNode selnode = new DependentSelectNode(getID(), spu);
- selnode.setCriteria(crit);
- processNode = selnode;
- }
+ SelectNode selnode = new SelectNode(getID());
+ selnode.setCriteria(crit);
+ processNode = selnode;
possiblyDependentObject = crit;
break;
@@ -420,21 +399,6 @@
return processNode;
}
- private SubqueryProcessorUtility createSubqueryProcessor(PlanNode node) {
- List<SubqueryContainer> subqueries = node.getSubqueryContainers();
- if (subqueries.isEmpty()){
- return null;
- }
- SymbolMap correlatedReferences =
(SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- List<ProcessorPlan> plans = new
ArrayList<ProcessorPlan>(subqueries.size());
- List<String> contextReferences = new
ArrayList<String>(subqueries.size());
- for (SubqueryContainer subqueryContainer : subqueries) {
- plans.add(subqueryContainer.getCommand().getProcessorPlan());
- contextReferences.add(((ContextReference)subqueryContainer).getContextSymbol());
- }
- return new SubqueryProcessorUtility(plans, contextReferences,
correlatedReferences);
- }
-
private RelationalNode correctProjectionForTempTable(PlanNode node,
AccessNode aNode,
LanguageObject
possiblyDependentObject) throws QueryMetadataException,
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -157,41 +157,42 @@
return result;
}
- /**
- * <p>Find all SELECT or PROJECT type PlanNodes in plan tree,
- * see if the criteria or projected symbols
- * of that node have any SubqueryContainers in it.
- * If so, find the ProcessorPlan from the supplied
- * map of child plans, and create a new Map of ProcessorPlan to the
- * SubqueryContainer object, and place that new Map as a property on the
- * plan node. The Map will be used later during processing.</p>
- * @param plan PlanNode
- */
private static void connectSubqueryContainers(PlanNode plan) {
- Set<GroupSymbol> groupSymbols = new HashSet<GroupSymbol>();
- for (PlanNode source : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE))
{
- groupSymbols.addAll(source.getGroups());
- }
+ Set<GroupSymbol> groupSymbols = getGroupSymbols(plan);
- for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT |
NodeConstants.Types.SELECT)) {
+ for (PlanNode node : NodeEditor.findAllNodes(plan, NodeConstants.Types.PROJECT |
NodeConstants.Types.SELECT | NodeConstants.Types.JOIN)) {
List<SubqueryContainer> subqueryContainers =
node.getSubqueryContainers();
if (subqueryContainers.isEmpty()){
continue;
}
- ArrayList<Reference> correlatedReferences = new
ArrayList<Reference>();
+ Set<GroupSymbol> localGroupSymbols = groupSymbols;
+ if (node.getType() == NodeConstants.Types.JOIN) {
+ localGroupSymbols = getGroupSymbols(node);
+ }
for (SubqueryContainer container : subqueryContainers) {
+ ArrayList<Reference> correlatedReferences = new
ArrayList<Reference>();
Command subCommand = container.getCommand();
- CorrelatedReferenceCollectorVisitor.collectReferences(subCommand,
groupSymbols, correlatedReferences);
+ CorrelatedReferenceCollectorVisitor.collectReferences(subCommand,
localGroupSymbols, correlatedReferences);
+ if (!correlatedReferences.isEmpty()) {
+ SymbolMap map = new SymbolMap();
+ for (Reference reference : correlatedReferences) {
+ map.addMapping(reference.getExpression(), reference.getExpression());
+ }
+ subCommand.setCorrelatedReferences(map);
+ }
}
- SymbolMap map = new SymbolMap();
- for (Reference reference : correlatedReferences) {
- map.addMapping(reference.getExpression(), reference.getExpression());
- }
- node.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, map);
node.addGroups(GroupsUsedByElementsVisitor.getGroups(node.getCorrelatedReferenceElements()));
}
}
+ private static Set<GroupSymbol> getGroupSymbols(PlanNode plan) {
+ Set<GroupSymbol> groupSymbols = new HashSet<GroupSymbol>();
+ for (PlanNode source : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE))
{
+ groupSymbols.addAll(source.getGroups());
+ }
+ return groupSymbols;
+ }
+
/**
* Method connectChildPlans.
* @param plan
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -127,9 +127,6 @@
// Special constant used in converting plan to process for all nodes
OUTPUT_COLS, // List <SingleElementSymbol>
- // Plan node constants, common to any or multiple plan node types
- CORRELATED_REFERENCES, // SymbolMap
-
// Plan Node Cost Estimate Constants
EST_SET_SIZE, // Integer represents the estimated set size this node would
produce for a sibling node as the indenpendent node in a dependent join scenario
EST_DEP_CARDINALITY, // Float value that represents the estimated cardinality
(amount of rows) produced by this node as the dependent node in a dependent join scenario
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/PlanNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -295,31 +295,55 @@
node.addLastChild(this);
}
+ public List<SymbolMap> getCorrelatedReferences() {
+ List<SubqueryContainer> containers = getSubqueryContainers();
+ if (containers.isEmpty()) {
+ return Collections.emptyList();
+ }
+ ArrayList<SymbolMap> result = new
ArrayList<SymbolMap>(containers.size());
+ for (SubqueryContainer container : containers) {
+ SymbolMap map = container.getCommand().getCorrelatedReferences();
+ if (map != null) {
+ result.add(map);
+ }
+ }
+ return result;
+ }
+
public Set<ElementSymbol> getCorrelatedReferenceElements() {
- SymbolMap refs = (SymbolMap)
this.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
+ List<SymbolMap> maps = getCorrelatedReferences();
- if(refs == null) {
+ if(maps.isEmpty()) {
return Collections.emptySet();
}
-
- List<Expression> values = refs.getValues();
- HashSet<ElementSymbol> result = new
HashSet<ElementSymbol>(values.size());
- for (Expression expr : values) {
- ElementCollectorVisitor.getElements(expr, result);
+ HashSet<ElementSymbol> result = new HashSet<ElementSymbol>();
+ for (SymbolMap symbolMap : maps) {
+ List<Expression> values = symbolMap.getValues();
+ for (Expression expr : values) {
+ ElementCollectorVisitor.getElements(expr, result);
+ }
}
return result;
}
public List<SubqueryContainer> getSubqueryContainers() {
Collection<? extends LanguageObject> toSearch = Collections.emptyList();
- if (this.getType() == NodeConstants.Types.SELECT){
- Criteria criteria =
(Criteria)this.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- toSearch = Arrays.asList(criteria);
- }
- if (this.getType() == NodeConstants.Types.PROJECT) {
- toSearch = (Collection)this.getProperty(NodeConstants.Info.PROJECT_COLS);
+ switch (this.getType()) {
+ case NodeConstants.Types.SELECT: {
+ Criteria criteria = (Criteria) this.getProperty(NodeConstants.Info.SELECT_CRITERIA);
+ toSearch = Arrays.asList(criteria);
+ break;
+ }
+ case NodeConstants.Types.PROJECT: {
+ toSearch = (Collection) this.getProperty(NodeConstants.Info.PROJECT_COLS);
+ break;
+ }
+ case NodeConstants.Types.JOIN: {
+ toSearch = (List<Criteria>)
this.getProperty(NodeConstants.Info.JOIN_CRITERIA);
+ break;
+ }
}
- return
(List<SubqueryContainer>)ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(toSearch);
+ return (List<SubqueryContainer>)
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(toSearch);
}
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -22,7 +22,6 @@
package com.metamatrix.query.optimizer.relational.rules;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -35,7 +34,6 @@
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
import com.metamatrix.query.sql.ReservedWords;
-import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
@@ -44,7 +42,6 @@
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
/**
*/
@@ -293,40 +290,6 @@
return caps.supportsCapability(Capability.QUERY_ORDERBY);
}
- public static boolean supportsJoinExpression(Object modelID, List joinCriteria,
QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- if (metadata.isVirtualModel(modelID)){
- return false;
- }
-
- // Find capabilities
- SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
-
- if(! caps.supportsCapability(Capability.FUNCTION)) {
- return false;
- }
-
- if(joinCriteria != null && joinCriteria.size() > 0) {
- Iterator iter = joinCriteria.iterator();
- while(iter.hasNext()) {
- Criteria crit = (Criteria) iter.next();
- Collection functions = FunctionCollectorVisitor.getFunctions(crit,
false);
-
- Iterator funcIter = functions.iterator();
- while(funcIter.hasNext()) {
- Function function = (Function) funcIter.next();
- if(! supportsScalarFunction(modelID, function, metadata, capFinder))
{
- return false;
- }
- }
- }
- }
-
- // Found nothing unsupported
- return true;
- }
-
public static boolean supportsScalarSubquery(Object modelID, ScalarSubquery subquery,
QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
throws QueryMetadataException, MetaMatrixComponentException {
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-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -23,7 +23,6 @@
package com.metamatrix.query.optimizer.relational.rules;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -66,7 +65,6 @@
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.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
public class FrameUtil {
@@ -103,9 +101,9 @@
return;
}
- for (Map.Entry<ElementSymbol, Expression> entry : new
HashSet<Map.Entry<ElementSymbol,
Expression>>(parentSymbolMap.asMap().entrySet())) {
- parentSymbolMap.addMapping(entry.getKey(),
convertExpression(entry.getValue(), symbolMap));
- }
+ for (Map.Entry<ElementSymbol, Expression> entry :
parentSymbolMap.asUpdatableMap().entrySet()) {
+ entry.setValue(convertExpression(entry.getValue(), symbolMap));
+ }
}
@@ -135,18 +133,17 @@
*/
private static void convertAccessPatterns(Map symbolMap,
PlanNode node) throws QueryPlannerException
{
- List accessPatterns =
(List)node.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
+ List<AccessPattern> accessPatterns =
(List<AccessPattern>)node.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
if (accessPatterns != null) {
- for (Iterator i = accessPatterns.iterator(); i.hasNext();) {
- AccessPattern ap = (AccessPattern)i.next();
- Set newElements = new HashSet();
+ for (AccessPattern ap : accessPatterns) {
+ Set<ElementSymbol> newElements = new
HashSet<ElementSymbol>();
for (Iterator elems = ap.getUnsatisfied().iterator(); elems.hasNext();)
{
ElementSymbol symbol = (ElementSymbol)elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
newElements.addAll(ElementCollectorVisitor.getElements(mapped,
true));
}
ap.setUnsatisfied(newElements);
- Set newHistory = new HashSet();
+ Set<ElementSymbol> newHistory = new
HashSet<ElementSymbol>();
for (Iterator elems = ap.getCurrentElements().iterator();
elems.hasNext();) {
ElementSymbol symbol = (ElementSymbol)elems.next();
Expression mapped = convertExpression(symbol, symbolMap);
@@ -173,6 +170,18 @@
int type = node.getType();
+ // Convert expressions from correlated subquery references;
+ List<SymbolMap> refMaps = node.getCorrelatedReferences();
+ boolean hasRefs = false;
+ for (SymbolMap refs : refMaps) {
+ for (Map.Entry<ElementSymbol, Expression> ref :
refs.asUpdatableMap().entrySet()) {
+ hasRefs = true;
+ Expression expr = ref.getValue();
+ Expression convertedExpr = convertExpression(expr, symbolMap);
+ ref.setValue(convertedExpr);
+ }
+ }
+
if(newGroup != null) {
if (!hasOld) {
return;
@@ -182,20 +191,10 @@
groups.clear();
}
- // 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 convertedExpr = convertExpression(expr, symbolMap);
- ref.setValue(convertedExpr);
- if (newGroup == null) {
- GroupsUsedByElementsVisitor.getGroups(convertedExpr, groups);
- }
- }
+ if (hasRefs) {
+
groups.addAll(GroupsUsedByElementsVisitor.getGroups(node.getCorrelatedReferenceElements()));
}
-
+
if(type == NodeConstants.Types.SELECT) {
Criteria crit = (Criteria)
node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
crit = convertCriteria(crit, symbolMap);
@@ -346,12 +345,6 @@
return map;
}
- static boolean hasSubquery(PlanNode critNode) {
- Criteria crit =
(Criteria)critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- Collection subCrits =
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crit);
- return (subCrits.size() > 0);
- }
-
/**
* Find the SOURCE, SET_OP, JOIN, or NULL node that originates the given groups
(typically from a criteria node).
* In the case of join nodes the best fit will be found rather than just the first
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -72,7 +72,7 @@
* @return
*/
static final JoinType optimizeJoinType(PlanNode critNode, PlanNode joinNode,
QueryMetadataInterface metadata) {
- if (critNode.getGroups().isEmpty() ||
!joinNode.getGroups().containsAll(critNode.getGroups()) ||
FrameUtil.hasSubquery(critNode)) {
+ if (critNode.getGroups().isEmpty() ||
!joinNode.getGroups().containsAll(critNode.getGroups())) {
return null;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -54,7 +54,6 @@
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.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -431,8 +430,7 @@
// Gather elements from correlated subquery references;
// currently only for SELECT or PROJECT nodes
- SymbolMap refs =
(SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (refs != null){
+ for (SymbolMap refs : node.getCorrelatedReferences()) {
for (Expression expr : refs.asMap().values()) {
AggregateSymbolCollectorVisitor.getAggregates(expr, requiredSymbols,
requiredSymbols);
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -68,6 +68,7 @@
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
public final class RuleCollapseSource implements OptimizerRule {
@@ -149,6 +150,7 @@
Query query = new Query();
Select select = new Select();
List<SingleElementSymbol> columns =
(List<SingleElementSymbol>)node.getProperty(NodeConstants.Info.OUTPUT_COLS);
+
replaceCorrelatedReferences(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(columns));
select.addSymbols(columns);
query.setSelect(select);
query.setFrom(new From());
@@ -168,6 +170,7 @@
switch(node.getType()) {
case NodeConstants.Types.JOIN:
{
+ replaceCorrelatedReferences(node.getSubqueryContainers());
JoinType joinType = (JoinType)
node.getProperty(NodeConstants.Info.JOIN_TYPE);
List crits = (List) node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
@@ -245,34 +248,7 @@
case NodeConstants.Types.SELECT:
{
Criteria crit = (Criteria)
node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- List<SubqueryContainer> containers = node.getSubqueryContainers();
- for (SubqueryContainer container : containers) {
- RelationalPlan subqueryPlan =
(RelationalPlan)container.getCommand().getProcessorPlan();
- if (subqueryPlan == null) {
- continue;
- }
- AccessNode child = (AccessNode)subqueryPlan.getRootNode();
- Command command = child.getCommand();
- final SymbolMap map =
(SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if (map != null) {
- ExpressionMappingVisitor visitor = new
ExpressionMappingVisitor(null) {
- @Override
- public Expression replaceExpression(
- Expression element) {
- if (element instanceof Reference) {
- Reference ref = (Reference)element;
- Expression replacement =
map.getMappedExpression(ref.getExpression());
- if (replacement != null) {
- return replacement;
- }
- }
- return element;
- }
- };
- DeepPostOrderNavigator.doVisit(command, visitor);
- }
- container.setCommand(command);
- }
+ replaceCorrelatedReferences(node.getSubqueryContainers());
if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING)) {
query.setCriteria(
CompoundCriteria.combineCriteria(query.getCriteria(), crit) );
} else {
@@ -306,6 +282,36 @@
}
}
+ private void replaceCorrelatedReferences(List<SubqueryContainer> containers) {
+ for (SubqueryContainer container : containers) {
+ RelationalPlan subqueryPlan =
(RelationalPlan)container.getCommand().getProcessorPlan();
+ if (subqueryPlan == null) {
+ continue;
+ }
+ AccessNode child = (AccessNode)subqueryPlan.getRootNode();
+ Command command = child.getCommand();
+ final SymbolMap map = container.getCommand().getCorrelatedReferences();
+ if (map != null) {
+ ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(null) {
+ @Override
+ public Expression replaceExpression(
+ Expression element) {
+ if (element instanceof Reference) {
+ Reference ref = (Reference)element;
+ Expression replacement = map.getMappedExpression(ref.getExpression());
+ if (replacement != null) {
+ return replacement;
+ }
+ }
+ return element;
+ }
+ };
+ DeepPostOrderNavigator.doVisit(command, visitor);
+ }
+ container.setCommand(command);
+ }
+ }
+
private void processLimit(PlanNode node,
QueryCommand query) {
Expression limit =
(Expression)node.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCopyCriteria.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -346,7 +346,7 @@
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
if(node.getGroups().size() == 1 && crit != null) {
- if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING) &&
!FrameUtil.hasSubquery(node)) {
+ if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING) &&
node.getSubqueryContainers().isEmpty()) {
if (!node.hasBooleanProperty(NodeConstants.Info.IS_COPIED)) {
toCopy.add(crit);
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleMergeCriteria.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -23,7 +23,6 @@
package com.metamatrix.query.optimizer.relational.rules;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -39,7 +38,6 @@
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.CompoundCriteria;
import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -54,13 +52,11 @@
throws QueryPlannerException, MetaMatrixComponentException {
// Find strings of criteria and merge them, removing duplicates
- List criteriaChains = new ArrayList();
+ List<PlanNode> criteriaChains = new ArrayList<PlanNode>();
findCriteriaChains(plan, criteriaChains);
// Merge chains
- Iterator chainIter = criteriaChains.iterator();
- while(chainIter.hasNext()) {
- PlanNode critNode = (PlanNode) chainIter.next();
+ for (PlanNode critNode : criteriaChains) {
mergeChain(critNode);
}
@@ -72,7 +68,7 @@
* @param node Root node to search
* @param foundNodes Roots of criteria chains
*/
- void findCriteriaChains(PlanNode root, List foundNodes)
+ void findCriteriaChains(PlanNode root, List<PlanNode> foundNodes)
throws QueryPlannerException, MetaMatrixComponentException {
PlanNode recurseRoot = root;
@@ -100,7 +96,6 @@
// Remove all of chain except root, collect crit from each
CompoundCriteria critParts = new CompoundCriteria();
- SymbolMap correlatedReferences = new SymbolMap();
PlanNode current = chainRoot;
boolean isDependentSet = false;
while(current.getType() == NodeConstants.Types.SELECT) {
@@ -108,8 +103,6 @@
isDependentSet |=
current.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET);
-
correlatedReferences.merge((SymbolMap)current.getProperty(NodeConstants.Info.CORRELATED_REFERENCES));
-
// Recurse
PlanNode last = current;
current = current.getLastChild();
@@ -129,9 +122,6 @@
// Replace criteria at root with new combined criteria
chainRoot.setProperty(NodeConstants.Info.SELECT_CRITERIA, combinedCrit);
- if (!correlatedReferences.asMap().isEmpty()){
- chainRoot.setProperty(NodeConstants.Info.CORRELATED_REFERENCES,
correlatedReferences);
- }
// Reset group for node based on combined criteria
chainRoot.getGroups().clear();
@@ -140,23 +130,6 @@
chainRoot.addGroups(GroupsUsedByElementsVisitor.getGroups(chainRoot.getCorrelatedReferenceElements()));
}
- /**
- * Add the 'addToProps' List (if not null) to the 'props' List
- * (if not null).
- * @param props
- * @param addToProps
- * @return 'props' List, or else new List if 'props' was null
- */
- private static List addProperties(List props, List addToProps) {
- if (addToProps != null){
- if (props == null){
- props = new ArrayList();
- }
- props.addAll(addToProps);
- }
- return props;
- }
-
public String toString() {
return "MergeCriteria"; //$NON-NLS-1$
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -153,7 +153,7 @@
critNode = currentNode.getParent();
- if (FrameUtil.hasSubquery(currentNode) || !currentNode.getGroups().isEmpty())
{
+ if (!currentNode.getGroups().isEmpty()) {
continue;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -104,7 +104,7 @@
boolean moved = false;
- if((critNode.getGroups().isEmpty() &&
!FrameUtil.hasSubquery(critNode)) || !atBoundary(critNode, sourceNode)) {
+ if((critNode.getGroups().isEmpty() &&
critNode.getSubqueryContainers().isEmpty()) || !atBoundary(critNode, sourceNode)) {
deadNodes.add(critNode);
continue;
}
@@ -136,7 +136,7 @@
private PlanNode findOriginatingNode(QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, PlanNode critNode)
throws MetaMatrixComponentException, QueryMetadataException {
- if (critNode.getGroups().isEmpty() && FrameUtil.hasSubquery(critNode)) {
+ if (critNode.getGroups().isEmpty()) {
Object modelId = RuleRaiseAccess.isEligibleSubquery(critNode, null, metadata,
capFinder);
if (modelId != null) {
for (PlanNode node : NodeEditor.findAllNodes(critNode, NodeConstants.Types.SOURCE))
{
@@ -159,10 +159,6 @@
* @return
*/
private boolean handleJoinCriteria(PlanNode joinNode, PlanNode critNode,
QueryMetadataInterface metadata) {
- //we currently don't allow subqueries in join criteria
- if (FrameUtil.hasSubquery(critNode)) {
- return false;
- }
JoinType jt = (JoinType)joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
if (jt == JoinType.JOIN_CROSS || jt == JoinType.JOIN_INNER) {
@@ -313,7 +309,7 @@
if (child != null && child.getType() == NodeConstants.Types.SET_OP)
{
//only allow criteria without subqueires - node cloning doesn't allow
for the proper creation of
//multiple nodes with the same subqueries
- if (child == sourceNode.getFirstChild() &&
!FrameUtil.hasSubquery(critNode)) {
+ if (child == sourceNode.getFirstChild() &&
critNode.getSubqueryContainers().isEmpty()) {
return pushAcrossSetOp(critNode, child);
}
//this could be an access node in the middle of the source and set op,
@@ -443,10 +439,6 @@
Criteria copyCrit = (Criteria) crit.clone();
copyNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, copyCrit);
copyNode.addGroups(critNode.getGroups());
- SymbolMap correlatedReferences =
(SymbolMap)critNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
- if(correlatedReferences != null) {
- copyNode.setProperty(NodeConstants.Info.CORRELATED_REFERENCES, new
SymbolMap(correlatedReferences));
- }
if(critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)) {
copyNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
}
@@ -534,7 +526,7 @@
return false; //not convertable
}
- if (FrameUtil.hasSubquery(critNode)
+ if (!critNode.getSubqueryContainers().isEmpty()
&& checkConversion(symbolMap,
critNode.getCorrelatedReferenceElements()) != null) {
return false; //not convertable, or has an aggregate for a correlated reference
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -60,7 +60,6 @@
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.EvaluateExpressionVisitor;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -119,6 +118,10 @@
{
// Check that the PROJECT contains only functions that can be pushed
List projectCols = (List)
parentNode.getProperty(NodeConstants.Info.PROJECT_COLS);
+
+ if(isEligibleSubquery(parentNode, modelID, metadata, capFinder) ==
null){
+ return null;
+ }
for (int i = 0; i < projectCols.size(); i++) {
SingleElementSymbol symbol =
(SingleElementSymbol)projectCols.get(i);
@@ -322,10 +325,6 @@
return false;
}
- // Check criteria capabilities of source. Criteria (even
- // multi-group criteria) can possibly be pushed if model can
- // support everything in the criteria.
-
if(!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(crit, modelID,
metadata, capFinder) ) {
return false;
}
@@ -343,7 +342,10 @@
* Check whether the subquery in the node is eligible to be pushed.
*/
static Object isEligibleSubquery(PlanNode critNode, Object critNodeModelID,
QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws
MetaMatrixComponentException {
- List<SubqueryContainer> plans = critNode.getSubqueryContainers();
+ return isEligibleSubquery(critNode.getSubqueryContainers(), critNodeModelID,
metadata, capFinder);
+ }
+
+ static Object isEligibleSubquery(List<SubqueryContainer> plans, Object
critNodeModelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws
MetaMatrixComponentException {
for (SubqueryContainer subqueryContainer : plans) {
ProcessorPlan plan = subqueryContainer.getCommand().getProcessorPlan();
if(!(plan instanceof RelationalPlan)) {
@@ -384,19 +386,20 @@
}
// Check whether source supports correlated subqueries and if not, whether
criteria has them
- SymbolMap refs = (SymbolMap)
critNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
+ SymbolMap refs = subqueryContainer.getCommand().getCorrelatedReferences();
try {
if(refs != null && !refs.asMap().isEmpty()) {
if(! CapabilitiesUtil.supportsCorrelatedSubquery(critNodeModelID,
metadata, capFinder)) {
return null;
}
-
+ //TODO: this check sees as correlated references as coming from the
containing scope
+ //but this is only an issue with deeply nested subqueries
if
(!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(command, critNodeModelID,
metadata, capFinder)) {
return null;
}
}
} catch(QueryMetadataException e) {
- throw new MetaMatrixComponentException(e, e.getMessage());
+ throw new MetaMatrixComponentException(e);
}
}
@@ -426,16 +429,9 @@
return false;
}
- if(inSelectClause && !(expr instanceof ElementSymbol)) {
-
if(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr).size() > 0) {
- // Don't support for now
- return false;
-
- } else if(expr instanceof Constant ||
EvaluateExpressionVisitor.willBecomeConstant(expr)) {
- if(! CapabilitiesUtil.supportsSelectLiterals(modelID, metadata,
capFinder)) {
- return false;
- }
- }
+ if(inSelectClause && !(expr instanceof ElementSymbol) &&
!CapabilitiesUtil.supportsSelectLiterals(modelID, metadata, capFinder)
+ && (expr instanceof Constant ||
EvaluateExpressionVisitor.willBecomeConstant(expr))) {
+ return false;
}
// By default, no reason we can't push
@@ -466,7 +462,7 @@
* @return The modelID if the raise can proceed and what common model these combined
* nodes will be sent to
*/
- Object canRaiseOverJoin(PlanNode joinNode, QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, boolean afterJoinPlanning)
+ private static Object canRaiseOverJoin(PlanNode joinNode, QueryMetadataInterface
metadata, CapabilitiesFinder capFinder, boolean afterJoinPlanning)
throws QueryMetadataException, MetaMatrixComponentException {
List crits = (List) joinNode.getProperty(NodeConstants.Info.JOIN_CRITERIA);
@@ -495,7 +491,7 @@
static Object canRaiseOverJoin(List children,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder,
- List crits,
+ List<Criteria> crits,
JoinType type) throws QueryMetadataException,
MetaMatrixComponentException {
Object modelID = null;
@@ -527,9 +523,7 @@
boolean supportsSelfJoins = CapabilitiesUtil.supportsSelfJoins(accessModelID,
metadata, capFinder);
if (!supportsSelfJoins) {
- Iterator groupIter = childNode.getGroups().iterator();
- while(groupIter.hasNext()) {
- GroupSymbol groupSymbol = (GroupSymbol) groupIter.next();
+ for (GroupSymbol groupSymbol : childNode.getGroups()) {
Object groupID = groupSymbol.getMetadataID();
if(!groupIDs.add(groupID)) {
// Already seen group - can't raise access over self join
@@ -553,21 +547,14 @@
// Check that model supports join expressions
if(crits != null && !crits.isEmpty()) {
- // Check whether has expression
- boolean hasExpression = false;
- Iterator critIter = crits.iterator();
- while(critIter.hasNext()) {
- Criteria crit = (Criteria) critIter.next();
- if(FunctionCollectorVisitor.getFunctions(crit, false).size() >
0) {
- hasExpression = true;
- break;
- }
+ for (Criteria crit : crits) {
+ if(!CriteriaCapabilityValidatorVisitor.canPushLanguageObject(crit,
accessModelID, metadata, capFinder) ) {
+ return null;
+ }
}
-
- // If expression was found and capabilities don't support, abort
this join
- if(hasExpression && !
CapabilitiesUtil.supportsJoinExpression(accessModelID, crits, metadata, capFinder)) {
- return null;
- }
+
if(isEligibleSubquery(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crits),
accessModelID, metadata, capFinder) == null){
+ return null;
+ }
}
modelID = accessModelID;
Modified:
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -51,7 +51,6 @@
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.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
@@ -108,6 +107,7 @@
}
List crits = (List)node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
ElementCollectorVisitor.getElements(crits, elements);
+ elements.addAll(node.getCorrelatedReferenceElements());
break;
}
case NodeConstants.Types.PROJECT:
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/ProcessorDataManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -24,12 +24,28 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.eval.LookupEvaluator;
import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.util.CommandContext;
-public interface ProcessorDataManager extends LookupEvaluator {
+public interface ProcessorDataManager {
TupleSource registerRequest(Object processorId, Command command, String modelName,
String connectorBindingId, int nodeID)
throws MetaMatrixComponentException, MetaMatrixProcessingException;
+
+ /**
+ * Lookup a value from a cached code table. If the code table is not loaded, it will
be
+ * loaded on the first query. Code tables should be cached based on a combination
of
+ * the codeTableName, returnElementName, and keyElementName. If the table is not
loaded,
+ * a request will be made and the method should throw a BlockedException.
+ */
+ Object lookupCodeValue(CommandContext context,
+ String codeTableName,
+ String returnElementName,
+ String keyElementName,
+ Object keyValue) throws BlockedException,
+ MetaMatrixComponentException,
MetaMatrixProcessingException;
+
+ void clearCodeTables();
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/TempTableDataManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -91,4 +91,9 @@
return this.processorDataManager.lookupCodeValue(context, codeTableName,
returnElementName, keyElementName, keyValue);
}
+ @Override
+ public void clearCodeTables() {
+ this.processorDataManager.clearCodeTables();
+ }
+
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -33,7 +33,7 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.util.VariableContext;
@@ -45,7 +45,7 @@
* a expression or a command(stored as a processplan). The Processing of the command is
* expected to result in 1 column, 1 row tuple.</p>
*/
-public abstract class AbstractAssignmentInstruction extends CommandInstruction {
+public abstract class AbstractAssignmentInstruction extends ProgramInstruction {
// variable whose value is updated in the context
private ElementSymbol variable;
@@ -63,11 +63,9 @@
* @throws BlockedException
* @throws MetaMatrixComponentException if error processing command or expression on
this instruction
*/
- public void process(ProgramEnvironment env) throws BlockedException,
+ public void process(ProcedurePlan procEnv) throws BlockedException,
MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
VariableContext varContext = procEnv.getCurrentVariableContext();
Object value = null;
if (this.getExpression() != null || this.getProcessorPlan() != null) {
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AssignmentInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -32,7 +32,7 @@
/**
* <p> This instruction updates the current variable context with a value for the
Variable
- * defined using a DeclareInstruction, the vriable value is obtained by either
processing
+ * defined using a DeclareInstruction, the variable value is obtained by either
processing
* a expression or a command(stored as a processplan). The Processing of the command is
* expected to result in 1 column, 1 row tuple.</p>
*/
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/BreakInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -38,7 +38,7 @@
return "BREAK INSTRUCTION"; //$NON-NLS-1$
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
super.process(env);
env.incrementProgramCounter();
}
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CommandInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.proc;
-
-import com.metamatrix.query.processor.program.ProgramInstruction;
-
-
-/**
- * This abstract base class has common methods for dealing with instructions that
- * have commands. In particular commands may have nested EXECs that have parameter
- * references, which require some special handling.
- *
- * @since 4.4
- */
-public abstract class CommandInstruction extends ProgramInstruction {
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ContinueInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -37,7 +37,7 @@
return "CONTINUE INSTRUCTION"; //$NON-NLS-1$
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
Program parentProgram = env.peek();
//find the parent program that contains the loop/while instruction
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/CreateCursorResultSetInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -34,11 +34,11 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
/**
*/
-public class CreateCursorResultSetInstruction extends CommandInstruction {
+public class CreateCursorResultSetInstruction extends ProgramInstruction {
protected String rsName;
protected ProcessorPlan plan;
@@ -56,11 +56,9 @@
* @throws BlockedException if this result set is not selecting from
* only temp groups
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
if(procEnv.resultSetExists(rsName)) {
procEnv.removeResults(rsName);
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -49,7 +49,6 @@
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.resolver.util.ResolveVirtualGroupCriteriaVisitor;
@@ -86,17 +85,15 @@
* immediately.
* </p>
*/
-public class ExecDynamicSqlInstruction extends CommandInstruction {
+public class ExecDynamicSqlInstruction extends ProgramInstruction {
private static class PopCallInstruction extends ProgramInstruction {
/**
- * @see
com.metamatrix.query.processor.program.ProgramInstruction#process(com.metamatrix.query.processor.program.ProgramEnvironment)
+ * @see
com.metamatrix.query.processor.program.ProgramInstruction#process(ProcedurePlan)
*/
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException,
+ public void process(ProcedurePlan procEnv) throws MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
procEnv.getContext().popCall();
}
@@ -146,11 +143,9 @@
* @throws BlockedException
* if this processing the plan throws a currentVarContext
*/
- public void process(ProgramEnvironment env) throws BlockedException,
+ public void process(ProcedurePlan procEnv) throws BlockedException,
MetaMatrixComponentException, MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
VariableContext localContext = procEnv.getCurrentVariableContext();
try {
@@ -240,7 +235,7 @@
* @throws MetaMatrixComponentException
* @throws MetaMatrixProcessingException
*/
- private void updateContextWithUsingValues(ProcedureEnvironment procEnv,
+ private void updateContextWithUsingValues(ProcedurePlan procEnv,
VariableContext localContext) throws MetaMatrixComponentException,
MetaMatrixProcessingException {
if (dynamicCommand.getUsing() != null
&& !dynamicCommand.getUsing().isEmpty()) {
@@ -367,7 +362,7 @@
* @throws MetaMatrixComponentException
* @throws QueryProcessingException
*/
- private void validateDynamicCommand(ProcedureEnvironment procEnv,
+ private void validateDynamicCommand(ProcedurePlan procEnv,
Command command) throws MetaMatrixComponentException,
QueryProcessingException {
// validate project symbols
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -32,7 +32,7 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
+import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.symbol.GroupSymbol;
/**
@@ -40,7 +40,7 @@
* instruction does not modify the values of any of the variables, hence it's results
are not
* important so they are removed immediately.</p>
*/
-public class ExecSqlInstruction extends CommandInstruction {
+public class ExecSqlInstruction extends ProgramInstruction {
public static final String RS_NAME = "EXECSQL_INSTRUCTION"; //$NON-NLS-1$
@@ -68,11 +68,9 @@
* counter is incremented after execution of the plan.</p>
* @throws BlockedException if this processing the plan throws a currentVarContext
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
if(intoGroup != null && intoGroup.isTempGroupSymbol()){
procEnv.executePlan(commandPlan, intoGroup.getName());
}else{
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -34,7 +34,6 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.lang.Criteria;
@@ -87,13 +86,11 @@
* evaluate to true, this instruction will increment the program counter of the
* current program.
* @throws MetaMatrixProcessingException
- * @see ProgramInstruction#process(ProgramEnvironment)
+ * @see ProgramInstruction#process(ProcedurePlan)
*/
- public void process(ProgramEnvironment env)
+ public void process(ProcedurePlan procEnv)
throws BlockedException, MetaMatrixComponentException,
MetaMatrixProcessingException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment) env;
-
boolean evalValue = procEnv.evaluateCriteria(condition);
if(evalValue) {
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -34,7 +34,6 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.VariableContext;
@@ -54,9 +53,7 @@
this.loopProgram = loopProgram;
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
- ProcedureEnvironment procEnv = (ProcedureEnvironment)env;
-
+ public void process(ProcedurePlan procEnv) throws MetaMatrixComponentException {
List currentRow = procEnv.getCurrentRow(rsName);
VariableContext varContext = procEnv.getCurrentVariableContext();
//set results to the variable context(the cursor.element is treated as variable)
@@ -111,7 +108,7 @@
/**
* @see
com.metamatrix.query.processor.proc.RepeatedInstruction#testCondition(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public boolean testCondition(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
+ public boolean testCondition(ProcedurePlan procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
if(!procEnv.resultSetExists(rsName)) {
procEnv.executePlan(plan, rsName);
}
@@ -129,7 +126,7 @@
/**
* @see
com.metamatrix.query.processor.proc.RepeatedInstruction#postInstruction(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public void postInstruction(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException {
+ public void postInstruction(ProcedurePlan procEnv) throws
MetaMatrixComponentException {
procEnv.removeResults(rsName);
}
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedureEnvironment.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,363 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.proc;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.TupleSourceID;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.execution.QueryExecPlugin;
-import com.metamatrix.query.processor.NullTupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
-import com.metamatrix.query.processor.program.ProgramInstruction;
-import com.metamatrix.query.sql.ProcedureReservedWords;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.tempdata.TempTableStore;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.ErrorMessageKeys;
-
-/**
- * <p>This class defines the environment that procedure language programs run in
- * and what {@link ProgramInstruction}s can access during execution. This
- * environment holds references to the {@link VariableContext}, this variable
- * context is updated with new variables and their values upon execution of the
- * program instructions.</p>
- */
-public class ProcedureEnvironment extends ProgramEnvironment {
-
- private Map tupleSourceMap = new HashMap(); // rsName -> TupleSource
- private Map tupleSourceIDMap = new HashMap(); // rsName -> TupleSourceID
- private Map currentRowMap = new HashMap();
-
- private static ElementSymbol ROWS_UPDATED =
- new
ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWS_UPDATED);
//$NON-NLS-1$
-
- private static int NO_ROWS_UPDATED = 0;
- private ProcedurePlan plan;
- private VariableContext currentVarContext;
- private boolean isUpdateProcedure = true;
-
- private TupleSource lastTupleSource;
-
- private List outputElements;
-
- private TempTableStore tempTableStore;
-
- private LinkedList tempContext = new LinkedList();
-
- /**
- * Constructor for ProcedureEnvironment.
- */
- public ProcedureEnvironment() {
- super();
- this.currentVarContext = new VariableContext(true);
- this.currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
- }
-
- /**
- * Initialize the environment with the procedure plan.
- */
- public void initialize(ProcessorPlan plan) {
- this.plan = (ProcedurePlan)plan;
- }
-
- private TupleSource getUpdateCountAsToupleSource() {
- Object rowCount = currentVarContext.getValue(ROWS_UPDATED);
- if(rowCount == null) {
- rowCount = new Integer(NO_ROWS_UPDATED);
- }
-
- final List updateResult = new ArrayList(1);
- updateResult.add(rowCount);
-
- return new UpdateCountTupleSource(updateResult);
- }
-
- /**
- * <p> Get the current <code>VariavleContext</code> on this
environment.
- * The VariableContext is updated with variables and their values by
- * {@link ProgramInstruction}s that are part of the ProcedurePlan that use
- * this environment.</p>
- * @return The current <code>VariariableContext</code>.
- */
- public VariableContext getCurrentVariableContext() {
- return this.currentVarContext;
- }
-
- public void executePlan(ProcessorPlan command, String rsName)
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
- boolean isExecSQLInstruction = rsName.equals(ExecSqlInstruction.RS_NAME);
- // Defect 14544: Close all non-final ExecSqlInstruction tuple sources before
creating a new source.
- // This guarantees that the tuple source will be removed predictably from the
buffer manager.
- if (isExecSQLInstruction) {
- removeResults(ExecSqlInstruction.RS_NAME);
- }
-
- TupleSourceID tsID = this.plan.registerRequest(command, this.currentVarContext);
- TupleSource source = this.plan.getResults(tsID);
- tupleSourceIDMap.put(rsName.toUpperCase(), tsID);
- tupleSourceMap.put(rsName.toUpperCase(), source);
- if(isExecSQLInstruction){
- //keep a reference to the tuple source
- //it may be the last one
- this.lastTupleSource = source;
- }
- }
-
- /**
- * @throws MetaMatrixComponentException
- * @see com.metamatrix.query.processor.program.ProgramEnvironment#pop()
- */
- public void pop() throws MetaMatrixComponentException {
- super.pop();
- if (this.currentVarContext.getParentContext() != null) {
- this.currentVarContext = this.currentVarContext.getParentContext();
- }
- Set current = getTempContext();
-
- Set tempTables = getLocalTempTables();
-
- tempTables.addAll(current);
-
- for (Iterator i = tempTables.iterator(); i.hasNext();) {
- removeResults((String)i.next());
- }
-
- this.tempContext.removeLast();
- }
-
- /**
- * @see
com.metamatrix.query.processor.program.ProgramEnvironment#push(com.metamatrix.query.processor.program.Program)
- */
- public void push(Program program) {
- super.push(program);
- VariableContext context = new VariableContext(true);
- context.setParentContext(this.currentVarContext);
- this.currentVarContext = context;
-
- Set current = getTempContext();
-
- Set tempTables = getLocalTempTables();
-
- current.addAll(tempTables);
- this.tempContext.add(new HashSet());
- }
-
- /**
- * @see
com.metamatrix.query.processor.program.ProgramEnvironment#incrementProgramCounter()
- */
- public void incrementProgramCounter() throws MetaMatrixComponentException {
- Program program = peek();
- ProgramInstruction instr = program.getCurrentInstruction();
- if (instr instanceof RepeatedInstruction) {
- RepeatedInstruction repeated = (RepeatedInstruction)instr;
- repeated.postInstruction(this);
- }
- super.incrementProgramCounter();
- }
-
- /**
- * @return
- */
- private Set getLocalTempTables() {
- Set tempTables = this.tempTableStore.getAllTempTables();
-
- //determine what was created in this scope
- for (int i = 0; i < tempContext.size() - 1; i++) {
- tempTables.removeAll((Set)tempContext.get(i));
- }
- return tempTables;
- }
-
- public Set getTempContext() {
- if (this.tempContext.isEmpty()) {
- tempContext.addLast(new HashSet());
- }
- return (Set)this.tempContext.getLast();
- }
-
- public List getCurrentRow(String rsName) {
- return (List) currentRowMap.get(rsName.toUpperCase());
- }
-
- public boolean iterateCursor(String rsName)
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- String rsKey = rsName.toUpperCase();
-
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source == null) {
- // TODO - throw exception?
- return false;
- }
-
- List row = source.nextTuple();
- currentRowMap.put(rsKey, row);
- return (row != null);
- }
-
- public void removeResults(String rsName) throws MetaMatrixComponentException {
- String rsKey = rsName.toUpperCase();
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source != null) {
- source.closeSource();
- TupleSourceID tsID = (TupleSourceID) tupleSourceIDMap.get(rsKey);
- this.plan.removeTupleSource(tsID);
- tupleSourceMap.remove(rsKey);
- tupleSourceIDMap.remove(rsKey);
- currentRowMap.remove(rsKey);
- this.tempTableStore.removeTempTableByName(rsKey);
- }
- }
-
-
- /**
- * Get the schema from the tuple source that
- * represents the columns in a result set
- * @param rsName the ResultSet name (not a temp group)
- * @return List of elements
- * @throws QueryProcessorException if the list of elements is null
- */
- public List getSchema(String rsName) throws MetaMatrixComponentException {
-
- // get the tuple source
- String rsKey = rsName.toUpperCase();
- TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
- if(source == null){
- throw new
MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0037,
rsName));
- }
- // get the schema from the tuple source
- List schema = source.getSchema();
- if(schema == null){
- throw new
MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0038));
- }
-
- return schema;
- }
-
- public boolean resultSetExists(String rsName) {
- String rsKey = rsName.toUpperCase();
- boolean exists = this.tupleSourceMap.containsKey(rsKey);
- return exists;
- }
-
- public ProcessorDataManager getDataManager() {
- return this.plan.getDataManager();
- }
-
- public CommandContext getContext() {
- CommandContext context = this.plan.getContext();
- context.setVariableContext(currentVarContext);
- return context;
- }
-
- /**
- * @return
- */
- public boolean isUpdateProcedure() {
- return isUpdateProcedure;
- }
-
- /**
- * @param b
- */
- public void setUpdateProcedure(boolean b) {
- isUpdateProcedure = b;
- }
-
- /**
- * @return
- */
- public TupleSource getFinalTupleSource() {
- if(this.isUpdateProcedure){
- return this.getUpdateCountAsToupleSource();
- }
-
- if(lastTupleSource == null){
- return new NullTupleSource(null);
- }
- return lastTupleSource;
- }
-
- public List getOutputElements() {
- return outputElements;
- }
-
- public void setOutputElements(List outputElements) {
- this.outputElements = outputElements;
- }
-
- public void reset() {
- tupleSourceMap.clear();
- tupleSourceIDMap.clear();
- currentRowMap.clear();
- currentVarContext = new VariableContext();
- currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
- lastTupleSource = null;
- }
-
-
- /**
- * @return Returns the tempTableStore.
- * @since 5.5
- */
- public TempTableStore getTempTableStore() {
- return this.tempTableStore;
- }
-
-
- /**
- * @param tempTableStore The tempTableStore to set.
- * @since 5.5
- */
- public void setTempTableStore(TempTableStore tempTableStore) {
- this.tempTableStore = tempTableStore;
- }
-
- boolean evaluateCriteria(Criteria condition) throws BlockedException,
MetaMatrixProcessingException, MetaMatrixComponentException {
- return new Evaluator(Collections.emptyMap(), getDataManager(),
getContext()).evaluate(condition, Collections.emptyList());
- }
-
- Object evaluateExpression(Expression expression) throws BlockedException,
MetaMatrixProcessingException, MetaMatrixComponentException {
- return new Evaluator(Collections.emptyMap(), getDataManager(),
getContext()).evaluate(expression, Collections.emptyList());
- }
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -25,9 +25,14 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
@@ -41,12 +46,12 @@
import com.metamatrix.common.log.LogManager;
import com.metamatrix.core.MetaMatrixCoreException;
import com.metamatrix.dqp.util.LogConstants;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.processor.BaseProcessorPlan;
import com.metamatrix.query.processor.DescribableUtil;
+import com.metamatrix.query.processor.NullTupleSource;
import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.QueryProcessor;
@@ -54,6 +59,9 @@
import com.metamatrix.query.processor.program.Program;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.processor.program.ProgramUtil;
+import com.metamatrix.query.processor.relational.SubqueryAwareEvaluator;
+import com.metamatrix.query.sql.ProcedureReservedWords;
+import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.util.VariableContext;
@@ -65,9 +73,6 @@
*/
public class ProcedurePlan extends BaseProcessorPlan {
- // State passed during construction
- private ProcedureEnvironment env;
- //this reference should never be used for anything except toString method
private Program originalProgram;
// State initialized by processor
@@ -84,16 +89,41 @@
private int beginBatch = 1;
private List batchRows;
private boolean lastBatch = false;
- private Map params;
+ private Map<ElementSymbol, Expression> params;
private QueryMetadataInterface metadata;
+
+ private Map tupleSourceMap = new HashMap(); // rsName -> TupleSource
+ private Map tupleSourceIDMap = new HashMap(); // rsName -> TupleSourceID
+ private Map currentRowMap = new HashMap();
+ private static ElementSymbol ROWS_UPDATED =
+ new
ElementSymbol(ProcedureReservedWords.VARIABLES+"."+ProcedureReservedWords.ROWS_UPDATED);
//$NON-NLS-1$
+
+ private static int NO_ROWS_UPDATED = 0;
+ private VariableContext currentVarContext;
+ private boolean isUpdateProcedure = true;
+
+ private TupleSource lastTupleSource;
+
+ private List outputElements;
+
+ private TempTableStore tempTableStore;
+
+ private LinkedList tempContext = new LinkedList();
+ private SubqueryAwareEvaluator evaluator;
+
+ // Stack of programs, with current program on top
+ private Stack<Program> programs = new Stack<Program>();
+
+ private boolean evaluatedParams;
+
/**
* Constructor for ProcedurePlan.
*/
- public ProcedurePlan(ProcedureEnvironment env) {
- this.env = env;
- this.env.initialize(this);
- this.originalProgram = (Program)this.env.getProgramStack().peek();
+ public ProcedurePlan(Program originalProgram) {
+ this.originalProgram = originalProgram;
+ this.programs.add(originalProgram);
+ createVariableContext();
}
/**
@@ -102,15 +132,26 @@
public void initialize(CommandContext context, ProcessorDataManager dataMgr,
BufferManager bufferMgr) {
this.bufferMgr = bufferMgr;
this.batchSize = bufferMgr.getProcessorBatchSize();
- TempTableStoreImpl tempTableStore = new TempTableStoreImpl(bufferMgr,
context.getConnectionID(), (TempTableStore)context.getTempTableStore());
+ tempTableStore = new TempTableStoreImpl(bufferMgr, context.getConnectionID(),
(TempTableStore)context.getTempTableStore());
this.dataMgr = new TempTableDataManager(dataMgr, tempTableStore);
- env.setTempTableStore(tempTableStore);
setContext(context);
+ if (evaluator == null) {
+ this.evaluator = new SubqueryAwareEvaluator(Collections.emptyMap(),
getDataManager(), getContext(), this.bufferMgr);
+ }
}
public void reset() {
super.reset();
-
+ if (evaluator != null) {
+ evaluator.reset();
+ }
+ evaluatedParams = false;
+ tupleSourceMap.clear();
+ tupleSourceIDMap.clear();
+ currentRowMap.clear();
+ createVariableContext();
+ lastTupleSource = null;
+
done = false;
internalProcessor = null;
internalResultID = null;
@@ -122,10 +163,8 @@
//reset program stack
originalProgram.resetProgramCounter();
- if(env.getProgramStack().empty()){
- env.getProgramStack().push(originalProgram);
- }
- env.reset();
+ programs.clear();
+ programs.push(originalProgram);
LogManager.logTrace(LogConstants.CTX_DQP, "ProcedurePlan reset");
//$NON-NLS-1$
}
@@ -151,42 +190,29 @@
// Run query processor on command
CommandContext subContext = (CommandContext) getContext().clone();
subContext.setVariableContext(currentVariableContext);
- subContext.setTempTableStore(env.getTempTableStore());
+ subContext.setTempTableStore(getTempTableStore());
internalProcessor = new QueryProcessor(subPlan, subContext, this.bufferMgr,
this.dataMgr);
this.internalResultID = this.internalProcessor.getResultsID();
return this.internalResultID;
}
- /**
- * Method for ProcessorEnvironment to remove a tuple source when it is done with it.
- */
- void removeTupleSource(TupleSourceID tupleSourceID)
- throws MetaMatrixComponentException {
- try {
- this.bufferMgr.removeTupleSource(tupleSourceID);
- } catch (TupleSourceNotFoundException e) {
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0021,
QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0021, (String)null));
- } catch (MetaMatrixComponentException e) {
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0022,
QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0022, (String) null));
- }
- LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"removed tuple
source", tupleSourceID, "for result set"}); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Get list of resolved elements describing output columns for this plan.
- * @return List of SingleElementSymbol
- */
- public List getOutputElements() {
-// ArrayList output = new ArrayList(1);
-// ElementSymbol count = new ElementSymbol("Count"); //$NON-NLS-1$
-// count.setType(DataTypeManager.DefaultDataClasses.INTEGER);
-// output.add(count);
-// return output;
- return env.getOutputElements();
- }
-
public void open() throws MetaMatrixProcessingException, MetaMatrixComponentException
{
- evaluateParams();
+ if (this.params != null && !this.evaluatedParams) {
+ for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet())
{
+ ElementSymbol param = entry.getKey();
+ Expression expr = entry.getValue();
+
+ VariableContext context = getCurrentVariableContext();
+ Object value = this.evaluateExpression(expr);
+
+ //check constraint
+ if (value == null &&
!metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
+ throw new
QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam",
expr)); //$NON-NLS-1$
+ }
+ context.setValue(param, value);
+ }
+ }
+ this.evaluatedParams = true;
}
/**
@@ -247,37 +273,43 @@
// execute plan
ProgramInstruction inst = null;
- while (!this.env.getProgramStack().empty()){
- Program program = env.peek();
+ while (!this.programs.empty()){
+ Program program = peek();
inst = program.getCurrentInstruction();
if (inst == null){
LogManager.logTrace(LogConstants.CTX_DQP, "Finished program",
program); //$NON-NLS-1$
- this.env.pop();
+ this.pop();
continue;
}
if (inst instanceof RepeatedInstruction) {
LogManager.logTrace(LogConstants.CTX_DQP, "Executing repeated
instruction", inst); //$NON-NLS-1$
RepeatedInstruction loop = (RepeatedInstruction)inst;
- if (loop.testCondition(env)) {
+ if (loop.testCondition(this)) {
LogManager.logTrace(LogConstants.CTX_DQP, "Passed condition,
executing program " + loop.getNestedProgram()); //$NON-NLS-1$
- inst.process(env);
- env.push(loop.getNestedProgram());
+ inst.process(this);
+ this.push(loop.getNestedProgram());
continue;
}
LogManager.logTrace(LogConstants.CTX_DQP, "Exiting repeated
instruction", inst); //$NON-NLS-1$
- loop.postInstruction(env);
+ loop.postInstruction(this);
} else {
LogManager.logTrace(LogConstants.CTX_DQP, "Executing instruction",
inst); //$NON-NLS-1$
- inst.process(this.env);
+ inst.process(this);
}
program.incrementProgramCounter();
}
- return this.env.getFinalTupleSource();
+ if(this.isUpdateProcedure){
+ return this.getUpdateCountAsToupleSource();
+ }
+
+ if(lastTupleSource == null){
+ return new NullTupleSource(null);
+ }
+ return lastTupleSource;
}
-
- public TupleSource getResults(TupleSourceID tupleID)
+ private TupleSource getResults()
throws MetaMatrixComponentException, BlockedException,
MetaMatrixProcessingException {
TupleSource results;
@@ -313,35 +345,28 @@
// Ignore
}
}
- if(env.getTempTableStore()!=null) {
- env.getTempTableStore().removeTempTables();
+ if(getTempTableStore()!=null) {
+ getTempTableStore().removeTempTables();
}
+ if (this.evaluator != null) {
+ this.evaluator.close();
+ }
}
public String toString() {
return "ProcedurePlan:\n" +
ProgramUtil.programToString(this.originalProgram); //$NON-NLS-1$
}
- /**
- * The plan is only clonable in the pre-execution stage, not the execution state
- * (things like program state, result sets, etc). It's only safe to call that
- * method in between query processings, inother words, it's only safe to call
- * clone() on a plan after nextTuple() returns null, meaning the plan has
- * finished processing.
- */
public Object clone(){
- ProcedureEnvironment clonedEnv = new ProcedureEnvironment();
- clonedEnv.getProgramStack().push(originalProgram.clone());
- clonedEnv.setUpdateProcedure(this.env.isUpdateProcedure());
- clonedEnv.setOutputElements(this.env.getOutputElements());
- ProcedurePlan plan = new ProcedurePlan(clonedEnv);
+ ProcedurePlan plan = new ProcedurePlan((Program)originalProgram.clone());
+ plan.setUpdateProcedure(this.isUpdateProcedure());
+ plan.setOutputElements(this.getOutputElements());
plan.setParams(params);
plan.setMetadata(metadata);
-
return plan;
}
- protected void addBatchRow(List row) {
+ private void addBatchRow(List row) {
if(this.batchRows == null) {
this.batchRows = new ArrayList(this.batchSize);
}
@@ -395,30 +420,257 @@
this.metadata = metadata;
}
- public void setParams( Map params ) {
+ public void setParams( Map<ElementSymbol, Expression> params ) {
this.params = params;
}
- public void evaluateParams() throws BlockedException, MetaMatrixComponentException,
MetaMatrixProcessingException {
+ private void createVariableContext() {
+ this.currentVarContext = new VariableContext(true);
+ this.currentVarContext.setValue(ROWS_UPDATED, new Integer(NO_ROWS_UPDATED));
+ }
+
+ private TupleSource getUpdateCountAsToupleSource() {
+ Object rowCount = currentVarContext.getValue(ROWS_UPDATED);
+ if(rowCount == null) {
+ rowCount = new Integer(NO_ROWS_UPDATED);
+ }
+
+ final List updateResult = new ArrayList(1);
+ updateResult.add(rowCount);
+
+ return new UpdateCountTupleSource(updateResult);
+ }
+
+ /**
+ * <p> Get the current <code>VariavleContext</code> on this
environment.
+ * The VariableContext is updated with variables and their values by
+ * {@link ProgramInstruction}s that are part of the ProcedurePlan that use
+ * this environment.</p>
+ * @return The current <code>VariariableContext</code>.
+ */
+ public VariableContext getCurrentVariableContext() {
+ return this.currentVarContext;
+ }
+
+ public void executePlan(ProcessorPlan command, String rsName)
+ throws MetaMatrixComponentException, MetaMatrixProcessingException {
+ boolean isExecSQLInstruction = rsName.equals(ExecSqlInstruction.RS_NAME);
+ // Defect 14544: Close all non-final ExecSqlInstruction tuple sources before
creating a new source.
+ // This guarantees that the tuple source will be removed predictably from the
buffer manager.
+ if (isExecSQLInstruction) {
+ removeResults(ExecSqlInstruction.RS_NAME);
+ }
- if ( params == null ) {
- return;
+ TupleSourceID tsID = registerRequest(command, this.currentVarContext);
+ TupleSource source = getResults();
+ tupleSourceIDMap.put(rsName.toUpperCase(), tsID);
+ tupleSourceMap.put(rsName.toUpperCase(), source);
+ if(isExecSQLInstruction){
+ //keep a reference to the tuple source
+ //it may be the last one
+ this.lastTupleSource = source;
}
+ }
+
+ /**
+ * @throws MetaMatrixComponentException
+ * @see com.metamatrix.query.processor.program.ProgramEnvironment#pop()
+ */
+ public void pop() throws MetaMatrixComponentException {
+ this.programs.pop();
+ if (this.currentVarContext.getParentContext() != null) {
+ this.currentVarContext = this.currentVarContext.getParentContext();
+ }
+ Set current = getTempContext();
+
+ Set tempTables = getLocalTempTables();
+
+ tempTables.addAll(current);
- for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry)iter.next();
- ElementSymbol param = (ElementSymbol)entry.getKey();
- Expression expr = (Expression)entry.getValue();
-
- VariableContext context = env.getCurrentVariableContext();
- Object value = new Evaluator(null, null, getContext()).evaluate(expr, null);
+ for (Iterator i = tempTables.iterator(); i.hasNext();) {
+ removeResults((String)i.next());
+ }
+
+ this.tempContext.removeLast();
+ }
+
+ /**
+ * @see
com.metamatrix.query.processor.program.ProgramEnvironment#push(com.metamatrix.query.processor.program.Program)
+ */
+ public void push(Program program) {
+ program.resetProgramCounter();
+ this.programs.push(program);
+ VariableContext context = new VariableContext(true);
+ context.setParentContext(this.currentVarContext);
+ this.currentVarContext = context;
+
+ Set current = getTempContext();
+
+ Set tempTables = getLocalTempTables();
+
+ current.addAll(tempTables);
+ this.tempContext.add(new HashSet());
+ }
+
+ /**
+ * @see
com.metamatrix.query.processor.program.ProgramEnvironment#incrementProgramCounter()
+ */
+ public void incrementProgramCounter() throws MetaMatrixComponentException {
+ Program program = peek();
+ ProgramInstruction instr = program.getCurrentInstruction();
+ if (instr instanceof RepeatedInstruction) {
+ RepeatedInstruction repeated = (RepeatedInstruction)instr;
+ repeated.postInstruction(this);
+ }
+ peek().incrementProgramCounter();
+ }
- //check constraint
- if (value == null && !metadata.elementSupports(param.getMetadataID(),
SupportConstants.Element.NULL)) {
- throw new
QueryValidatorException(QueryExecPlugin.Util.getString("ProcedurePlan.nonNullableParam",
expr)); //$NON-NLS-1$
- }
- context.setValue(param, value);
- }
+ /**
+ * @return
+ */
+ private Set getLocalTempTables() {
+ Set tempTables = this.tempTableStore.getAllTempTables();
+
+ //determine what was created in this scope
+ for (int i = 0; i < tempContext.size() - 1; i++) {
+ tempTables.removeAll((Set)tempContext.get(i));
+ }
+ return tempTables;
+ }
+ public Set getTempContext() {
+ if (this.tempContext.isEmpty()) {
+ tempContext.addLast(new HashSet());
+ }
+ return (Set)this.tempContext.getLast();
}
+
+ public List getCurrentRow(String rsName) {
+ return (List) currentRowMap.get(rsName.toUpperCase());
+ }
+
+ public boolean iterateCursor(String rsName)
+ throws MetaMatrixComponentException, MetaMatrixProcessingException {
+
+ String rsKey = rsName.toUpperCase();
+
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source == null) {
+ // TODO - throw exception?
+ return false;
+ }
+
+ List row = source.nextTuple();
+ currentRowMap.put(rsKey, row);
+ return (row != null);
+ }
+
+ public void removeResults(String rsName) throws MetaMatrixComponentException {
+ String rsKey = rsName.toUpperCase();
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source != null) {
+ source.closeSource();
+ TupleSourceID tsID = (TupleSourceID) tupleSourceIDMap.get(rsKey);
+ try {
+ this.bufferMgr.removeTupleSource(tsID);
+ } catch (TupleSourceNotFoundException e) {
+ throw new MetaMatrixComponentException(e,
ErrorMessageKeys.PROCESSOR_0021,
QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0021, (String)null));
+ } catch (MetaMatrixComponentException e) {
+ throw new MetaMatrixComponentException(e,
ErrorMessageKeys.PROCESSOR_0022,
QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0022, (String) null));
+ }
+ LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"removed tuple
source", tsID, "for result set"}); //$NON-NLS-1$ //$NON-NLS-2$
+ tupleSourceMap.remove(rsKey);
+ tupleSourceIDMap.remove(rsKey);
+ currentRowMap.remove(rsKey);
+ this.tempTableStore.removeTempTableByName(rsKey);
+ }
+ }
+
+
+ /**
+ * Get the schema from the tuple source that
+ * represents the columns in a result set
+ * @param rsName the ResultSet name (not a temp group)
+ * @return List of elements
+ * @throws QueryProcessorException if the list of elements is null
+ */
+ public List getSchema(String rsName) throws MetaMatrixComponentException {
+
+ // get the tuple source
+ String rsKey = rsName.toUpperCase();
+ TupleSource source = (TupleSource) tupleSourceMap.get(rsKey);
+ if(source == null){
+ throw new
MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0037,
rsName));
+ }
+ // get the schema from the tuple source
+ List schema = source.getSchema();
+ if(schema == null){
+ throw new
MetaMatrixComponentException(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0038));
+ }
+
+ return schema;
+ }
+
+ public boolean resultSetExists(String rsName) {
+ String rsKey = rsName.toUpperCase();
+ boolean exists = this.tupleSourceMap.containsKey(rsKey);
+ return exists;
+ }
+
+ public CommandContext getContext() {
+ CommandContext context = super.getContext();
+ if (evaluatedParams) {
+ context.setVariableContext(currentVarContext);
+ }
+ return context;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isUpdateProcedure() {
+ return isUpdateProcedure;
+ }
+
+ /**
+ * @param b
+ */
+ public void setUpdateProcedure(boolean b) {
+ isUpdateProcedure = b;
+ }
+
+ public List getOutputElements() {
+ return outputElements;
+ }
+
+ public void setOutputElements(List outputElements) {
+ this.outputElements = outputElements;
+ }
+
+ /**
+ * @return Returns the tempTableStore.
+ * @since 5.5
+ */
+ public TempTableStore getTempTableStore() {
+ return this.tempTableStore;
+ }
+
+ boolean evaluateCriteria(Criteria condition) throws BlockedException,
MetaMatrixProcessingException, MetaMatrixComponentException {
+ evaluator.setContext(getContext());
+ boolean result = evaluator.evaluate(condition, Collections.emptyList());
+ this.evaluator.close();
+ return result;
+ }
+
+ Object evaluateExpression(Expression expression) throws BlockedException,
MetaMatrixProcessingException, MetaMatrixComponentException {
+ evaluator.setContext(getContext());
+ Object result = evaluator.evaluate(expression, Collections.emptyList());
+ this.evaluator.close();
+ return result;
+ }
+
+ public Program peek() {
+ return programs.peek();
+ }
+
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/RepeatedInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -28,10 +28,10 @@
public interface RepeatedInstruction {
- public boolean testCondition(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException;
+ public boolean testCondition(ProcedurePlan procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException;
public Program getNestedProgram();
- public void postInstruction(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException;
+ public void postInstruction(ProcedurePlan procEnv) throws
MetaMatrixComponentException;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -31,7 +31,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.program.Program;
-import com.metamatrix.query.processor.program.ProgramEnvironment;
import com.metamatrix.query.processor.program.ProgramInstruction;
import com.metamatrix.query.sql.lang.Criteria;
@@ -49,7 +48,7 @@
this.condition = condition;
}
- public void process(ProgramEnvironment env) throws MetaMatrixComponentException {
+ public void process(ProcedurePlan env) throws MetaMatrixComponentException {
//do nothing
}
@@ -88,7 +87,7 @@
* @throws MetaMatrixProcessingException
* @see
com.metamatrix.query.processor.proc.RepeatedInstruction#testCondition(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public boolean testCondition(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
+ public boolean testCondition(ProcedurePlan procEnv) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
return procEnv.evaluateCriteria(condition);
}
@@ -102,7 +101,7 @@
/**
* @see
com.metamatrix.query.processor.proc.RepeatedInstruction#postInstruction(com.metamatrix.query.processor.proc.ProcedureEnvironment)
*/
- public void postInstruction(ProcedureEnvironment procEnv) throws
MetaMatrixComponentException {
+ public void postInstruction(ProcedurePlan procEnv) throws
MetaMatrixComponentException {
}
}
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramEnvironment.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,86 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.program;
-
-import java.util.Stack;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.query.processor.ProcessorPlan;
-
-/**
- * This interface defines the environment that programs run in and what
- * {@link ProgramInstruction}s can access during execution.
- */
-public abstract class ProgramEnvironment {
-
- // Stack of programs, with current program on top
- private Stack programs = new Stack();
-
-
- /**
- * Default constructor
- */
- public ProgramEnvironment() {
- }
-
- /**
- * Connect an XMLPlan to the environment
- * @param plan XMLPlan
- */
- public abstract void initialize(ProcessorPlan plan);
-
- /**
- * Get the Stack of Program objects, with the currently running
- * Program on top.
- * @return Stack of currently running {@link Program Programs},
- * with the current Program on top.
- */
- public Stack getProgramStack() {
- return programs;
- }
-
- public Program peek() {
- return (Program)programs.peek();
- }
-
- public void pop() throws MetaMatrixComponentException {
- this.programs.pop();
- }
-
- public void push(Program program) {
- program.resetProgramCounter();
- this.programs.push(program);
- }
-
- public void incrementProgramCounter() throws MetaMatrixComponentException {
- peek().incrementProgramCounter();
- }
-
- /**
- * Remove the a data source from the environment.
- * @param rsName The name of the result set.
- * @throws MetaMatrixComponentException
- */
- public abstract void removeResults(String rsName)
- throws MetaMatrixComponentException;
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/program/ProgramInstruction.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -29,6 +29,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.query.processor.Describable;
+import com.metamatrix.query.processor.proc.ProcedurePlan;
/**
* <p>Abstract superclass of all program instructions.</p>
@@ -52,7 +53,7 @@
* Program#incrementProgramCounter increment} the program counter of the current
program, but specialized
* instructions may add sub programs to the stack or not increment the counter (so
that they are executed again.)
*/
- public abstract void process(ProgramEnvironment env)
+ public abstract void process(ProcedurePlan env)
throws MetaMatrixComponentException, MetaMatrixProcessingException;
/**
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -38,7 +38,6 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.AbstractSetCriteria;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
@@ -141,12 +140,13 @@
private LinkedList<Integer> restartIndexes = new LinkedList<Integer>();
private int currentIndex;
private boolean hasNextCommand;
-
+ protected SubqueryAwareEvaluator eval;
public DependentCriteriaProcessor(int maxSetSize, RelationalNode dependentNode,
Criteria dependentCriteria) throws ExpressionEvaluationException,
MetaMatrixComponentException {
this.maxSetSize = maxSetSize;
this.dependentNode = dependentNode;
this.dependentCrit = dependentCriteria;
+ this.eval = new SubqueryAwareEvaluator(Collections.emptyMap(),
dependentNode.getDataManager(), dependentNode.getContext(),
dependentNode.getBufferManager());
queryCriteria = Criteria.separateCriteriaByAnd(dependentCrit);
for (int i = 0; i < queryCriteria.size(); i++) {
@@ -162,10 +162,9 @@
}
SetState state = new SetState();
setStates.put(i, state);
- Evaluator evaluator = new Evaluator(Collections.emptyMap(),
dependentNode.getDataManager(), dependentNode.getContext());
LinkedHashSet<Object> values = new LinkedHashSet<Object>();
for (Expression expr :
(Collection<Expression>)setCriteria.getValues()) {
- values.add(evaluator.evaluate(expr, null));
+ values.add(eval.evaluate(expr, null));
}
state.valueIterator = new CollectionValueIterator(values);
sources.add(Arrays.asList(state));
@@ -193,6 +192,9 @@
state.close();
}
}
+ if (this.eval != null) {
+ this.eval.close();
+ }
}
public Criteria prepareCriteria() throws MetaMatrixComponentException {
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -27,7 +27,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.util.VariableContext;
@@ -105,7 +104,7 @@
protected boolean prepareNextCommand(Command atomicCommand) throws
MetaMatrixComponentException, MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this,
(Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null,
getContext()));
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this,
(Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
}
if (criteriaProcessor.prepareNextCommand(this.getContext().getVariableContext()))
{
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -31,7 +31,6 @@
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.rewriter.QueryRewriter;
import com.metamatrix.query.sql.lang.CompareCriteria;
import com.metamatrix.query.sql.lang.Criteria;
@@ -46,15 +45,12 @@
private List inputReferences;
private List inputDefaults;
private Criteria critInProgress;
- private Evaluator eval;
public DependentProcedureCriteriaProcessor(RelationalNode dependentNode,
Criteria dependentCriteria,
List references,
- List defaults,
- Evaluator eval) throws
ExpressionEvaluationException, MetaMatrixComponentException {
+ List defaults) throws
ExpressionEvaluationException, MetaMatrixComponentException {
super(1, dependentNode, dependentCriteria);
- this.eval = eval;
this.inputDefaults = defaults;
this.inputReferences = references;
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureExecutionNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -29,7 +29,6 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.util.CommandContext;
@@ -97,7 +96,7 @@
MetaMatrixComponentException,
MetaMatrixProcessingException {
if (this.criteriaProcessor == null) {
- this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this,
(Criteria)inputCriteria.clone(), inputReferences, inputDefaults, new Evaluator(null, null,
getContext()));
+ this.criteriaProcessor = new DependentProcedureCriteriaProcessor(this,
(Criteria)inputCriteria.clone(), inputReferences, inputDefaults);
}
return
criteriaProcessor.prepareNextCommand(this.getProcessorPlan().getContext().getVariableContext());
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-
-/**
- * A project node containing one or more scalar subqueries.
- * These subqueries must be processed first before the
- * ScalarSubquery expression can be evaluated and the
- * project can proceed.
- */
-public class DependentProjectNode extends ProjectNode {
-
- private SubqueryProcessorUtility subqueryProcessor;
-
- /**
- * @param nodeID
- */
- public DependentProjectNode(int nodeID, SubqueryProcessorUtility spu) {
- super(nodeID);
- this.subqueryProcessor = spu;
- }
-
- public void reset() {
- super.reset();
- this.subqueryProcessor.reset();
- }
-
- /**
- * Calls super.open(), then initializes subquery processor
- */
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
- this.subqueryProcessor.open(this);
- }
-
- /**
- * Closes the subquery processor (which removes the temporary tuple
- * sources of the subquery results)
- * @see com.metamatrix.query.processor.relational.RelationalNode#close()
- */
- public void close()
- throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- this.subqueryProcessor.close(this.getBufferManager());
- }
- }
-
- /**
- * This subclass will execute any subqueries which the projection is
- * dependent on; if any subqueries are correlated, this class will
- * use the current tuple to execute correlated subqueries
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @see com.metamatrix.query.processor.relational.ProjectNode#prepareToProcessTuple
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException,
MetaMatrixProcessingException {
-
- this.subqueryProcessor.process(this, elementMap, currentTuple);
- }
-
- /**
- * Returns a deep clone
- * @return deep clone of this object
- * @see java.lang.Object#clone()
- */
- public Object clone(){
- DependentProjectNode clonedNode = new DependentProjectNode(super.getID(),
this.subqueryProcessor.clone());
- super.copy(this, clonedNode);
- return clonedNode;
- }
-
- public Map getDescriptionProperties() {
- // Default implementation - should be overridden
- Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Dependent Project"); //$NON-NLS-1$
- return props;
- }
-
- /**
- * @see com.metamatrix.query.processor.relational.RelationalNode#getSubPlans()
- * @since 4.2
- */
- public List getChildPlans() {
- return this.subqueryProcessor.getSubqueryPlans();
- }
-
-}
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-
-/**
- * This node represents a Select node for the case where the criteria
- * is or is composed of one or more SubqueryContainer criteria objects (for
- * subqueries in the criteria). In
- * that case, all the corresponding "child" or "sub" ProcessorPlans
- * (one for each SubqueryContainer criteria) must be processed before the
- * entire criteria can be evaluated.
- */
-public class DependentSelectNode extends SelectNode {
-
- private SubqueryProcessorUtility subqueryProcessor;
-
- /**
- * Constructor for DependentSelectNode.
- * @param nodeID
- */
- public DependentSelectNode(int nodeID, SubqueryProcessorUtility
subqueryProcessorUtility) {
- super(nodeID);
- this.subqueryProcessor = subqueryProcessorUtility;
- }
-
- /** for unit testing */
- SubqueryProcessorUtility getSubqueryProcessorUtility(){
- return this.subqueryProcessor;
- }
-
- public void reset() {
- super.reset();
- this.subqueryProcessor.reset();
- }
-
- /**
- * Calls super.open(), then initializes subquery processor
- */
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
- this.subqueryProcessor.open(this);
- }
-
- /**
- * Closes the subquery processor (which removes the temporary tuple
- * sources of the subquery results)
- * @see com.metamatrix.query.processor.relational.RelationalNode#close()
- */
- public void close()
- throws MetaMatrixComponentException {
- if (!isClosed()) {
- super.close();
- this.subqueryProcessor.close(this.getBufferManager());
- }
- }
-
- /**
- * This subclass will execute any subqueries which the criteria is
- * dependent on; if any subqueries are correlated, this class will
- * use the current tuple to execute correlated subqueries
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @see com.metamatrix.query.processor.relational.SelectNode#prepareToProcessTuple
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
-
- this.subqueryProcessor.process(this, elementMap, currentTuple);
- }
-
- /**
- * Returns a deep clone
- * @return deep clone of this object
- * @see java.lang.Object#clone()
- */
- public Object clone(){
- DependentSelectNode clonedNode = new DependentSelectNode(super.getID(),
subqueryProcessor.clone());
- super.copy(this, clonedNode);
- return clonedNode;
- }
-
- /*
- * @see com.metamatrix.query.processor.Describable#getDescriptionProperties()
- */
- public Map getDescriptionProperties() {
- // Default implementation - should be overridden
- Map props = super.getDescriptionProperties();
- props.put(PROP_TYPE, "Dependent Select"); //$NON-NLS-1$
- props.put(PROP_CRITERIA, getCriteria().toString());
- return props;
- }
-
- /**
- * @see com.metamatrix.query.processor.relational.RelationalNode#getSubPlans()
- * @since 4.2
- */
- public List getChildPlans() {
- return this.subqueryProcessor.getSubqueryPlans();
- }
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -23,6 +23,9 @@
package com.metamatrix.query.processor.relational;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -30,17 +33,20 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleSourceID;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.util.CommandContext;
/**
* @since 4.2
*/
-public class JoinNode extends RelationalNode {
+public class JoinNode extends SubqueryAwareRelationalNode {
private enum State { LOAD_LEFT, LOAD_RIGHT, EXECUTE }
private State state = State.LOAD_LEFT;
@@ -52,12 +58,10 @@
private JoinType joinType;
private String dependentValueSource;
- // Set up state - need to be cloned but not reset
private List leftExpressions;
private List rightExpressions;
private Criteria joinCriteria;
- // Cached state - do not need to be cloned or reset
private Map combinedElementMap;
public JoinNode(int nodeID) {
@@ -94,7 +98,18 @@
this.leftOpened = false;
this.rightOpened = false;
}
-
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+
+ // Create element lookup map for evaluating project expressions
+ List combinedElements = new ArrayList(getChildren()[0].getElements());
+ combinedElements.addAll(getChildren()[1].getElements());
+ this.combinedElementMap = createLookupMap(combinedElements);
+ }
+
public void open()
throws MetaMatrixComponentException, MetaMatrixProcessingException {
@@ -110,10 +125,6 @@
this.rightOpened = true;
}
- // Create element lookup map for evaluating project expressions
- List combinedElements = new ArrayList(getChildren()[0].getElements());
- combinedElements.addAll(getChildren()[1].getElements());
- this.combinedElementMap = createLookupMap(combinedElements);
this.state = State.LOAD_LEFT;
// Set Up Join Strategy
this.joinStrategy.initialize(this);
@@ -274,7 +285,7 @@
}
boolean matchesCriteria(List outputTuple) throws BlockedException,
MetaMatrixComponentException, CriteriaEvaluationException {
- return (this.joinCriteria == null || new Evaluator(this.combinedElementMap,
this.getDataManager(), this.getContext()).evaluate(this.joinCriteria, outputTuple));
+ return (this.joinCriteria == null ||
getEvaluator(this.combinedElementMap).evaluate(this.joinCriteria, outputTuple));
}
public List getLeftExpressions() {
@@ -284,5 +295,13 @@
public List getRightExpressions() {
return this.rightExpressions;
}
+
+ @Override
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ if (this.joinCriteria == null) {
+ return Collections.emptyList();
+ }
+ return Arrays.asList(this.joinCriteria);
+ }
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,19 +33,22 @@
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.AliasSymbol;
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.SelectSymbol;
+import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
-public class ProjectNode extends RelationalNode {
+public class ProjectNode extends SubqueryAwareRelationalNode {
private List selectSymbols;
@@ -55,7 +59,6 @@
// Saved state when blocked on evaluating a row - must be reset
private TupleBatch currentBatch;
private int currentRow;
- private boolean blockedOnPrepare = false;
public ProjectNode(int nodeID) {
super(nodeID);
@@ -63,13 +66,10 @@
public void reset() {
super.reset();
-
- elementMap = null;
needsProject = true;
currentBatch = null;
currentRow = 0;
- blockedOnPrepare = false;
}
/**
@@ -83,13 +83,12 @@
public void setSelectSymbols(List symbols) {
this.selectSymbols = symbols;
}
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- // Open the child source
- super.open();
-
// Do this lazily as the node may be reset and re-used and this info doesn't
change
if(elementMap == null) {
//in the case of select with no from, there is no child node
@@ -143,7 +142,7 @@
}
}
}
-
+
public TupleBatch nextBatchDirect()
throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
@@ -156,12 +155,6 @@
TupleBatch batch = this.currentBatch;
int beginRow = this.currentRow;
- // Call "prepareToProcessTuple" if there is no temporary batch state
- // (indicating this is the first call to get a next batch) or
- // if the blockedOnPrepare variable indicates that
- // "prepareToProcessTuple" threw the BlockedException
- boolean doPrepareToProcessTuple = (this.currentBatch == null ||
this.blockedOnPrepare);
-
if(batch == null) {
// There was no saved batch, so get a new one
//in the case of select with no from, should return only
@@ -186,25 +179,11 @@
// There was a saved batch, but we grabbed the state so it can now be
removed
this.currentBatch = null;
this.currentRow = 0;
- this.blockedOnPrepare = false;
}
for(int row = beginRow; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
- if (doPrepareToProcessTuple){
- try {
- // Hook for subclasses
- this.prepareToProcessTuple(this.elementMap, tuple);
- } catch(BlockedException e) {
- // Expression blocked, so save state and rethrow
- this.blockedOnPrepare = true;
- this.currentBatch = batch;
- this.currentRow = row;
- throw e;
- }
- }
-
List projectedTuple = new ArrayList(selectSymbols.size());
// Walk through symbols
@@ -232,23 +211,6 @@
return pullBatch();
}
- /**
- * This method is called by {@link #nextBatch} just after the current
- * tuple is pulled from the child processor node and just before any
- * processing is done (in this case, before the tuple is projected).
- * This gives subclasses a chance to do any custom processing - for example,
- * to examine the current tuple in order to execute correlated subqueries.
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @throws MetaMatrixProcessingException for exception due to user input or modeling
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException
{
- //Nothing done here
- }
-
private void updateTuple(SelectSymbol symbol, List values, List tuple)
throws BlockedException, MetaMatrixComponentException, ExpressionEvaluationException {
@@ -268,7 +230,7 @@
tuple.add(values.get(index.intValue()));
} else if(symbol instanceof ExpressionSymbol) {
Expression expression = ((ExpressionSymbol)symbol).getExpression();
- tuple.add(new Evaluator(elementMap, getDataManager(),
getContext()).evaluate(expression, values));
+ tuple.add(getEvaluator(this.elementMap).evaluate(expression, values));
} else {
Assertion.failed(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0034,
symbol.getClass().getName()));
}
@@ -305,5 +267,10 @@
return props;
}
-
+
+ @Override
+ public Collection<LanguageObject> getLanguageObjects() {
+ return this.getSelectSymbols();
+ }
+
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -23,9 +23,11 @@
package com.metamatrix.query.processor.relational;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -40,8 +42,12 @@
import com.metamatrix.query.processor.Describable;
import com.metamatrix.query.processor.DescribableUtil;
import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -483,9 +489,27 @@
* @since 4.2
*/
public List getChildPlans() {
- return null;
+ Collection<? extends LanguageObject> objs = getLanguageObjects();
+ if (objs == null || objs.isEmpty()) {
+ return null;
+ }
+ Collection<SubqueryContainer> containers =
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(objs);
+ if (containers.isEmpty()) {
+ return null;
+ }
+ List<ProcessorPlan> plans = new LinkedList<ProcessorPlan>();
+ for (SubqueryContainer container : containers) {
+ if (container.getCommand().getProcessorPlan() != null) {
+ plans.add(container.getCommand().getProcessorPlan());
+ }
+ }
+ return plans;
}
-
+
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ return null;
+ }
+
/*
* @see com.metamatrix.query.processor.Describable#getDescriptionProperties()
*/
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -22,17 +22,22 @@
package com.metamatrix.query.processor.relational;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.util.CommandContext;
-public class SelectNode extends RelationalNode {
+public class SelectNode extends SubqueryAwareRelationalNode {
private Criteria criteria;
@@ -44,7 +49,6 @@
private boolean blockedOnPrepare = false;
private TupleBatch blockedBatch = null;
private int blockedRow = 0;
- private Evaluator evaluator;
public SelectNode(int nodeID) {
super(nodeID);
@@ -57,7 +61,6 @@
blockedOnPrepare = false;
blockedBatch = null;
blockedRow = 0;
- evaluator = null;
}
public void setCriteria(Criteria criteria) {
@@ -68,18 +71,16 @@
return this.criteria;
}
- public void open()
- throws MetaMatrixComponentException, MetaMatrixProcessingException {
-
- super.open();
-
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
// Create element lookup map for evaluating project expressions
if(this.elementMap == null) {
this.elementMap = createLookupMap(this.getChildren()[0].getElements());
}
- this.evaluator = new Evaluator(elementMap, getDataManager(), getContext());
}
-
+
/**
* @see com.metamatrix.query.processor.relational.RelationalNode#nextBatchDirect()
*/
@@ -91,7 +92,6 @@
batch = this.getChildren()[0].nextBatch();
}
- boolean doPrepareToProcessTuple = !blockedOnCriteria;
int row = blockedRow;
if(! blockedOnCriteria && ! blockedOnPrepare) {
row = batch.getBeginRow();
@@ -106,22 +106,9 @@
for(; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
- if (doPrepareToProcessTuple){
- try {
- // Hook for subclasses
- this.prepareToProcessTuple(this.elementMap, tuple);
- } catch(BlockedException e) {
- // Save state and rethrow
- blockedOnPrepare = true;
- blockedBatch = batch;
- blockedRow = row;
- throw e;
- }
- }
-
// Evaluate criteria with tuple
try {
- if(evaluator.evaluate(this.criteria, tuple)) {
+ if(getEvaluator(this.elementMap).evaluate(this.criteria, tuple)) {
addBatchRow( projectTuple(elementMap, tuple, getElements()) );
}
} catch(BlockedException e) {
@@ -140,23 +127,6 @@
return pullBatch();
}
- /**
- * This method is called by {@link #nextBatch} just after the current
- * tuple is pulled from the child processor node and just before any
- * processing is done (in this case, before the criteria is evaluated).
- * This gives subclasses a chance to do any custom processing - for example,
- * to examine the current tuple in order to execute correlated subqueries.
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple the current tuple about to be processed by
- * this node
- * @throws MetaMatrixProcessingException for exception due to user input
- */
- protected void prepareToProcessTuple(Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException
{
- //Nothing done here
- }
-
protected void getNodeString(StringBuffer str) {
super.getNodeString(str);
str.append(criteria);
@@ -185,4 +155,9 @@
return props;
}
+ @Override
+ public Collection<? extends LanguageObject> getLanguageObjects() {
+ return Arrays.asList(this.criteria);
+ }
+
}
Copied:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
(from rev 837,
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java)
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
(rev 0)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -0,0 +1,141 @@
+/*
+ * 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.query.processor.relational;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.core.MetaMatrixCoreException;
+import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.processor.QueryProcessor;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
+import com.metamatrix.query.sql.symbol.ContextReference;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.util.ValueIterator;
+import com.metamatrix.query.sql.util.VariableContext;
+import com.metamatrix.query.util.CommandContext;
+
+/**
+ * <p>This utility handles the work of processing a subquery; certain types
+ * of processor nodes will use an instance of this class to do that work.
+ */
+public class SubqueryAwareEvaluator extends Evaluator {
+
+ public class SubqueryState {
+ QueryProcessor processor;
+ boolean done;
+ List<?> tuple;
+ ProcessorPlan plan;
+
+ void close() throws MetaMatrixComponentException {
+ if (processor == null) {
+ return;
+ }
+ try {
+ processor.closeProcessing();
+ TupleSourceID id = processor.getResultsID();
+ manager.removeTupleSource(id);
+ } catch (TupleSourceNotFoundException e) {
+
+ }
+ processor = null;
+ this.done = false;
+ }
+ }
+
+ //environment
+ private BufferManager manager;
+
+ //processing state
+ private Map<String, SubqueryState> subqueries = new HashMap<String,
SubqueryState>();
+
+ public SubqueryAwareEvaluator(Map elements, ProcessorDataManager dataMgr,
+ CommandContext context, BufferManager manager) {
+ super(elements, dataMgr, context);
+ this.manager = manager;
+ }
+
+ public void reset() {
+ for (SubqueryState subQueryState : subqueries.values()) {
+ subQueryState.plan.reset();
+ }
+ }
+
+ public void close() throws MetaMatrixComponentException {
+ for (SubqueryState state : subqueries.values()) {
+ state.close();
+ }
+ }
+
+ @Override
+ protected ValueIterator evaluateSubquery(SubqueryContainer container,
+ List tuple) throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
+ ContextReference ref = (ContextReference)container;
+ String key = (ref).getContextSymbol();
+ SubqueryState state = this.subqueries.get(key);
+ if (state == null) {
+ state = new SubqueryState();
+ state.plan = (ProcessorPlan)container.getCommand().getProcessorPlan().clone();
+ this.subqueries.put(key, state);
+ }
+ if ((tuple == null && state.tuple != null) || (tuple != null &&
!tuple.equals(state.tuple))) {
+ if (container.getCommand().getCorrelatedReferences() != null) {
+ state.close();
+ }
+ state.tuple = tuple;
+ }
+ if (!state.done) {
+ if (state.processor == null) {
+ CommandContext subContext = (CommandContext) context.clone();
+ state.processor = new QueryProcessor(state.plan, subContext, manager,
this.dataMgr);
+ if (container.getCommand().getCorrelatedReferences() != null) {
+ VariableContext currentContext = new VariableContext();
+ for (Map.Entry<ElementSymbol, Expression> entry :
container.getCommand().getCorrelatedReferences().asMap().entrySet()) {
+ currentContext.setValue(entry.getKey(), evaluate(entry.getValue(), tuple));
+ }
+ state.processor.getContext().pushVariableContext(currentContext);
+ }
+ }
+ try {
+ state.processor.process(Integer.MAX_VALUE);
+ } catch (MetaMatrixCoreException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ state.done = true;
+ state.processor.getProcessorPlan().reset();
+ }
+ return new DependentValueSource(state.processor.getResultsID(),
this.manager).getValueIterator(ref.getValueExpression());
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareEvaluator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
(rev 0)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -0,0 +1,41 @@
+package com.metamatrix.query.processor.relational;
+
+import java.util.Map;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.query.eval.Evaluator;
+
+public abstract class SubqueryAwareRelationalNode extends RelationalNode {
+
+ private SubqueryAwareEvaluator evaluator;
+
+ public SubqueryAwareRelationalNode(int nodeID) {
+ super(nodeID);
+ }
+
+ protected Evaluator getEvaluator(Map elementMap) {
+ if (this.evaluator == null) {
+ this.evaluator = new SubqueryAwareEvaluator(elementMap, getDataManager(),
getContext(), getBufferManager());
+ } else {
+ this.evaluator.setContext(getContext());
+ }
+ return this.evaluator;
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ if (evaluator != null) {
+ evaluator.reset();
+ }
+ }
+
+ @Override
+ public void close() throws MetaMatrixComponentException {
+ super.close();
+ if (evaluator != null) {
+ evaluator.close();
+ }
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryAwareRelationalNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,211 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleSourceID;
-import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * <p>This utility handles the work of processing a subquery; certain types
- * of processor nodes will use an instance of this class to do that work.
- */
-public class SubqueryProcessorUtility {
-
- private List<? extends ProcessorPlan> processorPlans;
- private List<String> contextReferences;
- private SymbolMap correlatedReferences;
-
- private List<QueryProcessor> processors = new ArrayList<QueryProcessor>();
-
- // "Placeholder" state, for resuming processing after
- // a BlockedException - not cloned
- private int currentIndex = 0;
- private QueryProcessor currentProcessor;
-
- // List <TupleSourceID> - same index-matchup as other two Lists
- // Need to clean up on close()
- private List<TupleSourceID> tupleSources = new ArrayList<TupleSourceID>();
-
- private VariableContext currentContext;
-
- public SubqueryProcessorUtility(List<? extends ProcessorPlan> valList,
List<String> contextReferences, SymbolMap references) {
- this.processorPlans = valList;
- this.contextReferences = contextReferences;
- if (references != null && !references.asMap().isEmpty()) {
- this.correlatedReferences = references;
- }
- }
-
- public SubqueryProcessorUtility clone() {
- List<ProcessorPlan> plans = new
ArrayList<ProcessorPlan>(processorPlans.size());
- for (ProcessorPlan processorPlan : processorPlans) {
- plans.add((ProcessorPlan)processorPlan.clone());
- }
- return new SubqueryProcessorUtility(plans, contextReferences, correlatedReferences);
- }
-
- List<? extends ProcessorPlan> getSubqueryPlans(){
- return this.processorPlans;
- }
-
- void reset() {
- this.currentIndex = 0;
- currentProcessor = null;
- // Reset internal plans
- for(int i=0; i<processorPlans.size(); i++) {
- ProcessorPlan plan = processorPlans.get(i);
- plan.reset();
- }
- }
-
- /**
- * initializes each subquery ProcessorPlan
- * @throws MetaMatrixComponentException
- */
- void open(RelationalNode parent) throws MetaMatrixComponentException {
- // Open subquery processor plans
- for (ProcessorPlan plan : this.processorPlans) {
- CommandContext subContext = (CommandContext) parent.getContext().clone();
- QueryProcessor processor = new QueryProcessor(plan, subContext,
parent.getBufferManager(), parent.getDataManager());
- this.processors.add(processor);
- this.tupleSources.add(processor.getResultsID());
- }
- }
-
- /**
- * Removes the temporary tuple sources of the subquery results
- */
- void close(BufferManager bufferManager)
- throws MetaMatrixComponentException {
-
- for (QueryProcessor processor : this.processors) {
- try {
- processor.closeProcessing();
- } catch (TupleSourceNotFoundException e) {
- }
- }
- this.processors.clear();
-
- for (TupleSourceID tsID : this.tupleSources) {
- try {
- bufferManager.removeTupleSource(tsID);
- } catch (TupleSourceNotFoundException e) {
- //ignore
- }
- }
-
- this.tupleSources.clear();
- }
-
- /**
- * <p>Processes processor plans (each key), stores as TupleSource Iterators in
- * each ValueIteratorProvider (each value). Continues synchronously until
- * all processing is completed or until a BlockedException is thrown. This
- * method can be called after a BlockedException and will resume processing
- * where it left off.</p>
- *
- * <p>After this method completes (including after multiple method calls
- * that resulted in a BlockedException), if this method is called again,
- * it will start processing over ONLY IF this instance has any correlated subquery
- * references. The assumption is that it will not be called again until
- * a new outer currentTuple is being passed in.</p>
- *
- * @param elementMap Map of ElementSymbol elements to Integer indices into
- * the currentTuple parameter
- * @param currentTuple current tuple of the containing query
- * @param bufferManager BufferManager
- * @param groupName String group name of client processor node
- * @throws BlockedException potentially at any time during processing
- * @throws MetaMatrixComponentException for unexpected exception
- * @throws MetaMatrixProcessingException for exception due to user input or modeling
- */
- void process(RelationalNode parent, Map elementMap, List currentTuple)
- throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
-
- // This IF block is only intended to be run when the outer query tuple has
changed,
- // so it should not be run when this instance is resuming processing after a
BlockedException
- if (this.currentContext == null && this.currentProcessor == null
&& this.correlatedReferences != null){
- // Close old tuple sources
- this.close(parent.getBufferManager());
- this.open(parent);
- this.currentContext = new VariableContext();
- for (Map.Entry<ElementSymbol, Expression> entry :
this.correlatedReferences.asMap().entrySet()) {
- this.currentContext.setValue(entry.getKey(), new Evaluator(elementMap,
parent.getDataManager(), parent.getContext()).evaluate(entry.getValue(), currentTuple));
- }
- }
-
- while (this.currentProcessor != null || this.currentIndex <
this.processorPlans.size()){
- //Initialize current ProcessorPlan tuple source, if necessary
- if (this.currentProcessor == null){
- this.currentProcessor = this.processors.get(currentIndex);
- if (this.currentContext != null) {
- this.currentProcessor.getContext().pushVariableContext(this.currentContext);
- }
- }
-
- // Process the results
- try {
- this.currentProcessor.process(Integer.MAX_VALUE);
- this.currentProcessor.getProcessorPlan().reset();
- } catch (MetaMatrixProcessingException e) {
- throw e;
- } catch (MetaMatrixComponentException e) {
- throw e;
- } catch (MetaMatrixCoreException e) {
- throw new MetaMatrixComponentException(e);
- }
-
- // Set the results on the ValueIteratorProviders
- parent.getContext().getVariableContext().setGlobalValue(this.contextReferences.get(this.currentIndex),
new DependentValueSource(this.currentProcessor.getResultsID(),
parent.getBufferManager()));
-
- this.currentProcessor = null;
- this.currentIndex++;
- }
-
- if (this.correlatedReferences != null){
- // If correlated references are present, re-zero currentIndex -
- // If we've made it this far, then the next time
- // this method is called, it should be for a new outer tuple
- currentIndex = 0;
- }
- this.currentContext = null;
- }
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -56,6 +56,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.DynamicCommand;
import com.metamatrix.query.sql.lang.GroupContext;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
import com.metamatrix.query.sql.proc.CommandStatement;
@@ -70,6 +71,7 @@
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
import com.metamatrix.query.util.LogConstants;
@@ -195,6 +197,9 @@
case Statement.TYPE_IF:
IfStatement ifStmt = (IfStatement) statement;
Criteria ifCrit = ifStmt.getCondition();
+ for (SubqueryContainer container :
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ifCrit)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(),
expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(ifCrit, null, externalGroups,
metadata);
resolveBlock(command, ifStmt.getIfBlock(), externalGroups, metadata,
expandCommand, isUpdateProcedure, analysis);
if(ifStmt.hasElseBlock()) {
@@ -249,6 +254,9 @@
resolveEmbeddedCommand(metadata, externalGroups, cmd, expandCommand, analysis);
} else if (assStmt.hasExpression()) {
Expression expr = assStmt.getExpression();
+ for (SubqueryContainer container :
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
+ resolveEmbeddedCommand(metadata, externalGroups,
container.getCommand(), expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(expr, null, externalGroups,
metadata);
}
}
@@ -282,6 +290,9 @@
case Statement.TYPE_WHILE:
WhileStatement whileStmt = (WhileStatement) statement;
Criteria whileCrit = whileStmt.getCondition();
+ for (SubqueryContainer container :
ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(whileCrit)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(),
expandCommand, analysis);
+ }
ResolverVisitor.resolveLanguageObject(whileCrit, null, externalGroups,
metadata);
resolveBlock(command, whileStmt.getBlock(), externalGroups, metadata,
expandCommand, isUpdateProcedure, analysis);
break;
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/AccessPattern.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -27,49 +27,51 @@
import java.util.LinkedList;
import java.util.Set;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+
/**
* This class represents both virtual and physical access patterns.
*
- * If a virtual access pattern is initially unstatisfied, it may be
+ * If a virtual access pattern is initially unsatisfied, it may be
* transformed by RuleMergeVirtual. In this case, the history of the
* access pattern will contain its previous definitions.
*/
-public class AccessPattern implements Comparable, Cloneable {
+public class AccessPattern implements Comparable<AccessPattern>, Cloneable {
- private Set unsatisfied = new HashSet();
- private LinkedList history = new LinkedList();
+ private Set<ElementSymbol> unsatisfied = new HashSet<ElementSymbol>();
+ private LinkedList<Collection<ElementSymbol>> history = new
LinkedList<Collection<ElementSymbol>>();
- public AccessPattern(Collection elements) {
+ public AccessPattern(Collection<ElementSymbol> elements) {
unsatisfied.addAll(elements);
history.add(elements);
}
- public Collection getCurrentElements() {
- return (Collection)history.getFirst();
+ public Collection<ElementSymbol> getCurrentElements() {
+ return history.getFirst();
}
- public void addElementHistory(Collection elements) {
+ public void addElementHistory(Collection<ElementSymbol> elements) {
this.history.addFirst(elements);
}
/**
* @return Returns the history.
*/
- public LinkedList getHistory() {
+ public LinkedList<Collection<ElementSymbol>> getHistory() {
return this.history;
}
/**
- * @return Returns the unstaisfied.
+ * @return Returns the unsatisfied.
*/
- public Set getUnsatisfied() {
+ public Set<ElementSymbol> getUnsatisfied() {
return this.unsatisfied;
}
/**
- * @param unstaisfied The unstaisfied to set.
+ * @param unstaisfied The unsatisfied to set.
*/
- public void setUnsatisfied(Set unstaisfied) {
+ public void setUnsatisfied(Set<ElementSymbol> unstaisfied) {
this.unsatisfied = unstaisfied;
}
@@ -84,13 +86,9 @@
sb.append(history);
return sb.toString();
}
-
- /**
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object o) {
- AccessPattern other = (AccessPattern)o;
-
+
+ @Override
+ public int compareTo(AccessPattern other) {
if (this.unsatisfied.size() > other.unsatisfied.size()){
return 1;
} else if (this.unsatisfied.size() < other.unsatisfied.size()){
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -22,7 +22,14 @@
package com.metamatrix.query.sql.lang;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.types.DataTypeManager;
@@ -32,6 +39,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
@@ -126,12 +134,26 @@
private Option option;
private ProcessorPlan plan;
+
+ private SymbolMap correlatedReferences;
/**
* Return type of command to make it easier to build switch statements by command type.
* @return Type from TYPE constants
*/
public abstract int getType();
+
+ /**
+ * Get the correlated references to the containing scope only
+ * @return
+ */
+ public SymbolMap getCorrelatedReferences() {
+ return correlatedReferences;
+ }
+
+ public void setCorrelatedReferences(SymbolMap correlatedReferences) {
+ this.correlatedReferences = correlatedReferences;
+ }
/**
* Gets the subCommands (both embedded and non-embedded) under this command. In
general the returned list
@@ -222,6 +244,9 @@
copy.setIsResolved(this.isResolved());
copy.plan = this.plan;
+ if (this.correlatedReferences != null) {
+ copy.correlatedReferences = this.correlatedReferences.clone();
+ }
}
/**
@@ -323,12 +348,10 @@
return getSubCommandsUpdatingModelCount(this, metadata);
}
- public static int getSubCommandsUpdatingModelCount(LanguageObject object,
QueryMetadataInterface metadata) throws MetaMatrixComponentException {
- List subCommands = CommandCollectorVisitor.getCommands(object);
+ public static int getSubCommandsUpdatingModelCount(Command object,
QueryMetadataInterface metadata) throws MetaMatrixComponentException {
+ List<Command> subCommands = CommandCollectorVisitor.getCommands(object);
int numCommands = subCommands.size();
- Iterator iter = subCommands.iterator();
- while(iter.hasNext()) {
- Command command = (Command)iter.next();
+ for (Command command : subCommands) {
if (numCommands == 1) {
return command.updatingModelCount(metadata);
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/CreateUpdateProcedureCommand.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -292,16 +291,25 @@
}
public int updatingModelCount(QueryMetadataInterface metadata) throws
MetaMatrixComponentException {
- for (final Iterator iterator = block.getStatements().iterator();
iterator.hasNext();) {
- final Statement statement = (Statement)iterator.next();
- int count = Command.getSubCommandsUpdatingModelCount(statement, metadata);
- if (!iterator.hasNext() && statement instanceof CommandStatement) {
- return count;
+ List<Command> subCommands = getSubCommands();
+ if (subCommands.isEmpty()) {
+ return 0;
+ }
+ Command lastCommand = null;
+ Statement statement =
(Statement)block.getStatements().get(block.getStatements().size() - 1);
+ if (statement instanceof CommandStatement) {
+ CommandStatement cmdStatement = (CommandStatement)statement;
+ lastCommand = cmdStatement.getCommand();
+ }
+ for (Command command : subCommands) {
+ int count = command.updatingModelCount(metadata);
+ if (command == lastCommand) {
+ return count;
}
if (count > 0) {
return 2;
}
- }
+ }
return 0;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -47,18 +47,14 @@
public SymbolMap() {
}
- public SymbolMap(SymbolMap other) {
- //todo clone;
- this.map.putAll(other.map);
+ public SymbolMap clone() {
+ SymbolMap clonedMap = new SymbolMap();
+ for (Map.Entry<ElementSymbol, Expression> entry : map.entrySet()) {
+ clonedMap.addMapping((ElementSymbol)entry.getKey().clone(),
(Expression)entry.getValue().clone());
+ }
+ return clonedMap;
}
- public SymbolMap merge(SymbolMap other) {
- if (other != null) {
- this.map.putAll(other.map);
- }
- return this;
- }
-
/**
* @return true if the map did not already contained the given symbol
*/
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -172,4 +172,9 @@
return this.variableMap.remove(symbol);
}
+ @Override
+ public String toString() {
+ return this.variableMap.toString();
+ }
+
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -33,7 +33,6 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.SetQuery;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
import com.metamatrix.query.sql.lang.SubqueryFromClause;
@@ -42,7 +41,6 @@
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.DeclareStatement;
import com.metamatrix.query.sql.proc.LoopStatement;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
@@ -186,15 +184,15 @@
* @param obj Language object
* @param elements Collection to collect commands in
*/
- public static final List<Command> getCommands(LanguageObject obj) {
+ public static final List<Command> getCommands(Command obj) {
return getCommands(obj, true, true);
}
- public static final List<Command> getCommands(LanguageObject obj, boolean
embeddedOnly) {
+ public static final List<Command> getCommands(Command obj, boolean
embeddedOnly) {
return getCommands(obj, true, !embeddedOnly);
}
- private static final List<Command> getCommands(LanguageObject obj, boolean
embedded, boolean nonEmbedded) {
+ private static final List<Command> getCommands(Command command, boolean
embedded, boolean nonEmbedded) {
HashSet<Mode> modes = new HashSet<Mode>();
if (embedded) {
modes.add(Mode.EMBEDDED);
@@ -203,39 +201,23 @@
modes.add(Mode.NON_EMBEDDED);
}
CommandCollectorVisitor visitor = new CommandCollectorVisitor(modes);
-
- //we need a special navigator here to prevent subcommands in statements from
being picked up
- //by the wrong parent
+ final boolean visitCommands = command instanceof SetQuery;
PreOrderNavigator navigator = new PreOrderNavigator(visitor) {
- public void visit(LoopStatement obj) {
- preVisitVisitor(obj);
- visitNode(obj.getBlock());
- }
-
- public void visit(CommandStatement obj) {
- preVisitVisitor(obj);
- }
-
- public void visit(AssignmentStatement obj) {
- preVisitVisitor(obj);
- if (obj.hasExpression()) {
- visitNode(obj.getExpression());
- }
- }
- public void visit(DeclareStatement obj) {
- preVisitVisitor(obj);
- if (obj.hasExpression()) {
- visitNode(obj.getExpression());
- }
- }
-
+ @Override
+ protected void visitNode(LanguageObject obj) {
+ if (!visitCommands && obj instanceof Command) {
+ return;
+ }
+ super.visitNode(obj);
+ }
+
};
- obj.acceptVisitor(navigator);
+ command.acceptVisitor(navigator);
return visitor.getCommands();
}
- public static final List<Command> getNonEmbeddedCommands(LanguageObject obj) {
+ public static final List<Command> getNonEmbeddedCommands(Command obj) {
return getCommands(obj, false, true);
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CorrelatedReferenceCollectorVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -35,21 +35,21 @@
* correspond to correlated subquery references.</p>
*
* <p>The easiest way to use this visitor is to call the static method which
creates the
- * the visitor by passing it the Langiuage Object and the variable context to be looked
up.
+ * the visitor by passing it the Language Object and the variable context to be looked
up.
* The public visit() methods should NOT be called directly.</p>
*/
public class CorrelatedReferenceCollectorVisitor extends LanguageVisitor {
// index of the reference on the language object
- private Collection groupSymbols;
- private List references;
+ private Collection<GroupSymbol> groupSymbols;
+ private List<Reference> references;
- public CorrelatedReferenceCollectorVisitor(Collection groupSymbols, List
correlatedReferences) {
+ public CorrelatedReferenceCollectorVisitor(Collection<GroupSymbol>
groupSymbols, List<Reference> correlatedReferences) {
this.groupSymbols = groupSymbols;
this.references = correlatedReferences;
}
- public List getReferences(){
+ public List<Reference> getReferences(){
return this.references;
}
@@ -61,14 +61,14 @@
* @param obj Language object
*/
public void visit(Reference obj) {
- Expression expr = obj.getExpression();
- if (expr instanceof ElementSymbol){
- ElementSymbol e = (ElementSymbol)expr;
- GroupSymbol g = e.getGroupSymbol();
- if (this.groupSymbols.contains(g) && e.isExternalReference()){
- this.references.add(obj);
- }
+ ElementSymbol e = obj.getExpression();
+ if (e == null) {
+ return;
}
+ GroupSymbol g = e.getGroupSymbol();
+ if (this.groupSymbols.contains(g) && e.isExternalReference()){
+ this.references.add(obj);
+ }
}
/**
@@ -78,7 +78,7 @@
* that the client (outer query) is interested in references to from the correlated
subquery
* @param correlatedReferences List of References collected
*/
- public static final void collectReferences(LanguageObject obj, Collection
groupSymbols, List correlatedReferences){
+ public static final void collectReferences(LanguageObject obj,
Collection<GroupSymbol> groupSymbols, List<Reference> correlatedReferences){
CorrelatedReferenceCollectorVisitor visitor =
new CorrelatedReferenceCollectorVisitor(groupSymbols, correlatedReferences);
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -29,7 +29,7 @@
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.eval.LookupEvaluator;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.navigator.DeepPostOrderNavigator;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
@@ -51,7 +51,7 @@
public class EvaluateExpressionVisitor extends ExpressionMappingVisitor {
private CommandContext context;
- private LookupEvaluator dataMgr;
+ private ProcessorDataManager dataMgr;
EvaluateExpressionVisitor() {
super(null);
@@ -106,7 +106,7 @@
return EvaluatableVisitor.isEvaluatable(obj,
duringPlanning?EvaluationLevel.PLANNING:EvaluationLevel.PROCESSING);
}
- public static final void replaceExpressions(LanguageObject obj, boolean deep,
LookupEvaluator dataMgr, CommandContext context)
+ public static final void replaceExpressions(LanguageObject obj, boolean deep,
ProcessorDataManager dataMgr, CommandContext context)
throws ExpressionEvaluationException, MetaMatrixComponentException {
EvaluateExpressionVisitor visitor = new EvaluateExpressionVisitor();
visitor.setContext(context);
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ValueIteratorProviderCollectorVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -24,7 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -32,6 +32,7 @@
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.lang.ExistsCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
@@ -49,14 +50,14 @@
*/
public class ValueIteratorProviderCollectorVisitor extends LanguageVisitor {
- private List valueIteratorProviders;
+ private List<SubqueryContainer> valueIteratorProviders;
/**
* Construct a new visitor with the default collection type, which is a
* {@link java.util.ArrayList}.
*/
public ValueIteratorProviderCollectorVisitor() {
- this.valueIteratorProviders = new ArrayList();
+ this.valueIteratorProviders = new ArrayList<SubqueryContainer>();
}
/**
@@ -64,7 +65,7 @@
* ValueIteratorProvider instances
* @param valueIteratorProviders Collection to accumulate found
*/
- ValueIteratorProviderCollectorVisitor(List valueIteratorProviders) {
+ ValueIteratorProviderCollectorVisitor(List<SubqueryContainer>
valueIteratorProviders) {
this.valueIteratorProviders = valueIteratorProviders;
}
@@ -74,7 +75,7 @@
* @return Collection of {@link com.metamatrix.sql.util.ValueIteratorProvider}
* (by default, this is a java.util.ArrayList)
*/
- public List getValueIteratorProviders() {
+ public List<SubqueryContainer> getValueIteratorProviders() {
return this.valueIteratorProviders;
}
@@ -119,23 +120,24 @@
* @param obj Language object
* @return java.util.ArrayList of found ValueIteratorProvider
*/
- public static final List getValueIteratorProviders(LanguageObject obj) {
+ public static final List<SubqueryContainer>
getValueIteratorProviders(LanguageObject obj) {
ValueIteratorProviderCollectorVisitor visitor = new
ValueIteratorProviderCollectorVisitor();
PreOrderNavigator.doVisit(obj, visitor);
return visitor.getValueIteratorProviders();
}
- public static final void getValueIteratorProviders(LanguageObject obj, List
valueIteratorProviders) {
+ public static final void getValueIteratorProviders(LanguageObject obj,
List<SubqueryContainer> valueIteratorProviders) {
ValueIteratorProviderCollectorVisitor visitor = new
ValueIteratorProviderCollectorVisitor(valueIteratorProviders);
PreOrderNavigator.doVisit(obj, visitor);
}
- public static final List getValueIteratorProviders(Collection<? extends
LanguageObject> languageObjects) {
- List result = new LinkedList();
+ public static final List<SubqueryContainer>
getValueIteratorProviders(Collection<? extends LanguageObject> languageObjects) {
+ if (languageObjects == null || languageObjects.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<SubqueryContainer> result = new LinkedList<SubqueryContainer>();
ValueIteratorProviderCollectorVisitor visitor = new
ValueIteratorProviderCollectorVisitor(result);
- Iterator i = languageObjects.iterator();
- while (i.hasNext()) {
- LanguageObject obj = (LanguageObject)i.next();
+ for (LanguageObject obj : languageObjects) {
PreOrderNavigator.doVisit(obj, visitor);
}
return result;
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/AbstractValidationVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -48,6 +48,8 @@
private QueryMetadataInterface metadata;
+ protected Command currentCommand;
+
public AbstractValidationVisitor() {
this.report = new ValidatorReport();
}
@@ -65,7 +67,7 @@
* not wipe the report.
*/
public void reset() {
- //nothing to do here
+ this.currentCommand = null;
}
// ######################### Store results info #########################
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -76,7 +76,6 @@
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.CommandStatement;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
import com.metamatrix.query.sql.proc.CriteriaSelector;
import com.metamatrix.query.sql.proc.DeclareStatement;
@@ -92,7 +91,6 @@
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -112,13 +110,9 @@
// update procedure being validated
private CreateUpdateProcedureCommand updateProc;
- // current procedure subCommand being visited that
- // may contain TranslateCriteria
- private Command transCommand;
public void reset() {
super.reset();
- this.transCommand = null;
this.isXML = false;
this.updateProc = null;
}
@@ -335,11 +329,8 @@
}
if(obj.hasCommand()) {
- // set state command on this may contain translate criteria
- this.transCommand = obj.getCommand();
+ Collection projSymbols = obj.getCommand().getProjectedSymbols();
- Collection projSymbols = transCommand.getProjectedSymbols();
-
//The command execution should result is a value that is assigned to the variable
// there cannot be more than one column in its results
if(projSymbols.size() != 1) {
@@ -352,18 +343,9 @@
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0014),
obj);
}
}
- } else if (obj.hasExpression()) {
- if (!CommandCollectorVisitor.getCommands(obj.getExpression()).isEmpty()) {
-
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.assignment_subquery"),
obj); //$NON-NLS-1$
- }
- }
+ }
}
- public void visit(CommandStatement obj) {
- // set state command on this may contain translate criteria
- this.transCommand = obj.getCommand();
- }
-
public void visit(CreateUpdateProcedureCommand obj) {
if(!obj.isUpdateProcedure()){
//Every virtual procedure should have at least one query.
@@ -430,10 +412,6 @@
}
}
}
-
- if (!CommandCollectorVisitor.getCommands(criteria).isEmpty()) {
-
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.if_subquery"),
obj); //$NON-NLS-1$
- }
}
public void visit(TranslateCriteria obj) {
@@ -504,8 +482,7 @@
* the translated criteria.
*/
protected void validateTranslateCriteria(TranslateCriteria obj) {
- // only possibility, used in If statement which will be invalidated during
visitation process
- if(this.transCommand == null) {
+ if(this.currentCommand == null) {
return;
}
Map symbolMap = this.updateProc.getSymbolMap();
@@ -532,7 +509,7 @@
}
Collection transleElmnts = ElementCollectorVisitor.getElements(obj, true);
- Collection groups = GroupCollectorVisitor.getGroups(this.transCommand, true);
+ Collection groups = GroupCollectorVisitor.getGroups(this.currentCommand, true);
int selectType = obj.getSelector().getSelectorType();
Iterator critIter = PredicateCollectorVisitor.getPredicates(userCrit).iterator();
@@ -1034,9 +1011,6 @@
if (obj.getIntoGroup() != null) {
validateInto(obj, obj.getAsColumns(), obj.getIntoGroup());
}
- if (!CommandCollectorVisitor.getCommands(obj).isEmpty()) {
-
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.assignment_subquery"),
obj); //$NON-NLS-1$
- }
if (obj.getUsing() != null) {
validateSetClauseList(obj.getUsing());
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -56,7 +56,7 @@
}
// Recursively validate subcommands
- Iterator iter = CommandCollectorVisitor.getCommands(object,
validateOnlyEmbedded).iterator();
+ Iterator iter = CommandCollectorVisitor.getCommands((Command)object,
validateOnlyEmbedded).iterator();
while(iter.hasNext()) {
Command subCommand = (Command) iter.next();
validate(subCommand, metadata, visitor, validateOnlyEmbedded);
@@ -83,7 +83,7 @@
protected void visitNode(LanguageObject obj) {
QueryMetadataInterface previous = visitor.getMetadata();
- setTempMetadata(metadata, visitor, obj);
+ setTempMetadata(metadata, visitor, obj);
super.visitNode(obj);
visitor.setMetadata(previous);
}
@@ -102,7 +102,8 @@
final AbstractValidationVisitor visitor,
LanguageObject obj) {
if (obj instanceof Command) {
- Command command = (Command)obj;
+ Command command = (Command)obj;
+ visitor.currentCommand = command;
Map tempMetadata = command.getTemporaryMetadata();
if(tempMetadata != null && !tempMetadata.isEmpty()) {
visitor.setMetadata(new TempMetadataAdapter(metadata, new
TempMetadataStore(tempMetadata)));
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -84,6 +84,7 @@
import com.metamatrix.dqp.util.LogConstants;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.server.serverapi.RequestInfo;
import com.metamatrix.vdb.runtime.VDBKey;
@@ -130,7 +131,7 @@
// Resources
private ConnectorCapabilitiesCache connectorCapabilitiesCache = new
ConnectorCapabilitiesCache();
private BufferManager bufferManager;
- private DataTierManager dataTierMgr;
+ private ProcessorDataManager dataTierMgr;
private PreparedPlanCache prepPlanCache;
private TrackingService tracker;
private TransactionService transactionService;
@@ -539,11 +540,11 @@
rowCount);
}
- DataTierManager getDataTierManager() {
+ ProcessorDataManager getDataTierManager() {
return this.dataTierMgr;
}
- public void setDataTierManager(DataTierManager dataTierMgr) {
+ public void setDataTierManager(ProcessorDataManager dataTierMgr) {
this.dataTierMgr = dataTierMgr;
}
@@ -634,7 +635,6 @@
dataTierMgr = new DataTierManagerImpl(this,
(DataService)
env.findService(DQPServiceNames.DATA_SERVICE),
- (MetadataService)
env.findService(DQPServiceNames.METADATA_SERVICE),
(VDBService)
env.findService(DQPServiceNames.VDB_SERVICE),
(BufferService)
env.findService(DQPServiceNames.BUFFER_SERVICE),
this.maxCodeTables,
Deleted: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.process;
-
-import com.metamatrix.query.processor.ProcessorDataManager;
-
-public interface DataTierManager extends ProcessorDataManager {
-
- void clearCodeTables();
-
-}
\ No newline at end of file
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -44,15 +44,15 @@
import com.metamatrix.dqp.message.RequestMessage;
import com.metamatrix.dqp.service.BufferService;
import com.metamatrix.dqp.service.DataService;
-import com.metamatrix.dqp.service.MetadataService;
import com.metamatrix.dqp.service.VDBService;
import com.metamatrix.dqp.util.LogConstants;
+import com.metamatrix.query.processor.ProcessorDataManager;
import com.metamatrix.query.processor.QueryProcessor;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.util.CommandContext;
-public class DataTierManagerImpl implements DataTierManager {
+public class DataTierManagerImpl implements ProcessorDataManager {
// Resources
private DQPCore requestMgr;
@@ -67,9 +67,8 @@
private CodeTableCache codeTableCache;
public DataTierManagerImpl(DQPCore requestMgr,
- DataService dataService, MetadataService metadataService, VDBService vdbService,
- BufferService bufferService, int maxCodeTables,
- int maxCodeTableRecords) {
+ DataService dataService, VDBService vdbService, BufferService bufferService,
+ int maxCodeTables, int maxCodeTableRecords) {
this.requestMgr = requestMgr;
this.dataService = dataService;
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-27
16:49:34 UTC (rev 845)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -29,6 +29,8 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.mapping.relational.QueryNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DependentProjectNode;
+import com.metamatrix.query.optimizer.TestOptimizer.DependentSelectNode;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -37,8 +39,6 @@
import com.metamatrix.query.processor.TestProcessor;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.LimitNode;
@@ -79,7 +79,7 @@
0 // UnionAll
};
- public static final Class[] NODE_TYPES = new Class[] {
+ public static final Class<?>[] NODE_TYPES = new Class[] {
AccessNode.class,
DependentAccessNode.class,
DependentSelectNode.class,
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -30,10 +30,10 @@
import java.util.List;
import java.util.Set;
-import org.teiid.connector.api.SourceSystemFunctions;
-
import junit.framework.TestCase;
+import org.teiid.connector.api.SourceSystemFunctions;
+
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
import com.metamatrix.api.exception.query.QueryParserException;
@@ -58,8 +58,6 @@
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.processor.relational.AccessNode;
import com.metamatrix.query.processor.relational.DependentAccessNode;
-import com.metamatrix.query.processor.relational.DependentProjectNode;
-import com.metamatrix.query.processor.relational.DependentSelectNode;
import com.metamatrix.query.processor.relational.DupRemoveNode;
import com.metamatrix.query.processor.relational.GroupingNode;
import com.metamatrix.query.processor.relational.JoinNode;
@@ -80,6 +78,7 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
+import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataFactory;
import com.metamatrix.query.unittest.FakeMetadataObject;
@@ -91,6 +90,8 @@
public class TestOptimizer extends TestCase {
public interface DependentJoin {}
+ public interface DependentSelectNode {}
+ public interface DependentProjectNode {}
public static final int[] FULL_PUSHDOWN = new int[] {
1, // Access
@@ -417,8 +418,8 @@
* @param relationalNode
* @return int[]
*/
- public static void collectCounts(RelationalNode relationalNode, int[] counts, Class[]
types) {
- Class nodeType = relationalNode.getClass();
+ public static void collectCounts(RelationalNode relationalNode, int[] counts,
Class<?>[] types) {
+ Class<?> nodeType = relationalNode.getClass();
if(nodeType.equals(JoinNode.class)) {
if (((JoinNode)relationalNode).getJoinStrategy() instanceof
NestedLoopJoinStrategy) {
updateCounts(NestedLoopJoinStrategy.class, counts, types);
@@ -428,7 +429,19 @@
if (((JoinNode)relationalNode).isDependent()) {
updateCounts(DependentJoin.class, counts, types);
}
- }else {
+ }else if (nodeType.equals(ProjectNode.class)){
+ if
(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((ProjectNode)relationalNode).getSelectSymbols()).isEmpty())
{
+ updateCounts(ProjectNode.class, counts, types);
+ } else {
+ updateCounts(DependentProjectNode.class, counts, types);
+ }
+ }else if (nodeType.equals(SelectNode.class)){
+ if
(ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((SelectNode)relationalNode).getCriteria()).isEmpty())
{
+ updateCounts(SelectNode.class, counts, types);
+ } else {
+ updateCounts(DependentSelectNode.class, counts, types);
+ }
+ } else {
updateCounts(nodeType, counts, types);
}
@@ -1862,7 +1875,7 @@
public void testPushOuterJoin1() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -6585,47 +6598,6 @@
checkSubPlanCount(plan, 0);
}
- /*
- * Expressions containing subqueries cannot be pushed down
- */
- public void testCase4306() {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- FakeMetadataFacade metadata = example1();
-
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
- caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
- caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
- caps.setCapabilitySupport(Capability.FUNCTION, true);
- caps.setFunctionSupport("+", true); //$NON-NLS-1$
- caps.setFunctionSupport("convert", true); //$NON-NLS-1$
- capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
- ProcessorPlan plan = helpPlan("select pm1.g1.e1, convert((select
max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", metadata, //$NON-NLS-1$
- null, capFinder,
- new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" }, SHOULD_SUCCEED);
//$NON-NLS-1$
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 1, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // Join
- 0, // MergeJoin
- 0, // Null
- 0, // PlanExecution
- 0, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
-
- checkSubPlanCount(plan, 1);
- }
-
public void testCase4312() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = getTypicalCapabilities();
@@ -6818,7 +6790,7 @@
*/
public void testSameConnector() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -354,7 +354,7 @@
// Create capabilities
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
- BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
Modified:
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -173,7 +173,7 @@
"(c37s.stringkey = ('1' || (m37s.intkey || '0'))) AND
" + //$NON-NLS-1$
"(m37s.stringkey = m37n.stringkey) ))"; //$NON-NLS-1$
- String sqlOut = "SELECT c37n.intkey FROM bqt1.mediuma AS c37n, bqt1.smallb
AS m37n WHERE (c37n.datevalue = (SELECT MAX(c37s.datevalue) FROM bqt1.mediuma AS c37s,
bqt1.smallb AS m37s WHERE (c37s.stringkey = ('1' || (m37s.intkey || '0')))
AND (m37s.stringkey LIKE '%0') AND (m37s.stringkey = m37n.stringkey))) AND
(c37n.stringkey = ('1' || (m37n.intkey || '0'))) AND (m37n.stringkey LIKE
'%0')"; //$NON-NLS-1$
+ String sqlOut = "SELECT g_0.intkey FROM bqt1.mediuma AS g_0, bqt1.smallb AS
g_1 WHERE (g_0.stringkey = concat('1', concat(g_1.intkey, '0'))) AND
(g_0.datevalue = (SELECT MAX(g_2.datevalue) FROM bqt1.mediuma AS g_2, bqt1.smallb AS g_3
WHERE (g_2.stringkey = concat('1', concat(g_3.intkey, '0'))) AND
(g_3.stringkey LIKE '%0') AND (g_3.stringkey = g_1.stringkey))) AND (g_1.stringkey
LIKE '%0')"; //$NON-NLS-1$
ProcessorPlan plan = helpPlan(sqlIn, FakeMetadataFactory.exampleBQTCached(),
null, capFinder,
@@ -716,5 +716,32 @@
new String[] { "SELECT g_0.intkey FROM bqt1.smalla AS g_0 WHERE
(g_0.intkey = (SELECT MAX(g_1.intkey) FROM bqt1.smallb AS g_1 WHERE g_1.stringkey =
g_0.stringkey)) OR (g_0.intkey = (SELECT MIN(g_2.IntKey) FROM bqt1.smallb AS g_2 WHERE
g_2.StringKey = g_0.stringkey))" }, SHOULD_SUCCEED); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
+
+ /*
+ * Expressions containing subqueries can be pushed down
+ */
+ @Test public void testProjectSubqueryPushdown() {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ FakeMetadataFacade metadata = example1();
+
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_WHERE, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+ caps.setCapabilitySupport(Capability.FUNCTION, true);
+ caps.setFunctionSupport("+", true); //$NON-NLS-1$
+ caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan("select pm1.g1.e1, convert((select
max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", metadata, //$NON-NLS-1$
+ null, capFinder,
+ new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_1.e1) FROM pm1.g1
AS g_1), integer) + 1) FROM pm1.g1 AS g_0" }, SHOULD_SUCCEED); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+
+ checkSubPlanCount(plan, 0);
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -23,13 +23,10 @@
package com.metamatrix.query.processor;
import java.util.ArrayList;
-import java.util.Arrays;
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 com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
@@ -354,5 +351,10 @@
public void setBlockOnce() {
blockOnce = true;
}
+
+ @Override
+ public void clearCodeTables() {
+
+ }
}
\ No newline at end of file
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -29,8 +29,6 @@
import java.util.Map;
import java.util.Set;
-import org.teiid.dqp.internal.process.DataTierManager;
-
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.TupleSource;
@@ -42,7 +40,7 @@
* @since 4.2
*/
public class HardcodedDataManager implements
- DataTierManager {
+ ProcessorDataManager {
// sql string to data
private Map data = new HashMap();
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -33,6 +33,7 @@
import junit.framework.TestCase;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.CriteriaEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.eval.Evaluator;
@@ -44,8 +45,8 @@
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ContextReference;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.util.ValueIterator;
import com.metamatrix.query.util.CommandContext;
@@ -101,14 +102,16 @@
elementMap.put(e1, new Integer(0));
List tuple = Arrays.asList(new String[]{"a"}); //$NON-NLS-1$
- CommandContext cc = new CommandContext() {
+ CommandContext cc = new CommandContext();
+ assertEquals(expectedResult, new Evaluator(elementMap, null, cc) {
@Override
- public ValueIterator getValueIterator(ContextReference ref)
- throws MetaMatrixComponentException {
+ protected ValueIterator evaluateSubquery(
+ SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
return new CollectionValueIterator(values);
}
- };
- assertEquals(expectedResult, new Evaluator(elementMap, null, cc).evaluate(crit,
tuple));
+ }.evaluate(crit, tuple));
}
private SubqueryCompareCriteria helpGetCompareSubqueryCriteria(int operator, int
predicateQuantifier){
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -34,6 +34,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.query.eval.Evaluator;
@@ -44,6 +45,7 @@
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.CollectionValueIterator;
import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
import com.metamatrix.query.sql.symbol.AggregateSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
@@ -275,14 +277,16 @@
throws BlockedException,
MetaMatrixComponentException, ExpressionEvaluationException {
final CollectionValueIterator valueIter = new CollectionValueIterator(values);
- CommandContext cc = new CommandContext() {
+ CommandContext cc = new CommandContext();
+ assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc) {
@Override
- public ValueIterator getValueIterator(ContextReference ref)
- throws MetaMatrixComponentException {
+ protected ValueIterator evaluateSubquery(
+ SubqueryContainer container, List tuple)
+ throws MetaMatrixProcessingException, BlockedException,
+ MetaMatrixComponentException {
return valueIter;
}
- };
- assertEquals(expected, new Evaluator(Collections.emptyMap(), null,
cc).evaluate(expr, null) );
+ }.evaluate(expr, null) );
}
public void testScalarSubquery2() throws Exception{
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -2580,6 +2580,58 @@
List[] expected = new List[] {Arrays.asList(new Object[] {new Integer(3)})};
helpTestProcess(plan, expected, dataMgr);
}
+
+ public void testDefect8693() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2 =
5;\n"; //$NON-NLS-1$
+ procedure = procedure + "if (5 in (select 5 from pm1.g1))\n";
//$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
+ FakeMetadataFacade metadata =
FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE,
procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 5, dataMgr);
+ }
+
+ public void testWhileWithSubquery() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1 = 2;\n"; //$NON-NLS-1$
+ procedure = procedure + "WHILE (5 in (select var1 from pm1.g1))\n";
//$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
+
+ FakeMetadataFacade metadata =
FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE,
procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 0, dataMgr);
+ }
+
+ public void testDefect18404() throws Exception {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1 = 5 + (select count(e2) from
pm1.g1);\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
+ procedure = procedure + "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
+
+ FakeMetadataFacade metadata =
FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE,
procedure);
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+ helpTestProcess(plan, 8, dataMgr);
+ }
+
private static final boolean DEBUG = false;
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -110,6 +110,10 @@
assertEquals(expectedCommand, command.toString());
return null;
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
public void testShouldExecuteUpdate() throws Exception {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -212,6 +212,10 @@
actualCommands.add(command);
return new FakeTupleSource(numExecutedCommands);
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
private static final class FakeTupleSource implements TupleSource {
private int currentTuple = 0;
Deleted:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -1,222 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-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.ExistsCriteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- * Tests {@link DependentSelectNode DependentSelectNode} class
- */
-public class TestDependentSelectNode extends TestCase {
-
- /**
- * Constructor for TestDependentSelectNode.
- * @param name
- */
- public TestDependentSelectNode(String name) {
- super(name);
- }
-
- //Just for testing clone() method of DependentSelectNode
- private static class DoNothingProcessorPlan implements ProcessorPlan{
- private DoNothingProcessorPlan original;
- public DoNothingProcessorPlan(){}
- public DoNothingProcessorPlan(DoNothingProcessorPlan original){
- this.original = original;
- }
- public Object clone() {return new DoNothingProcessorPlan(this);}
- public void close() throws MetaMatrixComponentException {}
- public void connectTupleSource(TupleSource source, int dataRequestID) {}
- public List getAndClearWarnings() {return null;}
- public List getOutputElements() {return null;}
- public void initialize(
- CommandContext context,
- ProcessorDataManager dataMgr,
- BufferManager bufferMgr) {}
- public CommandContext getContext() { return null; }
- public TupleBatch nextBatch()throws BlockedException,
MetaMatrixComponentException{return null;}
- public void open() throws MetaMatrixComponentException {}
- public void reset() {}
- /* (non-Javadoc)
- * @see com.metamatrix.query.processor.ProcessorPlan#getUpdateCount()
- */
- public int getUpdateCount() {
- // TODO Auto-generated method stub
- return 0;
- }
- public Map getDescriptionProperties() {
- return new HashMap();
- }
- public Collection getChildPlans() {
- return Collections.EMPTY_LIST;
- }
-
- }
-
- private List helpMakeFakeProcessorPlans(int count){
- List result = new ArrayList(count);
- for (int i=0; i<count; i++){
- result.add(new DoNothingProcessorPlan());
- }
- return result;
- }
-
- private Command helpMakeCommand(){
- Select select = new Select();
- ElementSymbol element = new ElementSymbol("e2"); //$NON-NLS-1$
- select.addSymbol(element);
- From from = new From();
- GroupSymbol pm1g2 = new GroupSymbol("pm1.g2"); //$NON-NLS-1$
- from.addGroup(pm1g2);
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- return query;
- }
-
- private Command helpMakeCommand2(){
- Select select = new Select();
- ElementSymbol element = new ElementSymbol("e3"); //$NON-NLS-1$
- select.addSymbol(element);
- From from = new From();
- GroupSymbol pm1g2 = new GroupSymbol("pm4.g5"); //$NON-NLS-1$
- from.addGroup(pm1g2);
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- return query;
- }
-
- /**
- * Tests clone() method of DependentSelectNode
- */
- public void testClone(){
- int id = 1;
- Command subCommand = helpMakeCommand();
- subCommand.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit = new SubquerySetCriteria(new Constant("3"), subCommand);
//$NON-NLS-1$
- Command subCommand2 = helpMakeCommand2();
- subCommand2.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit2 = new SubquerySetCriteria(new ElementSymbol("f"),
subCommand2); //$NON-NLS-1$
- DependentSelectNode node = new DependentSelectNode(id, new
SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new
DoNothingProcessorPlan()), null, null));
- //Set up criteria
- CompoundCriteria crit = new CompoundCriteria();
- crit.addCriteria(subCrit);
- crit.addCriteria(subCrit2);
- crit.setOperator(CompoundCriteria.AND);
-// Criteria otherCrit = new IsNullCriteria(new ElementSymbol("fakeElement"));
-// crit.addCriteria(otherCrit);
- node.setCriteria(crit);
-
- //Test clone
- DependentSelectNode cloned = (DependentSelectNode)node.clone();
-
- List<? extends ProcessorPlan> originalProcessorPlans =
node.getSubqueryProcessorUtility().getSubqueryPlans();
- List clonedProcessorPlans = cloned.getSubqueryProcessorUtility().getSubqueryPlans();
- assertTrue(clonedProcessorPlans.size() == 2);
- assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
- for (int i=0; i<originalProcessorPlans.size(); i++){
- //Check ProcessorPlans
- ProcessorPlan originalPlan = originalProcessorPlans.get(i);
- DoNothingProcessorPlan clonedPlan =
(DoNothingProcessorPlan)clonedProcessorPlans.get(i);
- assertNotNull(clonedPlan.original);
- assertSame(originalPlan, clonedPlan.original);
- }
-
- }
-
- /**
- * Tests clone() method of DependentSelectNode
- */
- public void testClone2(){
- int id = 1;
- Command subCommand = helpMakeCommand();
- subCommand.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit = new SubqueryCompareCriteria(new ElementSymbol("f"),
subCommand, SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ANY); //$NON-NLS-1$
-
- Command subCommand2 = helpMakeCommand2();
- subCommand2.setProcessorPlan(new DoNothingProcessorPlan());
- Criteria subCrit2 = new ExistsCriteria(subCommand2);
-
- //Set up DependentSelectNode data
- List crits = new ArrayList(2);
- crits.add(subCrit);
- crits.add(subCrit2);
-
- DependentSelectNode node = new DependentSelectNode(id, new
SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new
DoNothingProcessorPlan()), null, null));
-
- //Set up criteria
- CompoundCriteria crit = new CompoundCriteria();
- crit.addCriteria(subCrit);
- crit.addCriteria(subCrit2);
- crit.setOperator(CompoundCriteria.AND);
-// Criteria otherCrit = new IsNullCriteria(new
ElementSymbol("fakeElement"));
-// crit.addCriteria(otherCrit);
- node.setCriteria(crit);
-
- //Test clone
- DependentSelectNode cloned = (DependentSelectNode)node.clone();
-
- List originalProcessorPlans =
node.getSubqueryProcessorUtility().getSubqueryPlans();
- List clonedProcessorPlans =
cloned.getSubqueryProcessorUtility().getSubqueryPlans();
- assertTrue(clonedProcessorPlans.size() == 2);
- assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
- for (int i=0; i<originalProcessorPlans.size(); i++){
- //Check ProcessorPlans
- Object originalPlan = originalProcessorPlans.get(i);
- DoNothingProcessorPlan clonedPlan =
(DoNothingProcessorPlan)clonedProcessorPlans.get(i);
- assertNotNull(clonedPlan.original);
- assertSame(originalPlan, clonedPlan.original);
- }
- }
-
-}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -189,6 +189,10 @@
Object val = row.get(0);
assertEquals(new Integer(value), val);
}
+ @Override
+ public void clearCodeTables() {
+
+ }
}
private static final class FakeDataTupleSource implements TupleSource {
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -61,6 +61,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -1925,9 +1926,9 @@
Query query = (Query)helpTestRewriteCommand(sql, expected);
- List refs = new LinkedList();
+ List<Reference> refs = new LinkedList<Reference>();
- CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new
Object[] {new GroupSymbol("pm1.g1")}), refs);//$NON-NLS-1$
+ CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new
GroupSymbol("pm1.g1")), refs);//$NON-NLS-1$
assertEquals(1, refs.size());
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -30,6 +30,7 @@
import java.util.List;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.mapping.relational.QueryNode;
import com.metamatrix.query.mapping.xml.MappingAttribute;
@@ -1043,7 +1044,7 @@
QueryNode vspqn48 = new QueryNode("vsp48", "CREATE VIRTUAL
PROCEDURE BEGIN DECLARE string x; SELECT e1 FROM (EXEC pm1.sq2(pm1.vsp48.in)) as e;
END"); //$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp48 = createVirtualProcedure("pm1.vsp48", pm1,
Arrays.asList(new FakeMetadataObject[] { vsp48p1, vsp48p2 }), vspqn48); //$NON-NLS-1$
- FakeMetadataObject vsp49rs = createResultSet("pm1vsp49.rs", pm1, new
String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$
+ FakeMetadataObject vsp49rs = createResultSet("pm1vsp49.rs", pm1, new
String[] { "e1", "e2" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FakeMetadataObject vsp49p1 = createParameter("ret", 1,
ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, vsp49rs);
//$NON-NLS-1$
QueryNode vspqn49 = new QueryNode("vsp49", "CREATE VIRTUAL
PROCEDURE BEGIN DECLARE string x; x = 'b'; EXEC pm1.sq2(x); END");
//$NON-NLS-1$ //$NON-NLS-2$
FakeMetadataObject vsp49 = createVirtualProcedure("pm1.vsp49", pm1,
Arrays.asList(new FakeMetadataObject[] { vsp49p1 }), vspqn49); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -419,12 +419,9 @@
// Get invalid objects from report
Collection actualObjs = new ArrayList();
report.collectInvalidObjects(actualObjs);
- //System.out.println(report);
- if(actualObjs.size() == 0) {
- fail("Expected some failures but got none for procedure = " +
procedure); //$NON-NLS-1$
- }
+ assertTrue("Expected some failures but got none for procedure = " +
procedure, !actualObjs.isEmpty()); //$NON-NLS-1$
} catch(MetaMatrixException e) {
- fail("Exception during validation (" + e.getClass().getName() + "):
" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new RuntimeException(e);
}
}
@@ -1881,51 +1878,8 @@
store.addObject(virtualResultSet);
store.addObject(virtualStoredProcedure);
return new FakeMetadataFacade(store);
- }
+ }
- public void testDefect8693() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1 where e2 =
5;\n"; //$NON-NLS-1$
- procedure = procedure + "if (5 in (select 5 from pm1.g1))\n";
//$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
- public void testWhileWithSubquery() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "WHILE (5 in (select 5 from pm1.g1))\n";
//$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
- public void testDefect18404() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1 = 5 + (select count(e2) from
pm1.g1);\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED = ROWS_UPDATED + var1;\n";
//$NON-NLS-1$
- procedure = procedure + "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
//$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
public void testSelectIntoWithNull() {
helpValidate("SELECT null, null, null, null INTO pm1.g1 FROM pm1.g2",
new String[] {}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
}
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -108,7 +108,6 @@
dtm = new DataTierManagerImpl(rm,
dataService,
- new MockSingleMetadataService(metadata),
vdbService,
bs,
1000,
Modified:
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java
===================================================================
---
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-04-27
16:49:34 UTC (rev 845)
+++
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestTPCR.java 2009-04-27
19:02:50 UTC (rev 846)
@@ -212,7 +212,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan("select S_ACCTBAL, S_NAME,
N_NAME, P_PARTKEY, P_MFGR, S_ADDRESS, S_PHONE, S_COMMENT from (SELECT SUPPLIER.S_ACCTBAL,
SUPPLIER.S_NAME, NATION.N_NAME, PART.P_PARTKEY, PART.P_MFGR, SUPPLIER.S_ADDRESS,
SUPPLIER.S_PHONE, SUPPLIER.S_COMMENT FROM PART, SUPPLIER, PARTSUPP, NATION, REGION WHERE
(PART.P_PARTKEY = PS_PARTKEY) AND (S_SUPPKEY = PS_SUPPKEY) AND (P_SIZE = 15) AND (P_TYPE
LIKE '%BRASS') AND (S_NATIONKEY = N_NATIONKEY) AND (N_REGIONKEY = R_REGIONKEY) AND
(R_NAME = 'EUROPE') AND (PS_SUPPLYCOST = (SELECT MIN(PS_SUPPLYCOST) FROM PARTSUPP,
SUPPLIER, NATION, REGION WHERE (PART.P_PARTKEY = PS_PARTKEY) AND (S_SUPPKEY = PS_SUPPKEY)
AND (S_NATIONKEY = N_NATIONKEY) AND (N_REGIONKEY = R_REGIONKEY) AND (R_NAME =
'EUROPE'))) ORDER BY SUPPLIER.S_ACCTBAL DESC, NATION.N_NAME, SUPPLIER.S_NAME,
PART.P_PARTKEY) as x", //$NON-NLS-1$
METADATA, null, finder,
- new String[] {"SELECT g_1.S_ACCTBAL, g_1.S_NAME, g_3.N_NAME,
g_0.P_PARTKEY, g_0.P_MFGR, g_1.S_ADDRESS, g_1.S_PHONE, g_1.S_COMMENT FROM
TPCR_Oracle_9i.PART AS g_0, TPCR_Oracle_9i.SUPPLIER AS g_1, TPCR_Oracle_9i.PARTSUPP AS
g_2, TPCR_Oracle_9i.NATION AS g_3, TPCR_Oracle_9i.REGION AS g_4 WHERE (g_2.PS_SUPPLYCOST =
(SELECT MIN(g_5.PS_SUPPLYCOST) FROM TPCR_Oracle_9i.PARTSUPP AS g_5,
TPCR_Oracle_9i.SUPPLIER AS g_6, TPCR_Oracle_9i.NATION AS g_7, TPCR_Oracle_9i.REGION AS g_8
WHERE (g_7.N_REGIONKEY = g_8.R_REGIONKEY) AND (g_8.R_NAME = 'EUROPE') AND
(g_6.S_NATIONKEY = g_7.N_NATIONKEY) AND (g_6.S_SUPPKEY = g_5.PS_SUPPKEY) AND
(g_5.PS_PARTKEY = g_0.P_PARTKEY))) AND (g_0.P_PARTKEY = g_2.PS_PARTKEY) AND (g_0.P_SIZE =
15.0) AND (g_0.P_TYPE LIKE '%BRASS') AND (g_1.S_NATIONKEY = g_3.N_NATIONKEY) AND
(g_1.S_SUPPKEY = g_2.PS_SUPPKEY) AND (g_3.N_REGIONKEY = g_4.R_REGIONKEY) AND (g_4.R_NAME =
'EUROPE')"}, true); //$NON-NLS-1$
+ new String[] {"SELECT g_1.S_ACCTBAL, g_1.S_NAME, g_3.N_NAME,
g_0.P_PARTKEY, g_0.P_MFGR, g_1.S_ADDRESS, g_1.S_PHONE, g_1.S_COMMENT FROM
TPCR_Oracle_9i.PART AS g_0, TPCR_Oracle_9i.SUPPLIER AS g_1, TPCR_Oracle_9i.PARTSUPP AS
g_2, TPCR_Oracle_9i.NATION AS g_3, TPCR_Oracle_9i.REGION AS g_4 WHERE (g_0.P_PARTKEY =
g_2.PS_PARTKEY) AND (g_2.PS_SUPPLYCOST = (SELECT MIN(g_5.PS_SUPPLYCOST) FROM
TPCR_Oracle_9i.PARTSUPP AS g_5, TPCR_Oracle_9i.SUPPLIER AS g_6, TPCR_Oracle_9i.NATION AS
g_7, TPCR_Oracle_9i.REGION AS g_8 WHERE (g_7.N_REGIONKEY = g_8.R_REGIONKEY) AND
(g_8.R_NAME = 'EUROPE') AND (g_6.S_NATIONKEY = g_7.N_NATIONKEY) AND (g_6.S_SUPPKEY
= g_5.PS_SUPPKEY) AND (g_5.PS_PARTKEY = g_0.P_PARTKEY))) AND (g_0.P_SIZE = 15.0) AND
(g_0.P_TYPE LIKE '%BRASS') AND (g_1.S_NATIONKEY = g_3.N_NATIONKEY) AND
(g_1.S_SUPPKEY = g_2.PS_SUPPKEY) AND (g_3.N_REGIONKEY = g_4.R_REGIONKEY) AND (g_4.R_NAME =
'EUROPE')"}, true); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}