Search in sources :

Example 11 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryDoNotRewriteToJoin3.

@Test
public void testSubqueryDoNotRewriteToJoin3() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 <> e3)", "SELECT e1 FROM pm3.g1 WHERE e2 < SOME (SELECT MAX(pm1.g1.e2) FROM pm1.g1 WHERE e3 <> pm3.g1.e3)", RealMetadataFactory.example4(), cc);
    // should rewrite as we have an equi join predicate
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where e2 < some (select pm1.g1.e2 FROM pm1.g1 where pm3.g1.e3 = e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(pm1.g1.e2) AS expr1, e3 FROM pm1.g1 GROUP BY e3) AS X__1 WHERE (e2 < X__1.expr1) AND (pm3.g1.e3 = X__1.e3)", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 12 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testProjectSubqueryPushdown.

/*
     * Expressions containing subqueries can be pushed down
     */
@Test
public void testProjectSubqueryPushdown() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    BasicSourceCapabilities caps = getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
    // $NON-NLS-1$
    caps.setFunctionSupport("+", true);
    // $NON-NLS-1$
    caps.setFunctionSupport("convert", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    ProcessorPlan plan = helpPlan(// $NON-NLS-1$
    "select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", // $NON-NLS-1$
    metadata, null, capFinder, new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0), integer) + 1) FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    assertNotNull(plan.getDescriptionProperties().getProperty("Query Subplan 0"));
    HardcodedDataManager hcdm = new HardcodedDataManager(true);
    hcdm.addData("SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0", Arrays.asList("13"));
    hcdm.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0", Arrays.asList("10"), Arrays.asList("13"));
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    TestProcessor.helpProcess(plan, cc, hcdm, new List<?>[] { Arrays.asList("10", 14), Arrays.asList("13", 14) });
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR_PROJECTION, true);
    plan = helpPlan(// $NON-NLS-1$
    "select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", // $NON-NLS-1$
    metadata, null, capFinder, new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1), integer) + 1) FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    SHOULD_SUCCEED);
    checkNodeTypes(plan, FULL_PUSHDOWN);
    assertNull(plan.getDescriptionProperties().getProperty("Query Subplan 0"));
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 13 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryRewriteToJoinWithAggregate2.

@Test
public void testSubqueryRewriteToJoinWithAggregate2() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (select max(e2) FROM pm1.g1 WHERE pm3.g1.e1 = e1 HAVING min(e3) < pm3.g1.e3)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1, MIN(e3) AS expr3 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (X__1.expr3 < pm3.g1.e3) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 14 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryProducingBuffer.

@Test
public void testSubqueryProducingBuffer() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String sql = "SELECT e1, (select e2 from pm2.g1 where e1 = pm1.g1.e1 order by e2 limit 1) from pm1.g1 limit 1";
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hdm = new HardcodedDataManager(tm) {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command.toString().equals("SELECT g_0.e2 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'a'")) {
                return new TupleSource() {

                    @Override
                    public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                        throw new TeiidProcessingException("something's wrong");
                    }

                    @Override
                    public void closeSource() {
                    }
                };
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
    hdm.setBlockOnce(true);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(tm);
    try {
        TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
        fail();
    } catch (TeiidProcessingException e) {
        assert (e.getMessage().contains("something's wrong"));
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 15 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryDoNotRewriteToJoin.

@Test
public void testSubqueryDoNotRewriteToJoin() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where not exists (select pm1.g1.e1 FROM pm1.g1 where e1 = pm3.g1.e1)", "SELECT e1 FROM pm3.g1 WHERE NOT EXISTS (SELECT pm1.g1.e1 FROM pm1.g1 WHERE e1 = pm3.g1.e1 LIMIT 1)", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11