Search in sources :

Example 6 with BufferManager

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

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

the class TestProcessor method helpProcessException.

private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
    TupleBuffer tsId = null;
    BufferManager bufferMgr = null;
    try {
        bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
        // $NON-NLS-1$ //$NON-NLS-2$
        CommandContext context = new CommandContext("0", "test", null, null, 1);
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        tsId = collector.collectTuples();
        // $NON-NLS-1$
        fail("Expected error during processing, but got none.");
    } catch (TeiidException e) {
        // ignore - this is expected
        if (expectedErrorMessage != null) {
            assertEquals(expectedErrorMessage, e.getMessage());
        }
    } finally {
        if (tsId != null) {
            tsId.remove();
        }
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) TeiidException(org.teiid.core.TeiidException)

Example 8 with BufferManager

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

the class TestTempTables method testDeleteRemovingPage.

@Test
public void testDeleteRemovingPage() throws Exception {
    helpTestDelete();
    // test under other buffer scenarios - with restricted memory / small batch
    FakeDataManager fdm = new FakeDataManager();
    TestProcessor.sampleData1(fdm);
    BufferManager bm = BufferManagerFactory.getTestBufferManager(100000, 10);
    setUp(RealMetadataFactory.example1Cached(), fdm, bm);
    helpTestDelete();
    // with restricted memory / normal batch
    bm = BufferManagerFactory.getTestBufferManager(100000, 250);
    setUp(RealMetadataFactory.example1Cached(), fdm, bm);
    helpTestDelete();
}
Also used : BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 9 with BufferManager

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

the class TestTempTables method testInherentUpdateUsingTemp.

@Test
public void testInherentUpdateUsingTemp() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table g1 (e1 string primary key, e2 integer, e3 boolean, e4 double, FOREIGN KEY (e1) REFERENCES G2 (e1)) options (updatable true);" + " create foreign table g2 (e1 string primary key, e2 integer, e3 boolean, e4 double) options (updatable true);" + " create view v options (updatable true) as select g2.e1, g1.e2 from g1 inner join g2 on g1.e1 = g2.e1;", "x", "pm1");
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    setUp(metadata, hdm);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    cache.setTupleBufferCache(bm);
    dataManager = new TempTableDataManager(hdm, bm, cache);
    // $NON-NLS-1$
    execute("create temporary table x (e1 string, e2 integer, e3 string, primary key (e1))", new List[] { Arrays.asList(0) });
    execute("insert into x values ('a', 1, 'b')", new List[] { Arrays.asList(1) });
    TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x");
    // ensure that we're using the actual metadata
    assertNotNull(id);
    assertNotNull(this.metadata.getPrimaryKey(id));
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 = 1", new List[] { Arrays.asList("a") });
    hdm.addData("DELETE FROM g1 WHERE g1.e1 = 'a'", new List[] { Arrays.asList(1) });
    // $NON-NLS-1$
    execute("delete from v where e2 = (select max(e2) from x as z where e3 = z.e3)", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TempMetadataID(org.teiid.query.metadata.TempMetadataID) BufferManager(org.teiid.common.buffer.BufferManager) CachedResults(org.teiid.dqp.internal.process.CachedResults) Test(org.junit.Test)

Example 10 with BufferManager

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

the class TestVirtualDepJoin method helpTestMultipleBatches.

private void helpTestMultipleBatches(boolean unique) throws Exception, TeiidComponentException, TeiidException, SQLException {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT * from Master.Transactions where last = 'Davis' order by CustomerID, TransactionID";
    List<List<Object>> expected = new LinkedList<List<Object>>();
    // Create expected results
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(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$
    expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }));
    if (!unique) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }));
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(207), new Integer(3), new BigDecimal("12.34") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(299), new Integer(3), new BigDecimal("950.34") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1004), new Integer(3), new BigDecimal("542.20") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1005), new Integer(1), new BigDecimal("99.99") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1006), new Integer(1), new BigDecimal("10000.00") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1007), new Integer(2), new BigDecimal("0.75") }));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(630), new Long(1008), new Integer(2), new BigDecimal("62.00") }));
    // Construct data manager with data
    QueryMetadataInterface metadata = exampleVirtualDepJoin();
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataVirtualDepJoin(dataManager, metadata);
    overrideVirtualDepJoinData(dataManager, metadata, unique);
    // Plan query
    CommandContext context = TestProcessor.createCommandContext();
    Command command = TestProcessor.helpParse(sql);
    FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
    // $NON-NLS-1$
    finder.addCapabilities("US", caps);
    // $NON-NLS-1$
    finder.addCapabilities("Europe", caps);
    // $NON-NLS-1$
    finder.addCapabilities("CustomerMaster", caps);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
    // Run query
    BufferManager bufferMgr = createCustomBufferMgr(2);
    QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
    processor.setNonBlocking(true);
    BatchCollector collector = processor.createBatchCollector();
    TupleBuffer id = collector.collectTuples();
    TestProcessor.examineResults(expected.toArray(new List[expected.size()]), bufferMgr, id);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) LinkedList(java.util.LinkedList) 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)

Aggregations

BufferManager (org.teiid.common.buffer.BufferManager)46 Test (org.junit.Test)32 List (java.util.List)23 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)22 CommandContext (org.teiid.query.util.CommandContext)18 ArrayList (java.util.ArrayList)17 TupleBuffer (org.teiid.common.buffer.TupleBuffer)16 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)8 BlockedException (org.teiid.common.buffer.BlockedException)6 BigDecimal (java.math.BigDecimal)5 TupleSource (org.teiid.common.buffer.TupleSource)5 CachedResults (org.teiid.dqp.internal.process.CachedResults)5 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)5 FakeTupleSource (org.teiid.query.processor.FakeTupleSource)5 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)5 TupleBatch (org.teiid.common.buffer.TupleBatch)4 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ClobImpl (org.teiid.core.types.ClobImpl)2 ClobType (org.teiid.core.types.ClobType)2