Search in sources :

Example 61 with Command

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

the class TestJoinNode method testPrefetchDistinct.

@Test
public void testPrefetchDistinct() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e2 from pm1.g1 as a, (select e1, e2 from pm2.g2 union select 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<?>[2];
    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<?>[2];
    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);
    context.setBufferManager(mgr);
    TestProcessor.helpProcess(plan, context, hdm, new List<?>[] { Arrays.asList("0", 0), Arrays.asList("0", 1), Arrays.asList("1", 0), Arrays.asList("1", 1) });
}
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)

Example 62 with Command

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

the class TestProcessor method helpGetPlan.

public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata, CapabilitiesFinder finder) {
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n####################################\n" + sql);
    Command command = helpParse(sql);
    ProcessorPlan process = helpGetPlan(command, metadata, finder);
    return process;
}
Also used : Command(org.teiid.query.sql.lang.Command)

Example 63 with Command

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

the class TestProcessor method testPushdownLiteralInSelectWithOrderBy.

@Test
public void testPushdownLiteralInSelectWithOrderBy() {
    String sql = // $NON-NLS-1$
    "SELECT 1, concat('a', 'b' ) AS X FROM BQT1.SmallA where intkey = 0 " + // $NON-NLS-1$
    "UNION ALL " + // $NON-NLS-1$
    "select 2, 'Hello2' from BQT1.SmallA where intkey = 1 order by X desc";
    // Create expected results - would expect these to be:
    // 1, "ab"
    // 2, "Hello2"
    // but our fake tuple source is too dumb to return anything reasonable, so instead get:
    List[] expected = new List[] { Arrays.asList(new Object[] { null, null }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataBQTSmall(dataManager);
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    caps.setCapabilitySupport(Capability.QUERY_UNION, true);
    caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    // Run query
    helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 64 with Command

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

the class TestProcessor method testCase5413.

@Test
public void testCase5413() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Plan query
    // $NON-NLS-1$
    String sql = "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 0) = e1";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    CommandContext context = createCommandContext();
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
    // Run query
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "a" }) };
    FakeDataManager dataManager = new FakeDataManager();
    FakeDataStore.sampleData2(dataManager);
    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) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 65 with Command

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

the class TestProcedureResolving method testDefect13029_CorrectlySetUpdateProcedureTempGroupIDs.

@Test
public void testDefect13029_CorrectlySetUpdateProcedureTempGroupIDs() throws Exception {
    StringBuffer proc = // $NON-NLS-1$
    new StringBuffer("FOR EACH ROW").append(// $NON-NLS-1$
    "\nBEGIN").append(// $NON-NLS-1$
    "\nDECLARE string var1;").append(// $NON-NLS-1$
    "\nvar1 = '';").append(// $NON-NLS-1$
    "\n  LOOP ON (SELECT pm1.g1.e1 FROM pm1.g1) AS loopCursor").append(// $NON-NLS-1$
    "\n  BEGIN").append(// $NON-NLS-1$
    "\n    LOOP ON (SELECT pm1.g2.e1 FROM pm1.g2 WHERE loopCursor.e1 = pm1.g2.e1) AS loopCursor2").append(// $NON-NLS-1$
    "\n    BEGIN").append(// $NON-NLS-1$
    "\n      var1 = CONCAT(var1, CONCAT(' ', loopCursor2.e1));").append(// $NON-NLS-1$
    "\n    END").append(// $NON-NLS-1$
    "\n  END").append(// $NON-NLS-1$
    "\nEND");
    // $NON-NLS-1$
    String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
    Command command = helpResolveUpdateProcedure(proc.toString(), userUpdateStr, Table.TriggerEvent.UPDATE);
    Map<String, TempMetadataID> tempIDs = command.getTemporaryMetadata().getData();
    assertNotNull(tempIDs);
    // $NON-NLS-1$
    assertNull(tempIDs.get("LOOPCURSOR"));
    // $NON-NLS-1$
    assertNull(tempIDs.get("LOOPCURSOR2"));
    Command subCommand = CommandCollectorVisitor.getCommands(command).get(0);
    tempIDs = subCommand.getTemporaryMetadata().getData();
    assertNotNull(tempIDs);
    // $NON-NLS-1$
    assertNull(tempIDs.get("LOOPCURSOR"));
    // $NON-NLS-1$
    assertNull(tempIDs.get("LOOPCURSOR2"));
    subCommand = CommandCollectorVisitor.getCommands(command).get(1);
    tempIDs = subCommand.getTemporaryMetadata().getData();
    assertNotNull(tempIDs);
    // $NON-NLS-1$
    assertNotNull(tempIDs.get("LOOPCURSOR"));
    // $NON-NLS-1$
    assertNull(tempIDs.get("LOOPCURSOR2"));
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) TempMetadataID(org.teiid.query.metadata.TempMetadataID) 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