Search in sources :

Example 1 with TeiidProcessingException

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

the class Evaluator method evaluateParameter.

private Object evaluateParameter(List<?> tuple, DerivedColumn passing) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    if (passing.getExpression() instanceof Function) {
        Function f = (Function) passing.getExpression();
        // narrow optimization of json based documents to allow for lower overhead streaming
        if (f.getName().equalsIgnoreCase(SourceSystemFunctions.JSONTOXML)) {
            String rootName = (String) this.evaluate(f.getArg(0), tuple);
            Object lob = this.evaluate(f.getArg(1), tuple);
            if (rootName == null || lob == null) {
                return null;
            }
            try {
                if (lob instanceof Blob) {
                    return XMLSystemFunctions.jsonToXml(context, rootName, (Blob) lob, true);
                }
                return XMLSystemFunctions.jsonToXml(context, rootName, (Clob) lob, true);
            } catch (IOException e) {
                throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
            } catch (SQLException e) {
                throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
            } catch (TeiidProcessingException e) {
                throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
            }
        }
    } else if (passing.getExpression() instanceof XMLParse) {
        XMLParse xmlParse = (XMLParse) passing.getExpression();
        xmlParse.setWellFormed(true);
    }
    Object value = this.evaluate(passing.getExpression(), tuple);
    return value;
}
Also used : Blob(java.sql.Blob) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) LanguageObject(org.teiid.query.sql.LanguageObject) IOException(java.io.IOException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with TeiidProcessingException

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

the class Evaluator method evaluateJSONObject.

private Object evaluateJSONObject(List<?> tuple, JSONObject function, JSONBuilder builder) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
    List<DerivedColumn> args = function.getArgs();
    Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, false, false);
    boolean returnValue = false;
    try {
        if (builder == null) {
            returnValue = true;
            // preevaluate subqueries to prevent blocked exceptions
            for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(function)) {
                evaluateSubquery(container, tuple);
            }
            builder = new JSONBuilder(context.getBufferManager());
        }
        builder.start(false);
        for (NameValuePair<Object> nameValuePair : nameValuePairs) {
            addValue(tuple, builder, nameValuePair.name, nameValuePair.value);
        }
        builder.end(false);
        if (returnValue) {
            ClobType result = builder.close(context);
            builder = null;
            return result;
        }
        return null;
    } catch (TeiidProcessingException e) {
        throw new FunctionExecutionException(e);
    } finally {
        if (returnValue && builder != null) {
            builder.remove();
        }
    }
}
Also used : JSONBuilder(org.teiid.query.function.JSONFunctionMethods.JSONBuilder) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 3 with TeiidProcessingException

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

the class Evaluator method evaluateTextLine.

private Object evaluateTextLine(List<?> tuple, TextLine function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
    List<DerivedColumn> args = function.getExpressions();
    Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, true, true);
    try {
        return new ArrayImpl(TextLine.evaluate(Arrays.asList(nameValuePairs), defaultExtractor, function));
    } catch (TransformationException e) {
        throw new ExpressionEvaluationException(e);
    } catch (TeiidProcessingException e) {
        throw new ExpressionEvaluationException(e);
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 4 with TeiidProcessingException

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

the class Evaluator method evaluateXMLElement.

private Object evaluateXMLElement(List<?> tuple, XMLElement function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
    List<Expression> content = function.getContent();
    List<Object> values = new ArrayList<Object>(content.size());
    for (Expression exp : content) {
        values.add(internalEvaluate(exp, tuple));
    }
    try {
        Evaluator.NameValuePair<Object>[] attributes = null;
        if (function.getAttributes() != null) {
            attributes = getNameValuePairs(tuple, function.getAttributes().getArgs(), true, true);
        }
        return XMLSystemFunctions.xmlElement(context, function.getName(), namespaces(function.getNamespaces()), attributes, values);
    } catch (TeiidProcessingException e) {
        throw new FunctionExecutionException(e);
    }
}
Also used : FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) ArrayList(java.util.ArrayList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 5 with TeiidProcessingException

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

the class Evaluator method evaluate.

private Boolean evaluate(AbstractSetCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    // Evaluate expression
    Object leftValue = null;
    try {
        leftValue = evaluate(criteria.getExpression(), tuple);
    } catch (ExpressionEvaluationException e) {
        throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, criteria));
    }
    Boolean result = Boolean.FALSE;
    ValueIterator valueIter = null;
    if (criteria instanceof SetCriteria) {
        SetCriteria set = (SetCriteria) criteria;
        // Shortcut if null
        if (leftValue == null) {
            if (!set.getValues().isEmpty()) {
                return null;
            }
            return criteria.isNegated();
        }
        if (set.isAllConstants()) {
            boolean exists = set.getValues().contains(new Constant(leftValue, criteria.getExpression().getType()));
            if (!exists) {
                if (set.getValues().contains(Constant.NULL_CONSTANT)) {
                    return null;
                }
                return criteria.isNegated();
            }
            return !criteria.isNegated();
        }
        valueIter = new CollectionValueIterator(((SetCriteria) criteria).getValues());
    } else if (criteria instanceof DependentSetCriteria) {
        DependentSetCriteria ref = (DependentSetCriteria) criteria;
        VariableContext vc = getContext(criteria).getVariableContext();
        ValueIteratorSource vis = (ValueIteratorSource) vc.getGlobalValue(ref.getContextSymbol());
        if (leftValue == null) {
            return null;
        }
        Set<Object> values;
        try {
            values = vis.getCachedSet(ref.getValueExpression());
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
        if (values != null) {
            return values.contains(leftValue);
        }
        vis.setUnused(true);
        // them in memory
        return true;
    } else if (criteria instanceof SubquerySetCriteria) {
        try {
            valueIter = evaluateSubquery((SubquerySetCriteria) criteria, tuple);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    } else {
        // $NON-NLS-1$
        throw new AssertionError("unknown set criteria type");
    }
    while (valueIter.hasNext()) {
        if (leftValue == null) {
            return null;
        }
        Object possibleValue = valueIter.next();
        Object value = null;
        if (possibleValue instanceof Expression) {
            try {
                value = evaluate((Expression) possibleValue, tuple);
            } catch (ExpressionEvaluationException e) {
                throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, possibleValue));
            }
        } else {
            value = possibleValue;
        }
        if (value != null) {
            if (Constant.COMPARATOR.compare(leftValue, value) == 0) {
                return Boolean.valueOf(!criteria.isNegated());
            }
        // else try next value
        } else {
            result = null;
        }
    }
    if (result == null) {
        return null;
    }
    return Boolean.valueOf(criteria.isNegated());
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) Set(java.util.Set) ValueIterator(org.teiid.query.sql.util.ValueIterator) VariableContext(org.teiid.query.sql.util.VariableContext) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ValueIteratorSource(org.teiid.query.sql.util.ValueIteratorSource) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) LanguageObject(org.teiid.query.sql.LanguageObject)

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