Search in sources :

Example 56 with TeiidProcessingException

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

the class RequestWorkItem method addCancelCode.

private Throwable addCancelCode(Throwable exception) {
    String reason = null;
    synchronized (this) {
        reason = this.cancelReason;
    }
    if (exception instanceof TeiidException) {
        TeiidException te = (TeiidException) exception;
        if (SQLStates.QUERY_CANCELED.equals(te.getCode()) && EquivalenceUtil.areEqual(reason, te.getMessage())) {
            return exception;
        }
    }
    TeiidProcessingException tpe = new TeiidProcessingException(reason);
    tpe.initCause(exception);
    tpe.setCode(SQLStates.QUERY_CANCELED);
    return tpe;
}
Also used : TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 57 with TeiidProcessingException

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

the class Evaluator method evaluateXMLForest.

private Object evaluateXMLForest(List<?> tuple, XMLForest function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
    List<DerivedColumn> args = function.getArgs();
    Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, true, true);
    try {
        return XMLSystemFunctions.xmlForest(context, namespaces(function.getNamespaces()), nameValuePairs);
    } catch (TeiidProcessingException e) {
        throw new FunctionExecutionException(e);
    }
}
Also used : FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 58 with TeiidProcessingException

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

the class Evaluator method evaluate.

private Boolean evaluate(SubqueryCompareCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    // Evaluate expression
    Object leftValue = null;
    try {
        leftValue = evaluate(criteria.getLeftExpression(), tuple);
    } catch (ExpressionEvaluationException e) {
        throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, criteria));
    }
    // Need to be careful to initialize this variable carefully for the case
    // where valueIterator has no values, and the block below is not entered.
    // If there are no rows, and ALL is the predicate quantifier, the result
    // should be true.  If SOME is the predicate quantifier, or no quantifier
    // is used, the result should be false.
    Boolean result = Boolean.FALSE;
    if (criteria.getPredicateQuantifier() == SubqueryCompareCriteria.ALL) {
        result = Boolean.TRUE;
    }
    ValueIterator valueIter;
    if (criteria.getCommand() != null) {
        try {
            valueIter = evaluateSubquery(criteria, tuple);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    } else {
        Object array = evaluate(criteria.getArrayExpression(), tuple);
        final Object[] vals;
        if (array instanceof Object[]) {
            vals = (Object[]) array;
        } else {
            ArrayImpl arrayImpl = (ArrayImpl) array;
            vals = arrayImpl.getValues();
        }
        valueIter = new ValueIterator() {

            int index = 0;

            @Override
            public void reset() {
                index = 0;
            }

            @Override
            public boolean hasNext() {
                return index < vals.length;
            }

            @Override
            public Object next() {
                if (!hasNext()) {
                    throw new NoSuchElementException();
                }
                return vals[index++];
            }
        };
    }
    while (valueIter.hasNext()) {
        Object value = valueIter.next();
        // Shortcut if null
        if (leftValue == null) {
            return null;
        }
        if (value != null) {
            Boolean comp = compare(criteria.getOperator(), leftValue, value);
            switch(criteria.getPredicateQuantifier()) {
                case SubqueryCompareCriteria.ALL:
                    if (Boolean.FALSE.equals(comp)) {
                        return Boolean.FALSE;
                    }
                    break;
                case SubqueryCompareCriteria.SOME:
                    if (Boolean.TRUE.equals(comp)) {
                        return Boolean.TRUE;
                    }
                    break;
                default:
                    throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
            }
        } else {
            // value is null
            switch(criteria.getPredicateQuantifier()) {
                case SubqueryCompareCriteria.ALL:
                    if (Boolean.TRUE.equals(result)) {
                        result = null;
                    }
                    break;
                case SubqueryCompareCriteria.SOME:
                    if (Boolean.FALSE.equals(result)) {
                        result = null;
                    }
                    break;
                default:
                    throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
            }
        }
    }
    return result;
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ValueIterator(org.teiid.query.sql.util.ValueIterator) LanguageObject(org.teiid.query.sql.LanguageObject) NoSuchElementException(java.util.NoSuchElementException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 59 with TeiidProcessingException

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

the class StringAgg method getResult.

/**
 * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
 */
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
    if (this.result == null) {
        this.result = buildResult(commandContext);
    }
    try {
        this.result.getWriter().close();
        FileStoreOutputStream fs = this.result.getOuputStream();
        fs.close();
        if (binary) {
            if (fs.bytesWritten()) {
                return new BlobType(new BlobImpl(result));
            }
            return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
        }
        if (fs.bytesWritten()) {
            return new ClobType(new ClobImpl(result, -1));
        }
        return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING)));
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
    } catch (SQLException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) BlobType(org.teiid.core.types.BlobType) SQLException(java.sql.SQLException) SerialBlob(javax.sql.rowset.serial.SerialBlob) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) IOException(java.io.IOException) BlobImpl(org.teiid.core.types.BlobImpl) ClobImpl(org.teiid.core.types.ClobImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 60 with TeiidProcessingException

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

the class TextAgg method buildResult.

private FileStoreInputStreamFactory buildResult(CommandContext context) throws TeiidProcessingException {
    try {
        // $NON-NLS-1$
        FileStore fs = context.getBufferManager().createFileStore("textagg");
        FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding() == null ? Streamable.ENCODING : textLine.getEncoding());
        Writer w = fisf.getWriter();
        if (textLine.isIncludeHeader()) {
            Object[] header = TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {

                public Object getValue(DerivedColumn t) {
                    if (t.getAlias() == null && t.getExpression() instanceof ElementSymbol) {
                        return ((ElementSymbol) t.getExpression()).getShortName();
                    }
                    return t.getAlias();
                }
            }, textLine);
            writeList(w, header);
        }
        w.flush();
        return fisf;
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30420, e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) TextLine(org.teiid.query.sql.symbol.TextLine) IOException(java.io.IOException) DerivedColumn(org.teiid.query.sql.symbol.DerivedColumn) Writer(java.io.Writer) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6