Search in sources :

Example 36 with BlockedException

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

the class TempTableDataManager method loadGlobalTable.

private TupleSource loadGlobalTable(final CommandContext context, final GroupSymbol group, final String tableName, final GlobalTableStore globalStore) throws TeiidComponentException, TeiidProcessingException {
    LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30013, tableName));
    final QueryMetadataInterface metadata = context.getMetadata();
    final List<ElementSymbol> allColumns = ResolverUtil.resolveElementsInGroup(group, metadata);
    final TempTable table = globalStore.createMatTable(tableName, group);
    table.setUpdatable(false);
    return new ProxyTupleSource() {

        TupleSource insertTupleSource;

        boolean success;

        QueryProcessor qp;

        boolean closed;

        boolean errored;

        @Override
        protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
            long rowCount = -1;
            try {
                if (insertTupleSource == null) {
                    String fullName = metadata.getFullName(group.getMetadataID());
                    String transformation = metadata.getVirtualPlan(group.getMetadataID()).getQuery();
                    qp = context.getQueryProcessorFactory().createQueryProcessor(transformation, fullName, context);
                    insertTupleSource = new BatchCollector.BatchProducerTupleSource(qp);
                }
                table.insert(insertTupleSource, allColumns, false, false, null);
                table.getTree().compact();
                rowCount = table.getRowCount();
                Determinism determinism = qp.getContext().getDeterminismLevel();
                context.setDeterminismLevel(determinism);
                // TODO: could pre-process indexes to remove overlap
                for (Object index : metadata.getIndexesInGroup(group.getMetadataID())) {
                    List<ElementSymbol> columns = GlobalTableStoreImpl.resolveIndex(metadata, allColumns, index);
                    table.addIndex(columns, false);
                }
                for (Object key : metadata.getUniqueKeysInGroup(group.getMetadataID())) {
                    List<ElementSymbol> columns = GlobalTableStoreImpl.resolveIndex(metadata, allColumns, key);
                    table.addIndex(columns, true);
                }
                CacheHint hint = table.getCacheHint();
                if (hint != null && table.getPkLength() > 0) {
                    table.setUpdatable(hint.isUpdatable(false));
                }
                if (determinism.compareTo(Determinism.VDB_DETERMINISTIC) < 0 && (hint == null || hint.getScope() == null || Scope.VDB.compareTo(hint.getScope()) <= 0)) {
                    // $NON-NLS-1$
                    LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31143, determinism, tableName));
                }
                globalStore.loaded(tableName, table);
                success = true;
                LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30014, tableName, rowCount));
                return CollectionTupleSource.createUpdateCountTupleSource((int) Math.min(Integer.MAX_VALUE, rowCount));
            } catch (BlockedException e) {
                throw e;
            } catch (Exception e) {
                errored = true;
                if (executor == null || !executor.isShutdown()) {
                    // if we're shutting down, no need to log
                    LogManager.logError(LogConstants.CTX_MATVIEWS, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30015, tableName));
                }
                closeSource();
                rethrow(e);
                throw new AssertionError();
            }
        }

        @Override
        public void closeSource() {
            if (closed) {
                return;
            }
            if (!errored && !success) {
                LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31153, tableName));
            }
            closed = true;
            if (!success) {
                globalStore.failedLoad(tableName);
                table.remove();
            }
            if (qp != null) {
                qp.closeProcessing();
            }
            super.closeSource();
        }
    };
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Determinism(org.teiid.metadata.FunctionMethod.Determinism) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) QueryProcessingException(org.teiid.api.exception.query.QueryProcessingException) TeiidComponentException(org.teiid.core.TeiidComponentException) TransformationException(org.teiid.core.types.TransformationException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) BlockedException(org.teiid.common.buffer.BlockedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) BatchCollector(org.teiid.query.processor.BatchCollector)

Example 37 with BlockedException

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

the class TestBatchIterator method testNoSaveForwardOnly.

@Test
public void testNoSaveForwardOnly() throws Exception {
    BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2) {

        @Override
        public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
            TupleBatch tb = super.nextBatchDirect();
            tb.setRowOffset(tb.getBeginRow() + 3);
            return tb;
        }
    });
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
    tb.setForwardOnly(true);
    // $NON-NLS-1$
    bi.setBuffer(tb, false);
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(2));
    assertEquals(3, bi.getBuffer().getManagedRowCount());
    bi.nextTuple();
    // pull the first batch
    assertEquals(2, bi.available());
    assertEquals(0, bi.getBuffer().getManagedRowCount());
    for (int i = 0; i < 2; i++) {
        assertNotNull(bi.nextTuple());
        assertEquals(0, bi.getBuffer().getManagedRowCount());
    }
    bi.readAhead(3);
    assertEquals(2, bi.getBuffer().getManagedRowCount());
    for (int i = 0; i < 4; i++) {
        assertNotNull(bi.nextTuple());
        assertEquals(0, bi.getBuffer().getManagedRowCount());
    }
    assertNull(bi.nextTuple());
    assertEquals(0, bi.getBuffer().getManagedRowCount());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 38 with BlockedException

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

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

the class TestGroupingNode method helpProcess.

private void helpProcess(BufferManager mgr, GroupingNode node, CommandContext context, List[] expected, FakeTupleSource dataSource, ProcessorDataManager dataMgr) throws TeiidComponentException, BlockedException, TeiidProcessingException {
    RelationalNode dataNode = new FakeRelationalNode(0, dataSource, mgr.getProcessorBatchSize());
    dataNode.setElements(dataSource.getSchema());
    node.addChild(dataNode);
    node.initialize(context, mgr, dataMgr);
    node.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = node.nextBatch();
            for (int row = currentRow; row <= batch.getEndRow(); row++) {
                List tuple = batch.getTuple(row);
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + row, expected[row - 1], tuple);
            }
            currentRow += batch.getRowCount();
            if (batch.getTerminationFlag()) {
                break;
            }
        } catch (BlockedException e) {
        // ignore
        }
    }
    assertEquals(expected.length, currentRow - 1);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 40 with BlockedException

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

the class TestJoinNode method testSortMergeWithDistinct.

@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
    this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
    this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
    expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List leftElements = Arrays.asList(es1, es2);
    leftNode = new BlockingFakeRelationalNode(1, leftTuples);
    leftNode.setElements(leftElements);
    // $NON-NLS-1$
    ElementSymbol es3 = new ElementSymbol("e3");
    es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es4 = new ElementSymbol("e4");
    es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List rightElements = Arrays.asList(es3, es4);
    rightNode = new BlockingFakeRelationalNode(2, rightTuples) {

        @Override
        public boolean hasBuffer() {
            return false;
        }

        @Override
        public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
            fail();
            throw new AssertionError();
        }
    };
    rightNode.setElements(rightElements);
    List joinElements = new ArrayList();
    joinElements.addAll(leftElements);
    joinElements.addAll(rightElements);
    joinType = JoinType.JOIN_INNER;
    joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
    join = new JoinNode(3);
    join.setElements(joinElements);
    join.setJoinType(joinType);
    join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
    join.setJoinStrategy(joinStrategy);
    helpTestJoinDirect(expected, 100, 100000);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ArrayList(java.util.ArrayList) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) Test(org.junit.Test)

Aggregations

BlockedException (org.teiid.common.buffer.BlockedException)45 TupleBatch (org.teiid.common.buffer.TupleBatch)16 ArrayList (java.util.ArrayList)15 List (java.util.List)15 TeiidProcessingException (org.teiid.core.TeiidProcessingException)15 TeiidComponentException (org.teiid.core.TeiidComponentException)13 TupleBuffer (org.teiid.common.buffer.TupleBuffer)10 CommandContext (org.teiid.query.util.CommandContext)10 TupleSource (org.teiid.common.buffer.TupleSource)8 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 Test (org.junit.Test)6 BufferManager (org.teiid.common.buffer.BufferManager)6 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)5 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)5 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)5 Command (org.teiid.query.sql.lang.Command)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)4 SQLException (java.sql.SQLException)3 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)3