Search in sources :

Example 86 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class MergeJoinStrategy method compareToPrevious.

protected boolean compareToPrevious(SourceState target) throws TeiidComponentException, TeiidProcessingException {
    if (!target.getIterator().hasNext()) {
        target.setMaxProbeMatch(target.getIterator().getCurrentIndex());
        return false;
    }
    List previousTuple = target.getCurrentTuple();
    target.saveNext();
    if (target.getMaxProbeMatch() >= target.getIterator().getCurrentIndex()) {
        return true;
    }
    if (previousTuple != null) {
        int compare = 1;
        if (!target.isExpresssionDistinct()) {
            compare = compare(previousTuple, target.getCurrentTuple(), target.getExpressionIndexes(), target.getExpressionIndexes());
            if (compare < 0) {
                // note this is not a complete check - it will not detect all invalid circumstances as we exit early
                throw new TeiidComponentException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31202));
            }
        }
        if (compare != 0) {
            target.setMaxProbeMatch(target.getIterator().getCurrentIndex() - 1);
            return false;
        }
    }
    target.setMaxProbeMatch(target.getIterator().getCurrentIndex());
    return true;
}
Also used : List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 87 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class BatchedUpdatePlan method nextBatch.

/**
 * @see org.teiid.query.processor.ProcessorPlan#nextBatch()
 * @since 4.2
 */
public TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
    for (; planIndex < updatePlans.length && (getContext() == null || getContext().getBatchUpdateException() == null); ) {
        try {
            if (!planOpened[planIndex]) {
                // Open the plan only once
                /* Defect 16166
	                 * Some commands in a batch may depend on updates by previous commands in the same batch. A call
	                 * to open() usually submits an atomic command, so calling open() on all the child plans at the same time
	                 * will mean that the datasource may not be in the state expected by a later command within the batch. So,
	                 * for a batch of commands, we only open() a later plan when we are finished with the previous plan to
	                 * guarantee that the commands in the previous plan are completed before the commands in any subsequent
	                 * plans are executed.
	                 */
                openPlan();
            } else if (this.planContexts[planIndex] != null) {
                this.getContext().getTransactionServer().resume(this.planContexts[planIndex]);
            }
            // Execute nextBatch() on each plan in sequence
            TupleBatch nextBatch = null;
            do {
                // Can throw BlockedException
                nextBatch = updatePlans[planIndex].nextBatch();
                List<List<?>> currentBatch = nextBatch.getTuples();
                for (int i = 0; i < currentBatch.size(); i++, commandIndex++) {
                    updateCounts[commandIndex] = currentBatch.get(i);
                }
            } while (!nextBatch.getTerminationFlag());
            // since we are done with the plan explicitly close it.
            updatePlans[planIndex].close();
            if (this.planContexts[planIndex] != null) {
                TransactionService ts = this.getContext().getTransactionServer();
                ts.commit(this.planContexts[planIndex]);
                this.planContexts[planIndex] = null;
            }
            planIndex++;
        } catch (BlockedException e) {
            throw e;
        } catch (TeiidComponentException | TeiidProcessingException e) {
            if (singleResult) {
                throw e;
            }
            Throwable cause = e;
            if (e.getCause() instanceof TranslatorBatchException) {
                TranslatorBatchException tbe = (TranslatorBatchException) e.getCause();
                for (int i = 0; i < tbe.getUpdateCounts().length; i++) {
                    updateCounts[commandIndex++] = Arrays.asList(tbe.getUpdateCounts()[i]);
                }
            }
            updateCounts = Arrays.copyOf(updateCounts, commandIndex);
            getContext().setBatchUpdateException(cause);
        } finally {
            if (planIndex < updatePlans.length && this.planContexts[planIndex] != null) {
                this.getContext().getTransactionServer().suspend(this.planContexts[planIndex]);
            }
        }
    }
    if (singleResult) {
        long result = 0;
        for (int i = 0; i < updateCounts.length; i++) {
            int value = (Integer) updateCounts[i].get(0);
            if (value == Statement.EXECUTE_FAILED) {
                // the batch results rather than throwing an exception
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID31199, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31198));
            }
            if (value > 0) {
                result += value;
            }
        }
        TupleBatch batch = new TupleBatch(1, new List<?>[] { Arrays.asList((int) Math.min(Integer.MAX_VALUE, result)) });
        batch.setTerminationFlag(true);
        return batch;
    }
    // Add tuples to current batch
    TupleBatch batch = new TupleBatch(1, updateCounts);
    batch.setTerminationFlag(true);
    return batch;
}
Also used : TransactionService(org.teiid.dqp.service.TransactionService) BlockedException(org.teiid.common.buffer.BlockedException) TranslatorBatchException(org.teiid.translator.TranslatorBatchException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 88 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class BatchedUpdatePlan method close.

/**
 * @see org.teiid.query.processor.ProcessorPlan#close()
 * @since 4.2
 */
public void close() throws TeiidComponentException {
    // if the plan opened but the atomic request got cancelled then close the last plan node.
    TransactionService ts = this.getContext().getTransactionServer();
    if (planIndex < updatePlans.length && planOpened[planIndex]) {
        try {
            updatePlans[planIndex].close();
        } catch (TeiidComponentException e) {
            LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
        }
        if (this.planContexts[planIndex] != null) {
            try {
                ts.resume(this.planContexts[planIndex]);
                ts.rollback(this.planContexts[planIndex]);
            } catch (XATransactionException e) {
                LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
            }
            this.planContexts[planIndex] = null;
        }
    }
}
Also used : TransactionService(org.teiid.dqp.service.TransactionService) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 89 with TeiidComponentException

use of org.teiid.core.TeiidComponentException 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 90 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class AbstractValidationVisitor method handleException.

protected void handleException(TeiidException e, LanguageObject obj) {
    // Store exception information
    this.exceptionObject = obj;
    if (e instanceof TeiidComponentException) {
        this.exception = (TeiidComponentException) e;
    } else {
        this.exception = new TeiidComponentException(e);
    }
    // Abort the validation process
    setAbort(true);
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6