use of org.teiid.dqp.internal.process.PreparedPlan 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.dqp.internal.process.PreparedPlan 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.dqp.internal.process.PreparedPlan 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
}
}
use of org.teiid.dqp.internal.process.PreparedPlan in project teiid by teiid.
the class TestFunctionPushdown method testSimpleFunctionPushdown2.
@Test
public void testSimpleFunctionPushdown2() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "CREATE FOREIGN FUNCTION func(a object, b object) RETURNS string;"), new DDLHolder("z", "CREATE FOREIGN FUNCTION func1(a object, b object) RETURNS string; create foreign table g1 (e1 object)"));
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, 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 e1 from g1 where func(1, 1) = '2'";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT func(1, 1)", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] {});
// $NON-NLS-1$
sql = "select e1 from g1 where func1(1, 1) = '2'";
plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func1(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT g1.e1 FROM g1 WHERE func1(1, 1) = '2'", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("hello world") });
}
use of org.teiid.dqp.internal.process.PreparedPlan in project teiid by teiid.
the class TestInherintlyUpdatableViews method helpTest.
private Command helpTest(String userSql, String viewSql, String expectedSql, ProcessorDataManager dm) throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView(viewSql, metadata, "gx");
Command command = TestQueryRewriter.helpTestRewriteCommand(userSql, expectedSql, metadata);
if (dm != null) {
CommandContext context = createCommandContext();
SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
// $NON-NLS-1$
context.setPreparedPlanCache(planCache);
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
ProcessorPlan plan = helpGetPlan(helpParse(userSql), metadata, new DefaultCapabilitiesFinder(caps), context);
List<?>[] expected = new List[] { Arrays.asList(1) };
helpProcess(plan, context, dm, expected);
assertEquals(0, planCache.getTotalCacheEntries());
}
return command;
}
Aggregations