Author: shawkins
Date: 2011-12-15 14:34:02 -0500 (Thu, 15 Dec 2011)
New Revision: 3745
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1870 fix to ensure non deterministic functions are pushdown as expected
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java 2011-12-15
16:26:57 UTC (rev 3744)
+++
branches/7.6.x/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java 2011-12-15
19:34:02 UTC (rev 3745)
@@ -69,7 +69,7 @@
public void visit(Function obj) {
this.setDeterminismLevel(obj.getFunctionDescriptor().getDeterministic());
- if (obj.getFunctionDescriptor().getPushdown() == PushDown.MUST_PUSHDOWN) {
+ if (obj.getFunctionDescriptor().getPushdown() == PushDown.MUST_PUSHDOWN ||
obj.getFunctionDescriptor().getDeterministic() == Determinism.NONDETERMINISTIC) {
evaluationNotPossible(EvaluationLevel.PUSH_DOWN);
} else if (obj.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)
//TODO: if we had the context here we could plan better for non-prepared
requests
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-12-15
16:26:57 UTC (rev 3744)
+++
branches/7.6.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-12-15
19:34:02 UTC (rev 3745)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
@@ -170,9 +171,10 @@
Insert insert = (Insert)command;
TupleSource ts = insert.getTupleSource();
if (ts == null) {
+ Evaluator eval = new Evaluator(Collections.emptyMap(), this, context);
List<Object> values = new
ArrayList<Object>(insert.getValues().size());
for (Expression expr : (List<Expression>)insert.getValues()) {
- values.add(Evaluator.evaluate(expr));
+ values.add(eval.evaluate(expr, null));
}
ts = new CollectionTupleSource(Arrays.asList(values).iterator());
}
Modified:
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
---
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-12-15
16:26:57 UTC (rev 3744)
+++
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-12-15
19:34:02 UTC (rev 3745)
@@ -103,6 +103,7 @@
import org.teiid.query.util.CommandContext;
import org.teiid.query.validator.Validator;
import org.teiid.query.validator.ValidatorReport;
+import org.teiid.translator.SourceSystemFunctions;
@SuppressWarnings({"nls", "unchecked"})
public class TestProcessor {
@@ -7683,5 +7684,28 @@
}
+ @Test public void testNonDeterministicPushdown() throws Exception {
+ // Create query
+ String sql = "SELECT RAND(), lookup('pm1.g1', 'e1',
'e2', 1) FROM pm1.g1 limit 2"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(new Double(0.1), "a"),
+ Arrays.asList(new Double(0.2), "a"),
+ };
+
+ // Construct data manager with data
+ HardcodedDataManager hdm = new HardcodedDataManager();
+ hdm.addData("SELECT RAND() FROM pm1.g1", expected);
+ hdm.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new
List<?>[] {Arrays.asList(1, "a")});
+ BasicSourceCapabilities bsc = new BasicSourceCapabilities();
+ bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+ bsc.setFunctionSupport(SourceSystemFunctions.RAND, true);
+ // Plan query
+ CommandContext cc = createCommandContext();
+ ProcessorPlan plan = helpGetPlan(helpParse(sql),
RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
+
+ helpProcess(plan, cc, hdm, expected);
+ }
+
private static final boolean DEBUG = false;
}
Show replies by date