use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestWithClauseProcessing method testRecursivePushdown.
@Test
public void testRecursivePushdown() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
String sql = "WITH t(n) AS ( select e2 from pm1.g1 UNION SELECT n+1 FROM t WHERE n < 64 ) SELECT n FROM t";
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
bsc.setCapabilitySupport(Capability.RECURSIVE_COMMON_TABLE_EXPRESSIONS, true);
bsc.setFunctionSupport("+", true);
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "WITH t (n) AS (SELECT g_0.e2 FROM pm1.g1 AS g_0 UNION SELECT (g_0.n + 1) FROM t AS g_0 WHERE g_0.n < 64) SELECT g_0.n FROM t AS g_0" }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestWithClauseProcessing method testScalarInlining.
@Test
public void testScalarInlining() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
String sql = "WITH t(n) AS ( select 1 ) SELECT n FROM t as t1, pm1.g1";
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT 1 FROM pm1.g1 AS g_0" }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestFunctionPushdown method testSimpleFunctionPushdown.
@Test
public void testSimpleFunctionPushdown() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer)", "x", "y");
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select func(1)";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2) });
// ensure that pseudo-correlation works
// $NON-NLS-1$
sql = "select func(0) from g1 where func(e1) = 2";
plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1 FROM y.g1" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager();
dataManager.addData("SELECT y.g1.e1 FROM y.g1", new List[] { Arrays.asList(1), Arrays.asList(2) });
dataManager.addData("SELECT func(0)", new List[] { Arrays.asList(1) });
dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
dataManager.addData("SELECT func(2)", new List[] { Arrays.asList(3) });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1) });
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
// ensure that pseudo-correlation works
// $NON-NLS-1$
sql = "select case when hasrole('x') then func(0) else 2 end from g1";
plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT func(0) FROM y.g1" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT func(0) FROM g1", new List[] { Arrays.asList(1), Arrays.asList(1) });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1), Arrays.asList(1) });
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestFunctionPushdown method testMustPushdownSubexpressionOverGrouping.
@Test
public void testMustPushdownSubexpressionOverGrouping() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer, e2 integer)", "x", "y");
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select max(func(e2)) from g1 group by e1";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1, func(y.g1.e2) FROM y.g1" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT y.g1.e1, func(y.g1.e2) FROM y.g1", new List[] { Arrays.asList(1, 2), Arrays.asList(2, 3) });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2), Arrays.asList(3) });
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestFunctionPushdown method testSimpleFunctionPushdown1.
@Test
public void testSimpleFunctionPushdown1() throws Exception {
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
bsc.setFunctionSupport("parseDate_", true);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select parseDate_('2011-11-11')";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT parsedate_('2011-11-11')", new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
cc.setDQPWorkContext(RealMetadataFactory.buildWorkContext(tm));
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
// $NON-NLS-1$
sql = "select misc.namespace.func('2011-11-11')";
plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT parseDate_('2011-11-11')", new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
try {
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
fail();
} catch (TeiidProcessingException e) {
// not supported by any source
}
}
Aggregations