Search in sources :

Example 1 with BlockedException

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

the class TestDataTierManager method testPartialResults.

@Test
public void testPartialResults() throws Exception {
    DataTierTupleSource info = helpSetup(1);
    connectorManager.throwExceptionOnExecute = true;
    for (int i = 0; i < 10; i++) {
        try {
            assertNull(info.nextTuple());
            SourceWarning warning = (SourceWarning) context.getAndClearWarnings().get(0);
            assertTrue(warning.isPartialResultsError());
            return;
        } catch (BlockedException e) {
            Thread.sleep(50);
        }
    }
    fail();
}
Also used : SourceWarning(org.teiid.client.SourceWarning) BlockedException(org.teiid.common.buffer.BlockedException) Test(org.junit.Test)

Example 2 with BlockedException

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

the class ComplexDocumentFilter method matches.

@Override
public boolean matches(Map<String, Object> parentProperties, Map<String, Object> childProperties) throws TranslatorException {
    try {
        List<Object> tuple = new ArrayList<>();
        int i = 0;
        for (Column column : parentTable.getMetadataObject().getColumns()) {
            tuple.add(i++, parentProperties.get(MarshallerBuilder.getDocumentAttributeName(column, false, metadata)));
        }
        for (Column column : childTable.getMetadataObject().getColumns()) {
            tuple.add(i++, childProperties.get(MarshallerBuilder.getDocumentAttributeName(column, true, metadata)));
        }
        org.teiid.query.util.CommandContext cc = new org.teiid.query.util.CommandContext();
        final Evaluator evaluator = new Evaluator(elementMap, null, cc);
        return evaluator.evaluate(criteria, tuple);
    } catch (ExpressionEvaluationException e) {
        throw new TranslatorException(e);
    } catch (BlockedException e) {
        throw new TranslatorException(e);
    } catch (TeiidComponentException e) {
        throw new TranslatorException(e);
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) BlockedException(org.teiid.common.buffer.BlockedException) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 3 with BlockedException

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

the class SortUtility method onePassSort.

public List<TupleBuffer> onePassSort(boolean lowLatency) throws TeiidComponentException, TeiidProcessingException {
    boolean success = false;
    try {
        if (this.phase == INITIAL_SORT) {
            initialSort(true, lowLatency, -1);
            if (!isDoneReading()) {
                this.phase = INITIAL_SORT;
            }
        }
        for (TupleBuffer tb : activeTupleBuffers) {
            tb.close();
            // it is up to the caller to set the flag now
            tb.setForwardOnly(false);
        }
        success = true;
        return activeTupleBuffers;
    } catch (BlockedException e) {
        success = true;
        throw e;
    } finally {
        if (!success) {
            remove();
        }
    }
}
Also used : TupleBuffer(org.teiid.common.buffer.TupleBuffer) BlockedException(org.teiid.common.buffer.BlockedException)

Example 4 with BlockedException

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

the class AccessNode method nextBatchDirect.

public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
    if (!open) {
        // -- blocked during actual open
        openInternal();
        open = true;
    }
    if (multiSource && connectorBindingExpression == null) {
        return this.getChildren()[0].nextBatch();
    }
    while (shouldExecute && (!tupleSources.isEmpty() || hasNextCommand())) {
        if (tupleSources.isEmpty() && processCommandsIndividually()) {
            registerNext();
        }
        // drain the tuple source(s)
        for (int i = 0; i < this.tupleSources.size(); i++) {
            TupleSource tupleSource = tupleSources.get(i);
            try {
                List<?> tuple = null;
                while ((tuple = tupleSource.nextTuple()) != null) {
                    returnedRows = true;
                    if (this.projection != null && this.projection.length > 0) {
                        List<Object> newTuple = new ArrayList<Object>(this.projection.length);
                        for (Object object : this.projection) {
                            if (object instanceof Integer) {
                                newTuple.add(tuple.get((Integer) object));
                            } else {
                                newTuple.add(((Constant) object).getValue());
                            }
                        }
                        tuple = newTuple;
                    }
                    addBatchRow(tuple);
                    if (isBatchFull()) {
                        return pullBatch();
                    }
                }
                // end of source
                tupleSource.closeSource();
                tupleSources.remove(i--);
                if (reserved > 0) {
                    reserved -= schemaSize;
                    getBufferManager().releaseBuffers(schemaSize);
                }
                if (!processCommandsIndividually()) {
                    registerNext();
                }
                continue;
            } catch (BlockedException e) {
                if (processCommandsIndividually()) {
                    if (hasPendingRows()) {
                        return pullBatch();
                    }
                    throw e;
                }
                continue;
            }
        }
        if (processCommandsIndividually()) {
            if (hasPendingRows()) {
                return pullBatch();
            }
            continue;
        }
        if (!this.tupleSources.isEmpty()) {
            if (hasPendingRows()) {
                return pullBatch();
            }
            // $NON-NLS-1$
            throw BlockedException.block(getContext().getRequestId(), "Blocking on source request(s).");
        }
    }
    if (isUpdate && !returnedRows) {
        List<Integer> tuple = new ArrayList<Integer>(1);
        tuple.add(Integer.valueOf(0));
        // Add tuple to current batch
        addBatchRow(tuple);
    }
    terminateBatches();
    return pullBatch();
}
Also used : TupleSource(org.teiid.common.buffer.TupleSource) BlockedException(org.teiid.common.buffer.BlockedException)

Example 5 with BlockedException

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

the class AccessNode method openInternal.

private void openInternal() throws TeiidComponentException, TeiidProcessingException {
    // TODO: support a partitioning concept with multi-source and full dependent join pushdown
    if (subPlans != null) {
        if (this.evaluatedPlans == null) {
            this.evaluatedPlans = new HashMap<GroupSymbol, SubqueryState>();
            for (Map.Entry<GroupSymbol, RelationalPlan> entry : subPlans.entrySet()) {
                SubqueryState state = new SubqueryState();
                RelationalPlan value = entry.getValue();
                value.reset();
                state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager());
                state.collector = state.processor.createBatchCollector();
                this.evaluatedPlans.put(entry.getKey(), state);
            }
        }
        BlockedException be = null;
        for (SubqueryState state : evaluatedPlans.values()) {
            try {
                state.collector.collectTuples();
            } catch (BlockedException e) {
                be = e;
            }
        }
        if (be != null) {
            throw be;
        }
    }
    /*
		 * Check to see if we need a multi-source expansion.  If the connectorBindingExpression != null, then 
		 * the logic below will handle that case
		 */
    if (multiSource && connectorBindingExpression == null) {
        synchronized (this) {
            // the description can be obtained asynchly, so we need to synchronize
            VDBMetaData vdb = getContext().getVdb();
            ModelMetaData model = vdb.getModel(getModelName());
            List<String> sources = model.getSourceNames();
            // make sure that we have the right nodes
            if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) {
                this.childCount--;
                this.getChildren()[0] = null;
            }
            if (this.getChildCount() == 0) {
                sourceNames = sources;
                RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames);
                RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager());
                this.addChild(node);
            }
        }
        this.getChildren()[0].open();
        return;
    }
    // Copy command and resolve references if necessary
    if (processingCommand == null) {
        processingCommand = command;
        isUpdate = RelationalNodeUtil.isUpdate(command);
    }
    boolean needProcessing = true;
    if (this.connectorBindingExpression != null && connectorBindingId == null) {
        this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null);
        VDBMetaData vdb = getContext().getVdb();
        ModelMetaData model = vdb.getModel(getModelName());
        List<String> sources = model.getSourceNames();
        String replacement = this.connectorBindingId;
        if (!sources.contains(this.connectorBindingId)) {
            shouldExecute = false;
            if (command instanceof StoredProcedure) {
                StoredProcedure sp = (StoredProcedure) command;
                if (sp.returnParameters() && sp.getProjectedSymbols().size() > sp.getResultSetColumns().size()) {
                    throw new TeiidProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, command));
                }
            }
            return;
        }
        if (!(command instanceof StoredProcedure || command instanceof Insert)) {
            processingCommand = (Command) command.clone();
            MultiSourceElementReplacementVisitor.visit(replacement, getContext().getMetadata(), processingCommand);
        }
    }
    do {
        Command atomicCommand = nextCommand();
        if (shouldEvaluate) {
            needProcessing = prepareNextCommand(atomicCommand);
            nextCommand = null;
        } else {
            needProcessing = RelationalNodeUtil.shouldExecute(atomicCommand, true);
        }
        if (needProcessing) {
            registerRequest(atomicCommand);
        }
    // We use an upper limit here to the currency because these commands have potentially large in-memory value sets
    } while (!processCommandsIndividually() && hasNextCommand() && this.tupleSources.size() < Math.max(Math.min(MAX_CONCURRENT, this.getContext().getUserRequestSourceConcurrency()), this.getContext().getUserRequestSourceConcurrency() / 2));
}
Also used : SubqueryState(org.teiid.query.processor.relational.SubqueryAwareEvaluator.SubqueryState) Insert(org.teiid.query.sql.lang.Insert) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidProcessingException(org.teiid.core.TeiidProcessingException) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) QueryCommand(org.teiid.query.sql.lang.QueryCommand) Command(org.teiid.query.sql.lang.Command) WithQueryCommand(org.teiid.query.sql.lang.WithQueryCommand) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SymbolMap(org.teiid.query.sql.util.SymbolMap)

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