Search in sources :

Example 31 with BufferManager

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

the class TestTempTables method testForeignTemp.

@Test
public void testForeignTemp() throws Exception {
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    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 foreign temporary table x (e1 string options (nameinsource 'a'), e2 integer, e3 string, primary key (e1)) options (cardinality 1000, updatable true, \"other\" 'prop') on pm1", new List[] { Arrays.asList(0) });
    TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x");
    // ensure that we're using the actual metadata
    assertNotNull(id);
    assertNotNull(this.metadata.getPrimaryKey(id));
    assertEquals(1000, this.metadata.getCardinality(id), 0);
    assertEquals("pm1", this.metadata.getName(this.metadata.getModelID(id)));
    assertEquals("prop", this.metadata.getExtensionProperty(id, "other", false));
    hdm.addData("SELECT x.a, x.e2, x.e3 FROM x", new List[] { Arrays.asList(1, 2, "3") });
    // $NON-NLS-1$
    execute("select * from x", new List[] { Arrays.asList(1, 2, "3") });
    hdm.addData("SELECT g_0.e2 AS c_0, g_0.e3 AS c_1, g_0.a AS c_2 FROM x AS g_0 ORDER BY c_1, c_0", new List[] { Arrays.asList(2, "3", "1") });
    hdm.addData("SELECT g_0.e3, g_0.e2 FROM x AS g_0", new List[] { Arrays.asList("3", 2) });
    hdm.addData("DELETE FROM x WHERE x.a = '1'", new List[] { Arrays.asList(1) });
    // ensure compensation behaves as if physical - not temp
    // $NON-NLS-1$
    execute("delete from x where e2 = (select max(e2) from x as z where e3 = x.e3)", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0, x AS g_1 WHERE g_1.a = g_0.e1", new List[] { Arrays.asList(1) });
    // ensure pushdown support
    // $NON-NLS-1$
    execute("select g1.e1 from pm1.g1 g1, x where x.e1 = g1.e1", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
    try {
        // $NON-NLS-1$
        execute("create local temporary table x (e1 string)", new List[] { Arrays.asList(0) });
        fail();
    } catch (QueryResolverException e) {
    }
    // ensure that drop works
    execute("drop table x", new List[] { Arrays.asList(0) });
    try {
        execute("drop table x", new List[] { Arrays.asList(0) });
        fail();
    } catch (QueryResolverException e) {
    }
}
Also used : 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) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 32 with BufferManager

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

the class TestQueryProcessor method helpTestProcessor.

public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults) throws TeiidException {
    BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "group", null, null, 1);
    QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
    BatchCollector collector = processor.createBatchCollector();
    TupleBuffer tsID = null;
    while (true) {
        try {
            tsID = collector.collectTuples();
            break;
        } catch (BlockedException e) {
        }
    }
    // Compare # of rows in actual and expected
    // $NON-NLS-1$
    assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount());
    // Compare actual with expected results
    TupleSource actual = tsID.createIndexedTupleSource();
    if (expectedResults.length > 0) {
        for (int i = 0; i < expectedResults.length; i++) {
            List actRecord = actual.nextTuple();
            List expRecord = expectedResults[i];
            // $NON-NLS-1$
            assertEquals("Did not match row at row index " + i, expRecord, actRecord);
        }
    }
    tsID.remove();
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException)

Example 33 with BufferManager

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

the class TestAccessNode method helpTestOpen.

private void helpTestOpen(Command command, String expectedCommand, boolean shouldRegisterRequest) throws Exception {
    // Setup
    AccessNode node = new AccessNode(1);
    node.setCommand(command);
    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    node.setElements(command.getProjectedSymbols());
    node.initialize(context, bm, dataManager);
    node.setShouldEvaluateExpressions(true);
    // Call open()
    node.open();
    if (shouldRegisterRequest) {
        assertEquals(Arrays.asList(expectedCommand), dataManager.getQueries());
    } else {
        assertEquals(0, dataManager.getQueries().size());
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) BufferManager(org.teiid.common.buffer.BufferManager)

Example 34 with BufferManager

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

the class TestGroupingNode method test2.

@Test
public void test2() throws Exception {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    GroupingNode node = getExampleGroupingNode();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(1) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2) }) };
    helpProcess(mgr, node, context, expected, null);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 35 with BufferManager

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

the class TestGroupingNode method testDupSort.

@Test
public void testDupSort() throws Exception {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    GroupingNode node = getExampleGroupingNode();
    node.setRemoveDuplicates(true);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(1) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2) }) };
    helpProcess(mgr, node, context, expected, null);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

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