Search in sources :

Example 6 with TupleSource

use of org.teiid.common.buffer.TupleSource in project teiid by teiid.

the class TestAsyncTupleSource method testTupleSource.

@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
    AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {

        @Override
        public TupleSource call() throws Exception {
            return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
        }
    }, new CommandContext());
    for (int i = 0; i < 20; i++) {
        try {
            assertEquals(Arrays.asList(1), ats.nextTuple());
            break;
        } catch (BlockedException e) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
            }
        }
    }
    assertEquals(Arrays.asList(2), ats.nextTuple());
    assertNull(ats.nextTuple());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) BlockedException(org.teiid.common.buffer.BlockedException) BlockedException(org.teiid.common.buffer.BlockedException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 7 with TupleSource

use of org.teiid.common.buffer.TupleSource in project teiid by teiid.

the class TestProcessor method doProcess.

public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
    BufferManager bufferMgr = context.getBufferManager();
    if (bufferMgr == null) {
        BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
        bm.setProcessorBatchSize(context.getProcessorBatchSize());
        context.setBufferManager(bm);
        bufferMgr = bm;
    }
    context.getNextRand(0);
    if (context.getTempTableStore() == null) {
        context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
    }
    if (context.getGlobalTableStore() == null) {
        GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
        context.setGlobalTableStore(gts);
    }
    if (!(dataManager instanceof TempTableDataManager)) {
        SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
        cache.setTupleBufferCache(bufferMgr);
        dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
    }
    if (context.getQueryProcessorFactory() == null) {
        context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
    }
    TupleBuffer id = null;
    long rowCount = 0;
    try {
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        // processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        for (int i = 0; i < 100; i++) {
            try {
                id = collector.collectTuples();
                break;
            } catch (BlockedException e) {
            }
        }
        if (id == null) {
            fail("did not complete processing");
        }
        rowCount = id.getRowCount();
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("\nResults:\n" + id.getSchema());
            TupleSource ts2 = id.createIndexedTupleSource();
            for (int j = 0; j < rowCount; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$
                System.out.println("" + j + ": " + ts2.nextTuple());
            }
        }
        if (expectedResults != null) {
            examineResults(expectedResults, bufferMgr, id);
        }
    } finally {
        if (id != null) {
            id.remove();
        }
    }
    return rowCount;
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) BlockedException(org.teiid.common.buffer.BlockedException) CachedResults(org.teiid.dqp.internal.process.CachedResults) TupleSource(org.teiid.common.buffer.TupleSource) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) QueryProcessorFactoryImpl(org.teiid.dqp.internal.process.QueryProcessorFactoryImpl)

Example 8 with TupleSource

use of org.teiid.common.buffer.TupleSource 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)

Example 9 with TupleSource

use of org.teiid.common.buffer.TupleSource 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 10 with TupleSource

use of org.teiid.common.buffer.TupleSource in project teiid by teiid.

the class TestInsertProcessing method testInsertTriggerWithTypeChanges.

@Test
public void testInsertTriggerWithTypeChanges() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE SmallA (IntKey integer PRIMARY KEY,         StringKey string,         IntNum integer,         StringNum string,         FloatNum float,         LongNum bigint,         DoubleNum double,         ByteNum smallint,         DateValue date,         TimeValue time,         TimestampValue timestamp,         BooleanValue boolean,         CharValue char(1),         ShortValue smallint,         BigIntegerValue decimal,         BigDecimalValue decimal,         ObjectValue blob)     OPTIONS (UPDATABLE 'TRUE'); " + " CREATE VIEW SmallAV (IntKey integer PRIMARY KEY,     StringKey string,     IntNum integer,     StringNum string,     FloatNum float,     LongNum long,     DoubleNum double,     ByteNum byte,     DateValue date,     TimeValue time,     TimestampValue timestamp,     BooleanValue boolean,     CharValue char,     ShortValue short,     BigIntegerValue biginteger,     BigDecimalValue bigdecimal,     ObjectValue object) OPTIONS (UPDATABLE 'TRUE') AS SELECT IntKey, StringKey, IntNum,     StringNum, FloatNum, LongNum, DoubleNum,     convert(ByteNum, byte) AS ByteNum, DateValue, TimeValue, TimestampValue,     BooleanValue, CharValue, ShortValue,     convert(BigIntegerValue, biginteger) AS BigIntegerValue, BigDecimalValue,     convert(ObjectValue, object) AS ObjectValue FROM SmallA; " + " CREATE TRIGGER ON SmallAV INSTEAD OF INSERT AS FOR EACH ROW BEGIN ATOMIC     INSERT INTO smalla (IntKey, StringKey, IntNum, StringNum, FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue, BigIntegerValue, BigDecimalValue, ObjectValue) VALUES         (NEW.IntKey, NEW.StringKey, NEW.IntNum, NEW.StringNum, NEW.FloatNum, NEW.LongNum, NEW.DoubleNum, NEW.ByteNum, NEW.DateValue, NEW.TimeValue, NEW.TimestampValue,         NEW.BooleanValue, NEW.CharValue, NEW.ShortValue, NEW.BigIntegerValue, NEW.BigDecimalValue, to_bytes(convert(NEW.ObjectValue, string), 'UTF-8')); END;", "x", "y");
    // $NON-NLS-1$
    String sql = "INSERT INTO smallav (IntKey, IntNum) VALUES (1, null), (2, 2)";
    List<?>[] expected = new List[] { Arrays.asList(1) };
    final List[] secondResult = new List[] { Arrays.asList(2, null, 2, null, null, null, null, null, null, null, null, null, null, null, null, null, null) };
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            TupleSource ts = ((Insert) command).getTupleSource();
            try {
                List<?> tuple = ts.nextTuple();
                assertEquals(Arrays.asList(1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), tuple);
                tuple = ts.nextTuple();
                assertEquals(secondResult[0], tuple);
                assertNull(ts.nextTuple());
            } catch (TeiidProcessingException e) {
                throw new TeiidRuntimeException(e);
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    dataManager.addData("INSERT INTO smalla (IntKey, StringKey, IntNum, StringNum, FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue, BigIntegerValue, BigDecimalValue, ObjectValue) VALUES (...)", Arrays.asList(2));
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, true);
    ProcessorPlan plan = helpGetPlan(sql, tm, new DefaultCapabilitiesFinder(bsc));
    helpProcess(plan, dataManager, expected);
    sql = "INSERT INTO smallav (IntKey, CharValue) VALUES (1, null), (2, convert('+', char))";
    plan = helpGetPlan(sql, tm, new DefaultCapabilitiesFinder(bsc));
    secondResult[0] = Arrays.asList(2, null, null, null, null, null, null, null, null, null, null, null, '+', null, null, null, null);
    helpProcess(plan, dataManager, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Insert(org.teiid.query.sql.lang.Insert) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TupleSource(org.teiid.common.buffer.TupleSource) List(java.util.List) Test(org.junit.Test)

Aggregations

TupleSource (org.teiid.common.buffer.TupleSource)31 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)11 Test (org.junit.Test)10 TupleBuffer (org.teiid.common.buffer.TupleBuffer)10 CommandContext (org.teiid.query.util.CommandContext)10 List (java.util.List)9 BlockedException (org.teiid.common.buffer.BlockedException)9 TeiidProcessingException (org.teiid.core.TeiidProcessingException)9 Command (org.teiid.query.sql.lang.Command)9 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 ArrayList (java.util.ArrayList)6 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)6 BufferManager (org.teiid.common.buffer.BufferManager)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)4 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)3