Search in sources :

Example 6 with FakeFunctionMetadataSource

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") });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Example 7 with FakeFunctionMetadataSource

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);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Example 8 with FakeFunctionMetadataSource

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
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) TeiidComponentException(org.teiid.core.TeiidComponentException) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 9 with FakeFunctionMetadataSource

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") });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Example 10 with FakeFunctionMetadataSource

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);
}
Also used : FunctionTree(org.teiid.query.function.FunctionTree) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Aggregations

FakeFunctionMetadataSource (org.teiid.query.optimizer.FakeFunctionMetadataSource)10 Test (org.junit.Test)9 FunctionTree (org.teiid.query.function.FunctionTree)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)7 CommandContext (org.teiid.query.util.CommandContext)3 ArrayList (java.util.ArrayList)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)1 QueryNode (org.teiid.query.mapping.relational.QueryNode)1 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)1 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)1 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)1 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)1 XMLQuery (org.teiid.query.sql.symbol.XMLQuery)1