Search in sources :

Example 11 with TupleBuffer

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

the class LanguageBridgeFactory method translate.

org.teiid.language.Comparison translate(DependentSetCriteria criteria) {
    Operator operator = Operator.EQ;
    org.teiid.language.Expression arg = null;
    final TupleBuffer tb = criteria.getDependentValueSource().getTupleBuffer();
    if (criteria.getValueExpression() instanceof Array) {
        Array array = (Array) criteria.getValueExpression();
        List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>();
        Class<?> baseType = null;
        for (Expression ex : array.getExpressions()) {
            if (baseType == null) {
                baseType = ex.getType();
            } else if (!baseType.equals(ex.getType())) {
                baseType = DataTypeManager.DefaultDataClasses.OBJECT;
            }
            params.add(createParameter(criteria, tb, ex));
        }
        arg = new org.teiid.language.Array(baseType, params);
    } else {
        Expression ex = criteria.getValueExpression();
        arg = createParameter(criteria, tb, ex);
    }
    if (this.dependentSets == null) {
        this.dependentSets = new HashMap<String, List<? extends List<?>>>();
    }
    this.dependentSets.put(criteria.getContextSymbol(), new TupleBufferList(tb));
    Comparison result = new org.teiid.language.Comparison(translate(criteria.getExpression()), arg, operator);
    return result;
}
Also used : Operator(org.teiid.language.Comparison.Operator) TupleBuffer(org.teiid.common.buffer.TupleBuffer) org.teiid.language(org.teiid.language) Array(org.teiid.query.sql.symbol.Array) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Expression(org.teiid.query.sql.symbol.Expression)

Example 12 with TupleBuffer

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

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

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

Example 15 with TupleBuffer

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

the class FakeRelationalNode method getBufferDirect.

@Override
protected TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
    TupleBuffer tb = Mockito.mock(TupleBuffer.class);
    Mockito.stub(tb.getRowCount()).toReturn((long) (maxRows != -1 ? Math.min(maxRows, data.length) : data.length));
    return tb;
}
Also used : TupleBuffer(org.teiid.common.buffer.TupleBuffer)

Aggregations

TupleBuffer (org.teiid.common.buffer.TupleBuffer)43 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)19 BufferManager (org.teiid.common.buffer.BufferManager)16 List (java.util.List)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)11 BlockedException (org.teiid.common.buffer.BlockedException)10 TupleSource (org.teiid.common.buffer.TupleSource)10 CommandContext (org.teiid.query.util.CommandContext)7 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)6 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TupleBatch (org.teiid.common.buffer.TupleBatch)4 Map (java.util.Map)3 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)3 Expression (org.teiid.query.sql.symbol.Expression)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 IndexedTupleSource (org.teiid.common.buffer.IndexedTupleSource)2