use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryDoNotRewriteToJoin3.
@Test
public void testSubqueryDoNotRewriteToJoin3() throws Exception {
CommandContext cc = new CommandContext();
cc.setOptions(new Options().subqueryUnnestDefault(true));
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 <> e3)", "SELECT e1 FROM pm3.g1 WHERE e2 < SOME (SELECT MAX(pm1.g1.e2) FROM pm1.g1 WHERE e3 <> pm3.g1.e3)", RealMetadataFactory.example4(), cc);
// should rewrite as we have an equi join predicate
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 = e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(pm1.g1.e2) AS expr1, e3 FROM pm1.g1 GROUP BY e3) AS X__1 WHERE (e2 < X__1.expr1) AND (pm3.g1.e3 = X__1.e3)", RealMetadataFactory.example4(), cc);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testProjectSubqueryPushdown.
/*
* Expressions containing subqueries can be pushed down
*/
@Test
public void testProjectSubqueryPushdown() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
BasicSourceCapabilities caps = getTypicalCapabilities();
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);
// $NON-NLS-1$
caps.setFunctionSupport("+", true);
// $NON-NLS-1$
caps.setFunctionSupport("convert", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
ProcessorPlan plan = helpPlan(// $NON-NLS-1$
"select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", // $NON-NLS-1$
metadata, null, capFinder, new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0), integer) + 1) FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
assertNotNull(plan.getDescriptionProperties().getProperty("Query Subplan 0"));
HardcodedDataManager hcdm = new HardcodedDataManager(true);
hcdm.addData("SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0", Arrays.asList("13"));
hcdm.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0", Arrays.asList("10"), Arrays.asList("13"));
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(metadata);
TestProcessor.helpProcess(plan, cc, hcdm, new List<?>[] { Arrays.asList("10", 14), Arrays.asList("13", 14) });
caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR_PROJECTION, true);
plan = helpPlan(// $NON-NLS-1$
"select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", // $NON-NLS-1$
metadata, 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" }, // $NON-NLS-1$
SHOULD_SUCCEED);
checkNodeTypes(plan, FULL_PUSHDOWN);
assertNull(plan.getDescriptionProperties().getProperty("Query Subplan 0"));
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryRewriteToJoinWithAggregate2.
@Test
public void testSubqueryRewriteToJoinWithAggregate2() throws Exception {
CommandContext cc = new CommandContext();
cc.setOptions(new Options().subqueryUnnestDefault(true));
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 = e1 HAVING min(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1, MIN(e3) AS expr3 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.expr3 < pm3.g1.e3) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryProducingBuffer.
@Test
public void testSubqueryProducingBuffer() throws Exception {
TransformationMetadata tm = RealMetadataFactory.example1Cached();
String sql = "SELECT e1, (select e2 from pm2.g1 where e1 = pm1.g1.e1 order by e2 limit 1) from pm1.g1 limit 1";
BasicSourceCapabilities bsc = getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager hdm = new HardcodedDataManager(tm) {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (command.toString().equals("SELECT g_0.e2 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'a'")) {
return new TupleSource() {
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
throw new TeiidProcessingException("something's wrong");
}
@Override
public void closeSource() {
}
};
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
hdm.setBlockOnce(true);
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(tm);
try {
TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
fail();
} catch (TeiidProcessingException e) {
assert (e.getMessage().contains("something's wrong"));
}
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryDoNotRewriteToJoin.
@Test
public void testSubqueryDoNotRewriteToJoin() throws Exception {
CommandContext cc = new CommandContext();
cc.setOptions(new Options().subqueryUnnestDefault(true));
TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where not exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1 WHERE NOT EXISTS (SELECT pm1.g1.e1 FROM pm1.g1 WHERE e1 = pm3.g1.e1 LIMIT 1)", RealMetadataFactory.example4(), cc);
}
Aggregations