Search in sources :

Example 1 with ExceptionExpression

use of org.teiid.query.sql.proc.ExceptionExpression in project teiid by teiid.

the class Evaluator method internalEvaluate.

protected Object internalEvaluate(Expression expression, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    if (expression instanceof DerivedExpression) {
        if (elements != null) {
            // Try to evaluate by lookup in the elements map (may work for both ElementSymbol and ExpressionSymbol
            Integer index = (Integer) elements.get(expression);
            if (index != null) {
                return tuple.get(index.intValue());
            }
        }
        // Otherwise this should be an ExpressionSymbol and we just need to dive in and evaluate the expression itself
        if (expression instanceof ExpressionSymbol) {
            ExpressionSymbol exprSyb = (ExpressionSymbol) expression;
            Expression expr = exprSyb.getExpression();
            return internalEvaluate(expr, tuple);
        }
        return getContext(expression).getFromContext(expression);
    }
    if (expression instanceof Constant) {
        Constant c = (Constant) expression;
        if (c.isMultiValued()) {
            // $NON-NLS-1$
            throw new AssertionError("Multi-valued constant not allowed to be directly evaluated");
        }
        return c.getValue();
    } else if (expression instanceof Function) {
        return evaluate((Function) expression, tuple);
    } else if (expression instanceof CaseExpression) {
        return evaluate((CaseExpression) expression, tuple);
    } else if (expression instanceof SearchedCaseExpression) {
        return evaluate((SearchedCaseExpression) expression, tuple);
    } else if (expression instanceof Reference) {
        Reference ref = (Reference) expression;
        if (ref.isPositional() && ref.getExpression() == null) {
            return getContext(ref).getVariableContext().getGlobalValue(ref.getContextSymbol());
        }
        Object result = getContext(ref.getExpression()).getFromContext(ref.getExpression());
        if (ref.getConstraint() != null) {
            try {
                ref.getConstraint().validate(result);
            } catch (QueryValidatorException e) {
                throw new ExpressionEvaluationException(e);
            }
        }
        return result;
    } else if (expression instanceof Criteria) {
        return evaluate((Criteria) expression, tuple);
    } else if (expression instanceof ScalarSubquery) {
        return evaluate((ScalarSubquery) expression, tuple);
    } else if (expression instanceof Criteria) {
        return evaluate((Criteria) expression, tuple);
    } else if (expression instanceof TextLine) {
        return evaluateTextLine(tuple, (TextLine) expression);
    } else if (expression instanceof XMLElement) {
        return evaluateXMLElement(tuple, (XMLElement) expression);
    } else if (expression instanceof XMLForest) {
        return evaluateXMLForest(tuple, (XMLForest) expression);
    } else if (expression instanceof JSONObject) {
        return evaluateJSONObject(tuple, (JSONObject) expression, null);
    } else if (expression instanceof XMLSerialize) {
        return evaluateXMLSerialize(tuple, (XMLSerialize) expression);
    } else if (expression instanceof XMLQuery) {
        return evaluateXMLQuery(tuple, (XMLQuery) expression, false);
    } else if (expression instanceof QueryString) {
        return evaluateQueryString(tuple, (QueryString) expression);
    } else if (expression instanceof XMLParse) {
        return evaluateXMLParse(tuple, (XMLParse) expression);
    } else if (expression instanceof Array) {
        Array array = (Array) expression;
        List<Expression> exprs = array.getExpressions();
        Object[] result = (Object[]) java.lang.reflect.Array.newInstance(array.getComponentType(), exprs.size());
        for (int i = 0; i < exprs.size(); i++) {
            Object eval = internalEvaluate(exprs.get(i), tuple);
            if (eval instanceof ArrayImpl) {
                eval = ((ArrayImpl) eval).getValues();
            }
            result[i] = eval;
        }
        return new ArrayImpl(result);
    } else if (expression instanceof ExceptionExpression) {
        return evaluate(tuple, (ExceptionExpression) expression);
    } else if (expression instanceof XMLCast) {
        return evaluate(tuple, (XMLCast) expression);
    } else {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30329, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30329, expression.getClass().getName()));
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 2 with ExceptionExpression

use of org.teiid.query.sql.proc.ExceptionExpression in project teiid by teiid.

the class ResolverVisitor method checkException.

public static void checkException(Expression obj) throws QueryResolverException {
    if (obj == null || obj instanceof ExceptionExpression) {
        return;
    }
    if (obj instanceof ElementSymbol) {
        ElementSymbol es = (ElementSymbol) obj;
        if (!(es.getMetadataID() instanceof TempMetadataID)) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
        }
        TempMetadataID tid = (TempMetadataID) es.getMetadataID();
        if (tid.getType() != Exception.class) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
        }
    } else if (obj instanceof Constant) {
        Constant c = (Constant) obj;
        if (!(c.getValue() instanceof Exception)) {
            throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
        }
    } else {
        throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
    }
}
Also used : ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) InvalidFunctionException(org.teiid.api.exception.query.InvalidFunctionException)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)2 ExceptionExpression (org.teiid.query.sql.proc.ExceptionExpression)2 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)1 InvalidFunctionException (org.teiid.api.exception.query.InvalidFunctionException)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 TempMetadataID (org.teiid.query.metadata.TempMetadataID)1 LanguageObject (org.teiid.query.sql.LanguageObject)1