Search in sources :

Example 36 with BufferManager

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

the class TestGroupingNode method helpTestEmptyGroup.

public void helpTestEmptyGroup(boolean groupBy) throws Exception {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    ElementSymbol col1 = new ElementSymbol("col1");
    col1.setType(Integer.class);
    // $NON-NLS-1$
    ElementSymbol bigDecimal = new ElementSymbol("value");
    bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
    // Set up
    GroupingNode node = new GroupingNode(1);
    List outputElements = new ArrayList();
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("SUM", false, bigDecimal));
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("AVG", false, bigDecimal));
    node.setElements(outputElements);
    // Set grouping elements to null
    if (groupBy) {
        List groupingElements = new ArrayList();
        // $NON-NLS-1$
        groupingElements.add(col1.clone());
        node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List[] data = new List[] {};
    List[] expected = new List[] { Arrays.asList(new Object[] { null, null }) };
    if (groupBy) {
        expected = new List[] {};
    }
    List symbols = new ArrayList();
    symbols.add(col1);
    symbols.add(bigDecimal);
    FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
    helpProcess(mgr, node, context, expected, dataSource, null);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager)

Example 37 with BufferManager

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

the class TestGroupingNode method testdefect9842.

@Test
public void testdefect9842() throws Exception {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    ElementSymbol col1 = new ElementSymbol("col1");
    col1.setType(Integer.class);
    // $NON-NLS-1$
    ElementSymbol bigDecimal = new ElementSymbol("value");
    bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
    // Set up
    GroupingNode node = new GroupingNode(1);
    List outputElements = new ArrayList();
    outputElements.add(col1);
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("SUM", false, bigDecimal));
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("AVG", false, bigDecimal));
    node.setElements(outputElements);
    // Set grouping elements to null
    List groupingElements = new ArrayList();
    groupingElements.add(col1);
    node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List[] data = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(1), new BigDecimal("0.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(1), new BigDecimal("1.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(2), new BigDecimal("2.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(2), new BigDecimal("3.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(2), new BigDecimal("4.0") }) };
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(1), new BigDecimal("1.0"), new BigDecimal(.5) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new Integer(2), new BigDecimal("9.0"), new BigDecimal("3.0") }) };
    List symbols = new ArrayList();
    symbols.add(col1);
    symbols.add(bigDecimal);
    FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
    helpProcess(mgr, node, context, expected, dataSource, null);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 38 with BufferManager

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

the class TestProjectIntoNode method helpTestNextBatch.

private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {
    ProjectIntoNode node = new ProjectIntoNode(2);
    TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
    RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
    node.addChild(child);
    // $NON-NLS-1$
    node.setIntoGroup(new GroupSymbol("myGroup"));
    // $NON-NLS-1$
    ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1");
    // $NON-NLS-1$
    ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2");
    elementSymbol_1.setType(Integer.class);
    elementSymbol_2.setType(String.class);
    List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
    node.setIntoElements(elements);
    child.setElements(elements);
    node.setMode(mode);
    // $NON-NLS-1$
    node.setModelName("myModel");
    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
    ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);
    child.initialize(context, bm, dataManager);
    node.initialize(context, bm, dataManager);
    node.open();
    TupleBatch batch = null;
    // Do the remaining batches
    while (true) {
        try {
            batch = node.nextBatch();
            break;
        } catch (BlockedException e) {
        // Normal
        }
    }
    assertNotNull(batch);
    List[] tuples = batch.getAllTuples();
    assertEquals(1, tuples.length);
    Object[] columns = tuples[0].toArray();
    assertNotNull(columns);
    assertEquals(1, columns.length);
    // Should have inserted all rows
    assertEquals(new Integer(NUM_ROWS), columns[0]);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) CommandContext(org.teiid.query.util.CommandContext) ProcessorDataManager(org.teiid.query.processor.ProcessorDataManager) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) List(java.util.List) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 39 with BufferManager

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

the class TestSelectNode method helpTestSelect.

private void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child, SelectNode selectNode) throws TeiidComponentException, TeiidProcessingException {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    child.setElements(childElements);
    child.initialize(context, mgr, dataMgr);
    selectNode.setCriteria(criteria);
    selectNode.setElements(elements);
    selectNode.addChild(child);
    selectNode.initialize(context, mgr, dataMgr);
    selectNode.open();
    BatchIterator iterator = new BatchIterator(selectNode);
    for (int i = 0; i < expected.length; i++) {
        while (true) {
            try {
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + i, expected[i], iterator.nextTuple());
                break;
            } catch (BlockedException e) {
                continue;
            }
        }
    }
    assertFalse(iterator.hasNext());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BatchIterator(org.teiid.query.processor.BatchIterator) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException)

Example 40 with BufferManager

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

the class TestSortNode method testSortLimit.

@Test
public void testSortLimit() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR);
    tsid.addTuple(Arrays.asList(4));
    tsid.addTuple(Arrays.asList(3));
    tsid.addTuple(Arrays.asList(2));
    tsid.addTuple(Arrays.asList(1));
    tsid.close();
    // $NON-NLS-1$
    SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    su.setBatchSize(2);
    TupleBuffer out = su.sort(2);
    TupleSource ts = out.createIndexedTupleSource();
    assertEquals(Arrays.asList(1), ts.nextTuple());
    assertEquals(Arrays.asList(2), ts.nextTuple());
    assertNull(ts.nextTuple());
    // $NON-NLS-1$
    su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
    su.setBatchSize(10);
    out = su.sort(2);
    ts = out.createIndexedTupleSource();
    assertEquals(Arrays.asList(1), ts.nextTuple());
    assertEquals(Arrays.asList(2), ts.nextTuple());
    assertNull(ts.nextTuple());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) 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