Search in sources :

Example 26 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestWithClauseProcessing method testWithImplicitIndexing.

@Test
public void testWithImplicitIndexing() throws Exception {
    // $NON-NLS-1$
    String sql = "with a (x, y, z) as /*+ no_inline */ (select e1, e2, e3 from pm1.g1) select (select max(x) from a where y = pm1.g2.e2), pm1.g2.* from pm1.g2";
    HardcodedDataManager dataManager = new HardcodedDataManager();
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached());
    List<?>[] rows = new List<?>[20480];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i), i);
    }
    dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", rows);
    rows = new List<?>[20480];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList("a", i, true, 1.1);
    }
    dataManager.addData("SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2", rows);
    List<?>[] expected = new List[20480];
    for (int i = 0; i < rows.length; i++) {
        expected[i] = Arrays.asList(String.valueOf(i), "a", i, true, 1.1);
    }
    CommandContext cc = createCommandContext();
    BufferManagerImpl bm = (BufferManagerImpl) cc.getBufferManager();
    long reads = bm.getReadAttempts();
    helpProcess(plan, cc, dataManager, expected);
    reads = bm.getReadAttempts() - reads;
    assertTrue(reads < 500000);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) List(java.util.List) Test(org.junit.Test)

Example 27 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestGroupingNode method helpTestLookupFunctionInAggregate.

private void helpTestLookupFunctionInAggregate(int batchSize) throws Exception {
    BufferManagerImpl mgr = BufferManagerFactory.createBufferManager();
    mgr.setProcessorBatchSize(batchSize);
    // Set up
    GroupingNode node = new GroupingNode(1);
    List outputElements = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol col1 = new ElementSymbol("col1");
    col1.setType(Integer.class);
    // $NON-NLS-1$
    ElementSymbol col2 = new ElementSymbol("col2");
    col2.setType(Integer.class);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), col2 });
    // $NON-NLS-1$
    FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
    func.setFunctionDescriptor(desc);
    func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    outputElements.add(col1);
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("COUNT", false, func));
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("SUM", false, func));
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("SUM", true, func));
    node.setElements(outputElements);
    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);
    FakeDataManager dataMgr = new FakeDataManager();
    dataMgr.setThrowBlocked(true);
    Map valueMap = new HashMap();
    valueMap.put(new Integer(0), new Integer(1));
    valueMap.put(new Integer(1), new Integer(2));
    valueMap.put(new Integer(2), new Integer(3));
    valueMap.put(new Integer(3), new Integer(4));
    valueMap.put(new Integer(4), new Integer(5));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
    List[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(1), new Long(4), new Long(4) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1), new Long(5), new Long(5) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1), new Long(3), new Long(3) }), Arrays.asList(new Object[] { new Integer(2), new Integer(4), new Long(9), new Long(5) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1), new Long(1), new Long(1) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2), new Long(7), new Long(7) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1), new Long(4), new Long(4) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2), new Long(9), new Long(9) }) };
    helpProcess(mgr, node, context, expected, dataMgr);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) HashMap(java.util.HashMap) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Function(org.teiid.query.sql.symbol.Function) AggregateFunction(org.teiid.query.function.aggregate.AggregateFunction) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 28 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestJoinNode method testEnhancedWithLimit.

@Test
public void testEnhancedWithLimit() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e2 from pm1.g1 as a, pm2.g2 as b where a.e1 = b.e1 limit 10";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
    HardcodedDataManager hdm = new HardcodedDataManager();
    List<?>[] rows = new List<?>[50];
    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<?>[200];
    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);
    rows = new List<?>[10];
    for (int i = 0; i < rows.length; i++) {
        rows[i] = Arrays.asList(String.valueOf(i), i);
    }
    TestProcessor.helpProcess(plan, context, hdm, rows);
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 29 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestJoinNode method helpTestJoinDirect.

public void helpTestJoinDirect(List[] expectedResults, int batchSize, int processingBytes) throws TeiidComponentException, TeiidProcessingException {
    BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(processingBytes, batchSize);
    mgr.setTargetBytesPerRow(100);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    join.addChild(leftNode);
    join.addChild(rightNode);
    leftNode.initialize(context, mgr, dataMgr);
    rightNode.initialize(context, mgr, dataMgr);
    join.initialize(context, mgr, dataMgr);
    process(expectedResults);
    join.reset();
    process(expectedResults);
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext)

Example 30 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestJoinNode method testEnhancedWithSortDistinct.

@Test
public void testEnhancedWithSortDistinct() 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 where a.e1 = b.e1";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
    HardcodedDataManager hdm = new HardcodedDataManager();
    List<?>[] rows = new List<?>[10];
    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<?>[10];
    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, rows);
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)34 Test (org.junit.Test)24 CommandContext (org.teiid.query.util.CommandContext)13 List (java.util.List)11 ArrayList (java.util.ArrayList)8 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 RequestMessage (org.teiid.client.RequestMessage)6 ResultsMessage (org.teiid.client.ResultsMessage)5 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)5 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)4 TupleSource (org.teiid.common.buffer.TupleSource)3 BufferFrontedFileStoreCache (org.teiid.common.buffer.impl.BufferFrontedFileStoreCache)3 FileStorageManager (org.teiid.common.buffer.impl.FileStorageManager)3 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)3 Command (org.teiid.query.sql.lang.Command)3 BufferServiceImpl (org.teiid.services.BufferServiceImpl)3 HashMap (java.util.HashMap)2 BlockedException (org.teiid.common.buffer.BlockedException)2 BufferManager (org.teiid.common.buffer.BufferManager)2 TupleBatch (org.teiid.common.buffer.TupleBatch)2