Search in sources :

Example 56 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestVirtualDepJoin method testVirtualDepJoinPartialPushdown.

@Test
public void testVirtualDepJoinPartialPushdown() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT * from Master.Transactions where last = 'Davis'";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }) };
    // Construct data manager with data
    QueryMetadataInterface metadata = exampleVirtualDepJoin();
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataVirtualDepJoin(dataManager, metadata);
    // Plan query
    CommandContext context = TestProcessor.createCommandContext();
    Command command = TestProcessor.helpParse(sql);
    FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
    BasicSourceCapabilities caps2 = TestOptimizer.getTypicalCapabilities();
    caps2.setCapabilitySupport(Capability.CRITERIA_IN, false);
    // $NON-NLS-1$
    finder.addCapabilities("US", caps1);
    // $NON-NLS-1$
    finder.addCapabilities("Europe", caps2);
    // $NON-NLS-1$
    finder.addCapabilities("CustomerMaster", caps1);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    3, // Select
    1, // Sort
    0, // UnionAll
    1 });
    TestOptimizer.checkDependentJoinCount(plan, 1);
    // Run query
    TestProcessor.helpProcess(plan, context, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) BigDecimal(java.math.BigDecimal) Command(org.teiid.query.sql.lang.Command) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 57 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestVirtualDepJoin method testVirtualDepJoinNoValues.

@Test
public void testVirtualDepJoinNoValues() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first=-9999 group by c.id, first, last";
    // Create expected results
    List[] expected = new List[] {};
    // Construct data manager with data
    QueryMetadataInterface metadata = exampleVirtualDepJoin();
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataVirtualDepJoin(dataManager, metadata);
    // Plan query
    CommandContext context = TestProcessor.createCommandContext();
    Command command = TestProcessor.helpParse(sql);
    FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
    // $NON-NLS-1$
    finder.addCapabilities("Europe", caps);
    // $NON-NLS-1$
    finder.addCapabilities("CustomerMaster", caps);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
    TestOptimizer.checkDependentJoinCount(plan, 1);
    // Run query
    TestProcessor.helpProcess(plan, context, dataManager, expected);
    // Second query *will not be run* as no values were passed and dependent side has always false criteria
    // So, the list should contain only the first query
    assertEquals(3, dataManager.getQueries().size());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 58 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestWithClauseProcessing method testSingleItemInOn.

@Test
public void testSingleItemInOn() {
    // $NON-NLS-1$
    String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1 limit 1) SELECT pm2.g1.e1 from pm2.g1 left outer join pm2.g2 on (pm2.g1.e2 = pm2.g2.e2 and pm2.g1.e1 = (select a.x from a))";
    List[] expected = new List[] { Arrays.asList("a") };
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        boolean block = true;

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (block) {
                block = false;
                throw BlockedException.INSTANCE;
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    dataManager.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0", new List[] { Arrays.asList("a") });
    dataManager.addData("SELECT g_0.e1 FROM pm2.g1 AS g_0 LEFT OUTER JOIN pm2.g2 AS g_1 ON g_0.e2 = g_1.e2 AND g_0.e1 = 'a'", new List[] { Arrays.asList("a") });
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
    bsc.setCapabilitySupport(Capability.CRITERIA_ON_SUBQUERY, true);
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc));
    helpProcess(plan, dataManager, expected);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 59 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestOrderByRewrite method getCommand.

private static Command getCommand(String sql) throws TeiidComponentException, TeiidProcessingException {
    Command command = QueryParser.getQueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached());
    return QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), null);
}
Also used : Command(org.teiid.query.sql.lang.Command)

Example 60 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestJoinNode method testDupRemoveUnderJoin.

@Test
public void testDupRemoveUnderJoin() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e2 from pm1.g1 as a, (select distinct e1, e2 from pm2.g2) as b";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
    HardcodedDataManager hdm = new HardcodedDataManager() {

        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            final TupleSource source = super.registerRequest(context, command, modelName, parameterObject);
            return new TupleSource() {

                private int block;

                @Override
                public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                    if (block++ % 2 == 0) {
                        throw BlockedException.INSTANCE;
                    }
                    return source.nextTuple();
                }

                @Override
                public void closeSource() {
                    source.closeSource();
                }
            };
        }
    };
    List<?>[] rows = new List<?>[1];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i));
    }
    hdm.addData("SELECT pm1.g1.e1 FROM pm1.g1", rows);
    rows = new List<?>[1025];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i), i);
    }
    hdm.addData("SELECT pm2.g2.e1, pm2.g2.e2 FROM pm2.g2", rows);
    BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(1, 2);
    mgr.setTargetBytesPerRow(100);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List<?>[] results = new List<?>[1025];
    for (int i = 0; i < results.length; i++) {
        results[i] = Arrays.asList("0", i);
    }
    TestProcessor.helpProcess(plan, context, hdm, results);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10