Search in sources :

Example 1 with PreparedPlan

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

Example 2 with PreparedPlan

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

Example 3 with PreparedPlan

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
    }
}
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 4 with PreparedPlan

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") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) 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) DDLHolder(org.teiid.query.unittest.RealMetadataFactory.DDLHolder) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 5 with PreparedPlan

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;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)

Aggregations

PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)11 CommandContext (org.teiid.query.util.CommandContext)8 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6 Test (org.junit.Test)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)5 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)5 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)4 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 NamedThreadFactory (org.teiid.core.util.NamedThreadFactory)2 CachedResults (org.teiid.dqp.internal.process.CachedResults)2 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1