use of org.teiid.query.optimizer.FakeFunctionMetadataSource in project teiid by teiid.
the class TestFunctionPushdown method testMustPushdownOverMultipleSourcesWithView.
@Test
public void testMustPushdownOverMultipleSourcesWithView() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport("misc.namespace.func", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
// $NON-NLS-1$
String sql = "select func(x.e1) from (select x.* from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2 order by e1 limit 10) as x";
ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1, g_0.e1 AS c_2 FROM pm1.g1 AS g_0 ORDER BY c_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1) });
dataManager.addData("SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1, g_0.e1 AS c_2 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1, "aa", "a"), Arrays.asList(2, "bb", "b") });
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(metadata);
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("aa") });
}
use of org.teiid.query.optimizer.FakeFunctionMetadataSource in project teiid by teiid.
the class TestFunctionPushdown method testMustPushdownOverMultipleSourcesWithoutSupport.
@Test
public void testMustPushdownOverMultipleSourcesWithoutSupport() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
// $NON-NLS-1$
String sql = "select func(x.e1) from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2";
helpPlan(sql, metadata, null, capFinder, new String[] {}, // $NON-NLS-1$
ComparisonMode.FAILED_PLANNING);
}
use of org.teiid.query.optimizer.FakeFunctionMetadataSource 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.query.optimizer.FakeFunctionMetadataSource in project teiid by teiid.
the class TestFunctionPushdown method testMustPushdownOverMultipleSources.
@Test
public void testMustPushdownOverMultipleSources() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport("misc.namespace.func", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
// $NON-NLS-1$
String sql = "select func(x.e1) from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2";
ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1, "a") });
dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1), Arrays.asList(2) });
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(metadata);
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("a") });
}
use of org.teiid.query.optimizer.FakeFunctionMetadataSource in project teiid by teiid.
the class TestQueryRewriter method testUDFParse.
@Test
public void testUDFParse() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
String sql = "parsedate_(pm1.g1.e1) = {d'2001-01-01'}";
helpTestRewriteCriteria(sql, parseCriteria(sql, metadata), metadata);
}
Aggregations