Author: shawkins
Date: 2009-09-29 09:52:23 -0400 (Tue, 29 Sep 2009)
New Revision: 1489
Modified:
trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.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/rules/RulePushSelectCriteria.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java
Log:
TEIID-858 fix for dependentsetcriteria not being replaced
Modified: trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-09-28
21:11:23 UTC (rev 1488)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -317,7 +317,13 @@
valueIter = new CollectionValueIterator(((SetCriteria)criteria).getValues());
} else if (criteria instanceof DependentSetCriteria){
ContextReference ref = (ContextReference)criteria;
- HashSet<Object> values = getValues(getContext(criteria), ref);
+ ValueIteratorSource vis =
(ValueIteratorSource)getContext(criteria).getVariableContext().getGlobalValue(ref.getContextSymbol());
+ HashSet<Object> values;
+ try {
+ values = vis.getCachedSet(ref.getValueExpression());
+ } catch (MetaMatrixProcessingException e) {
+ throw new CriteriaEvaluationException(e, e.getMessage());
+ }
if (values != null) {
return values.contains(leftValue);
}
@@ -362,19 +368,6 @@
return Boolean.valueOf(criteria.isNegated());
}
- public static HashSet<Object> getValues(CommandContext context,
- ContextReference ref) throws MetaMatrixComponentException,
- CriteriaEvaluationException {
- ValueIteratorSource vis =
(ValueIteratorSource)context.getVariableContext().getGlobalValue(ref.getContextSymbol());
- HashSet<Object> values;
- try {
- values = vis.getCachedSet(ref.getValueExpression());
- } catch (MetaMatrixProcessingException e) {
- throw new CriteriaEvaluationException(e, e.getMessage());
- }
- return values;
- }
-
public boolean evaluate(IsNullCriteria criteria, List tuple)
throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
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-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -82,7 +82,6 @@
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.EvaluatableVisitor;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
-import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
public class PlanToProcessConverter {
@@ -90,14 +89,12 @@
private IDGenerator idGenerator;
private AnalysisRecord analysisRecord;
private CapabilitiesFinder capFinder;
- private CommandContext context;
- public PlanToProcessConverter(QueryMetadataInterface metadata, IDGenerator idGenerator,
AnalysisRecord analysisRecord, CapabilitiesFinder capFinder, CommandContext context) {
+ public PlanToProcessConverter(QueryMetadataInterface metadata, IDGenerator idGenerator,
AnalysisRecord analysisRecord, CapabilitiesFinder capFinder) {
this.metadata = metadata;
this.idGenerator = idGenerator;
this.analysisRecord = analysisRecord;
this.capFinder = capFinder;
- this.context = context;
}
public RelationalPlan convert(PlanNode planNode)
@@ -275,16 +272,9 @@
//create dependent access node
DependentAccessNode depAccessNode = new
DependentAccessNode(getID());
- int maxSetSize = -1;
if(modelID != null){
- try {
- // set the max set size for the access node
- maxSetSize =
CapabilitiesUtil.getMaxInCriteriaSize(modelID, metadata, capFinder);
- }catch(QueryMetadataException e) {
- throw new QueryPlannerException(e,
QueryExecPlugin.Util.getString(ErrorMessageKeys.OPTIMIZER_0006, modelID));
- }
+
depAccessNode.setMaxSetSize(CapabilitiesUtil.getMaxInCriteriaSize(modelID, metadata,
capFinder));
}
- depAccessNode.setMaxSetSize(maxSetSize);
processNode = depAccessNode;
aNode = depAccessNode;
}
@@ -298,8 +288,7 @@
//-- special handling for temp tables. currently they cannot
perform projection
try {
if (command instanceof Query) {
- processNode = correctProjectionForTempTable(node,
- aNode);
+ processNode = correctProjectionForTempTable(node,
aNode);
}
} catch (QueryMetadataException err) {
throw new MetaMatrixComponentException(err);
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-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -53,7 +53,6 @@
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -146,7 +145,7 @@
planToProcessConverter = context.getPlanToProcessConverter();
}
if (planToProcessConverter == null) {
- planToProcessConverter = new PlanToProcessConverter(metadata, idGenerator,
analysisRecord, capFinder, context);
+ planToProcessConverter = new PlanToProcessConverter(metadata, idGenerator,
analysisRecord, capFinder);
}
RelationalPlan result = planToProcessConverter.convert(plan);
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-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -282,8 +282,9 @@
}
satisfyAccessPatterns(critNode, currentNode);
-
- if (critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET))
{
+
+ if (critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)
+ &&
CapabilitiesUtil.getMaxInCriteriaSize(RuleRaiseAccess.getModelIDFromAccess(currentNode,
metadata), metadata, capFinder) > 0) {
//once a dependent crit node is pushed, don't bother pushing
it further into the command
//dependent access node will use this as an assumption for where
dependent sets can appear in the command
critNode.setProperty(NodeConstants.Info.IS_PUSHED,
Boolean.TRUE);
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java 2009-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentAccessNode.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -114,10 +114,6 @@
Query query = (Query)atomicCommand;
- if (query.getCriteria() == null || maxSetSize < 1) {
- return super.prepareNextCommand(atomicCommand);
- }
-
if (this.criteriaProcessor == null) {
this.criteriaProcessor = new DependentCriteriaProcessor(this.maxSetSize,
this, query.getCriteria());
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-09-28
21:11:23 UTC (rev 1488)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -69,6 +69,7 @@
import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.metadata.TempMetadataStore;
import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.relational.DependentValueSource;
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.resolver.util.ResolverVisitor;
@@ -144,6 +145,7 @@
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
+import com.metamatrix.query.sql.util.ValueIterator;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.CriteriaTranslatorVisitor;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
@@ -1085,11 +1087,36 @@
}
rewriteSubqueryContainer((SubqueryContainer)criteria, true);
} else if (criteria instanceof DependentSetCriteria) {
- criteria = rewriteCriteria((AbstractSetCriteria)criteria);
+ criteria = rewriteDependentSetCriteria((DependentSetCriteria)criteria);
}
return evaluateCriteria(criteria);
}
+
+ private Criteria rewriteDependentSetCriteria(DependentSetCriteria dsc)
+ throws QueryValidatorException {
+ if (dataMgr == null) {
+ return rewriteCriteria(dsc);
+ }
+ SetCriteria setCrit = new SetCriteria();
+ setCrit.setExpression(dsc.getExpression());
+ HashSet<Object> values = new HashSet<Object>();
+ try {
+ DependentValueSource dvs =
(DependentValueSource)this.context.getVariableContext().getGlobalValue(dsc.getContextSymbol());
+ ValueIterator iter = dvs.getValueIterator(dsc.getValueExpression());
+ while (iter.hasNext()) {
+ values.add(iter.next());
+ }
+ } catch (MetaMatrixComponentException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ List<Constant> constants = new ArrayList<Constant>(values.size());
+ for (Object value : values) {
+ constants.add(new Constant(value, setCrit.getExpression().getType()));
+ }
+ setCrit.setValues(constants);
+ return rewriteCriteria(setCrit);
+ }
/**
* Performs simple expression flattening
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2009-09-28
21:11:23 UTC (rev 1488)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -34,7 +34,6 @@
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SelectSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
/**
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -133,7 +133,7 @@
}
public void visit(DependentSetCriteria obj) {
- evaluationNotPossible(EvaluationLevel.PUSH_DOWN);
+ evaluationNotPossible(EvaluationLevel.PROCESSING);
}
public void visit(ExistsCriteria obj) {
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java 2009-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -59,7 +59,7 @@
IDGenerator idGenerator, AnalysisRecord analysisRecord,
CapabilitiesFinder capFinder, Set<String> multiSourceModels,
String vdbName, VDBService vdbService, String vdbVersion, CommandContext context) {
- super(metadata, idGenerator, analysisRecord, capFinder, context);
+ super(metadata, idGenerator, analysisRecord, capFinder);
this.multiSourceModels = multiSourceModels;
this.vdbName = vdbName;
this.vdbService = vdbService;
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java 2009-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -25,6 +25,10 @@
import java.util.Arrays;
import java.util.List;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.QueryParserException;
+import com.metamatrix.api.exception.query.QueryResolverException;
+import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.query.optimizer.TestOptimizer;
import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
@@ -498,9 +502,24 @@
}
public void testCase5130a() throws Exception {
- FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ HardcodedDataManager dataManager = helpTestDependentJoin(false);
+
+ assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey,
a.intkey FROM bqt2.smalla AS a WHERE (concat(a.stringkey, 't') IN ('1t',
'2')) AND (a.intkey IN (1))")); //$NON-NLS-1$
+ }
+
+ public void testUnlimitedIn() throws Exception {
+ helpTestDependentJoin(true);
+ }
+
+ private HardcodedDataManager helpTestDependentJoin(boolean unlimitIn)
+ throws QueryParserException, QueryResolverException,
+ QueryValidatorException, MetaMatrixComponentException {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+ if (unlimitIn) {
+ caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, -1);
+ }
capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
@@ -511,8 +530,8 @@
new String[] {"SELECT
g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0 WHERE g_0.intkey IN (<dependent
values>)", "SELECT g_0.stringkey, g_0.intkey FROM bqt2.smallb AS g_0"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
- 1, // Access
- 1, // DependentAccess
+ unlimitIn?2:1, // Access
+ unlimitIn?0:1, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
@@ -540,9 +559,8 @@
};
TestProcessor.helpProcess(plan, dataManager, expected);
-
- assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey,
a.intkey FROM bqt2.smalla AS a WHERE (concat(a.stringkey, 't') IN ('1t',
'2')) AND (a.intkey IN (1))")); //$NON-NLS-1$
- }
+ return dataManager;
+ }
static void sampleData4(FakeDataManager dataMgr) throws Exception {
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
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-09-28
21:11:23 UTC (rev 1488)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java 2009-09-29
13:52:23 UTC (rev 1489)
@@ -22,15 +22,15 @@
package com.metamatrix.query.processor.relational;
+import java.util.Arrays;
+
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.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.FakeDataManager;
+import com.metamatrix.query.processor.TestProcessor;
import com.metamatrix.query.resolver.TestResolver;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.CompoundCriteria;
@@ -57,14 +57,18 @@
CommandContext context = new CommandContext();
context.setProcessorID("processorID"); //$NON-NLS-1$
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
- FakePDM dataManager = new FakePDM(expectedCommand);
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
node.initialize(context, bm, dataManager);
node.setShouldEvaluateExpressions(true);
// Call open()
node.open();
-
- assertEquals(shouldRegisterRequest, dataManager.registerRequestCalled);
+ if (shouldRegisterRequest) {
+ assertEquals(Arrays.asList(expectedCommand), dataManager.getQueries());
+ } else {
+ assertEquals(0, dataManager.getQueries().size());
+ }
}
public void testOpen_Defect16059() throws Exception {
@@ -91,31 +95,14 @@
CommandContext context = new CommandContext();
context.setProcessorID("processorID"); //$NON-NLS-1$
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
- FakePDM dataManager = new FakePDM("SELECT e1, e2 FROM pm1.g1 WHERE e2 =
5"); //$NON-NLS-1$
+ FakeDataManager dataManager = new FakeDataManager();
+ TestProcessor.sampleData1(dataManager);
node.initialize(context, bm, dataManager);
// Call open()
node.open();
- assertTrue(dataManager.registerRequestCalled);
+ assertEquals(Arrays.asList("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5"),
dataManager.getQueries()); //$NON-NLS-1$
}
- private final static class FakePDM implements ProcessorDataManager {
- private String expectedCommand;
- private boolean registerRequestCalled = false;
- private FakePDM(String command) {
- this.expectedCommand = command;
- }
- public Object lookupCodeValue(CommandContext context,String codeTableName,String
returnElementName,String keyElementName,Object keyValue) throws
BlockedException,MetaMatrixComponentException {return null;}
- public TupleSource registerRequest(Object processorID,Command command,String
modelName,String connectorBindingId, int nodeID) throws MetaMatrixComponentException {
- registerRequestCalled = true;
- assertEquals(expectedCommand, command.toString());
- return null;
- }
- @Override
- public void clearCodeTables() {
-
- }
- }
-
public void testShouldExecuteUpdate() throws Exception {
Update update = new Update();