use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestOptimizer method helpGetCommand.
public static Command helpGetCommand(String sql, QueryMetadataInterface md, List<String> bindings) throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
if (DEBUG)
System.out.println("\n####################################\n" + sql);
Command command = null;
if (bindings != null && !bindings.isEmpty()) {
command = TestResolver.helpResolveWithBindings(sql, md, bindings);
} else {
command = QueryParser.getQueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, md);
}
ValidatorReport repo = Validator.validate(command, md);
Collection<LanguageObject> failures = new ArrayList<LanguageObject>();
repo.collectInvalidObjects(failures);
if (failures.size() > 0) {
// $NON-NLS-1$
fail("Exception during validation (" + repo);
}
// rewrite
command = QueryRewriter.rewrite(command, md, new CommandContext());
return command;
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestOptimizer method testInvalidSource.
@Test(expected = QueryPlannerException.class)
public void testInvalidSource() throws Exception {
// $NON-NLS-1$
String sql = "select * from pm1.g1";
QueryMetadataInterface md = RealMetadataFactory.example1Cached();
QueryOptimizer.optimizePlan(helpGetCommand(sql, md, null), md, null, new DefaultCapabilitiesFinder() {
@Override
public boolean isValid(String modelName) {
return false;
}
}, null, new CommandContext());
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestJoinOptimization method testMergeJoinOrderNotPushed1.
/**
* Same as above but using the system/option property
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
@Test
public void testMergeJoinOrderNotPushed1() throws Exception {
String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey " + // $NON-NLS-1$
"from bqt1.smalla inner join bqt2.smalla on (bqt2.smalla.stringkey = bqt1.smalla.stringkey)";
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
CommandContext cc = TestProcessor.createCommandContext();
cc.getOptions().setAssumeMatchingCollation(false);
// Plan query
ProcessorPlan plan = TestProcessor.helpGetPlan(TestOptimizer.helpGetCommand(sql, RealMetadataFactory.exampleBQTCached(), null), RealMetadataFactory.exampleBQTCached(), new DefaultCapabilitiesFinder(bsc), cc);
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT g_0.StringKey, g_0.IntKey FROM BQT1.SmallA AS g_0", Arrays.asList("b", 1), Arrays.asList("a", 3));
hdm.addData("SELECT g_0.StringKey, g_0.IntKey FROM BQT2.SmallA AS g_0", Arrays.asList("c", 1), Arrays.asList("a", 2));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(3, 2) });
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryRewriteToJoinDistinct.
@Test
public void testSubqueryRewriteToJoinDistinct() throws Exception {
CommandContext cc = new CommandContext();
cc.setOptions(new Options().subqueryUnnestDefault(true));
TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1)", "SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example1Cached(), cc);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryRewriteToJoinWithAggregate.
@Test
public void testSubqueryRewriteToJoinWithAggregate() 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)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc);
}
Aggregations