Search in sources :

Example 6 with CommandContext

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

the class TestOptimizer method helpGetCommand.

public static Command helpGetCommand(String sql, QueryMetadataInterface md, List<String> bindings) throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n####################################\n" + sql);
    Command command = null;
    if (bindings != null && !bindings.isEmpty()) {
        command = TestResolver.helpResolveWithBindings(sql, md, bindings);
    } else {
        command = QueryParser.getQueryParser().parseCommand(sql);
        QueryResolver.resolveCommand(command, md);
    }
    ValidatorReport repo = Validator.validate(command, md);
    Collection<LanguageObject> failures = new ArrayList<LanguageObject>();
    repo.collectInvalidObjects(failures);
    if (failures.size() > 0) {
        // $NON-NLS-1$
        fail("Exception during validation (" + repo);
    }
    // rewrite
    command = QueryRewriter.rewrite(command, md, new CommandContext());
    return command;
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) ArrayList(java.util.ArrayList) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 7 with CommandContext

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

the class TestOptimizer method testInvalidSource.

@Test(expected = QueryPlannerException.class)
public void testInvalidSource() throws Exception {
    // $NON-NLS-1$
    String sql = "select * from pm1.g1";
    QueryMetadataInterface md = RealMetadataFactory.example1Cached();
    QueryOptimizer.optimizePlan(helpGetCommand(sql, md, null), md, null, new DefaultCapabilitiesFinder() {

        @Override
        public boolean isValid(String modelName) {
            return false;
        }
    }, null, new CommandContext());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 8 with CommandContext

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

the class TestJoinOptimization method testMergeJoinOrderNotPushed1.

/**
 * Same as above but using the system/option property
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
@Test
public void testMergeJoinOrderNotPushed1() throws Exception {
    String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey " + // $NON-NLS-1$
    "from bqt1.smalla inner join bqt2.smalla on (bqt2.smalla.stringkey = bqt1.smalla.stringkey)";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.getOptions().setAssumeMatchingCollation(false);
    // Plan query
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestOptimizer.helpGetCommand(sql, RealMetadataFactory.exampleBQTCached(), null), RealMetadataFactory.exampleBQTCached(), new DefaultCapabilitiesFinder(bsc), cc);
    HardcodedDataManager hdm = new HardcodedDataManager();
    hdm.addData("SELECT g_0.StringKey, g_0.IntKey FROM BQT1.SmallA AS g_0", Arrays.asList("b", 1), Arrays.asList("a", 3));
    hdm.addData("SELECT g_0.StringKey, g_0.IntKey FROM BQT2.SmallA AS g_0", Arrays.asList("c", 1), Arrays.asList("a", 2));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(3, 2) });
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 9 with CommandContext

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

the class TestSubqueryPushdown method testSubqueryRewriteToJoinDistinct.

@Test
public void testSubqueryRewriteToJoinDistinct() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select distinct e1 from pm1.g1 as x where exists (select pm1.g1.e1 FROM pm1.g1 where e1 = x.e1)", "SELECT DISTINCT e1 FROM pm1.g1 AS x, (SELECT e1 FROM pm1.g1) AS X__1 WHERE x.e1 = X__1.e1", RealMetadataFactory.example1Cached(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 10 with CommandContext

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

the class TestSubqueryPushdown method testSubqueryRewriteToJoinWithAggregate.

@Test
public void testSubqueryRewriteToJoinWithAggregate() 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)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1 FROM pm1.g1 GROUP BY e1) AS X__1 WHERE (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)

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