Search in sources :

Example 16 with ExpressionEvaluationException

use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.

the class Evaluator method evaluate.

private Boolean evaluate(CompareCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    // Evaluate left expression
    Object leftValue = null;
    try {
        leftValue = evaluate(criteria.getLeftExpression(), tuple);
    } catch (ExpressionEvaluationException e) {
        // $NON-NLS-1$
        throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30312, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30312, "left", criteria));
    }
    // Shortcut if null
    if (leftValue == null) {
        return null;
    }
    // Evaluate right expression
    Object rightValue = null;
    try {
        rightValue = evaluate(criteria.getRightExpression(), tuple);
    } catch (ExpressionEvaluationException e) {
        // $NON-NLS-1$
        throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30312, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30312, "right", criteria));
    }
    // Shortcut if null
    if (rightValue == null) {
        return null;
    }
    // Compare two non-null values using specified operator
    return compare(criteria.getOperator(), leftValue, rightValue);
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 17 with ExpressionEvaluationException

use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.

the class Evaluator method evaluateIsDistinct.

private Boolean evaluateIsDistinct(IsDistinctCriteria idc, List<?> tuple) throws AssertionError, ExpressionEvaluationException, BlockedException, TeiidComponentException {
    RowValue left = getRowValue(tuple, idc.getLeftRowValue());
    RowValue right = getRowValue(tuple, idc.getRightRowValue());
    if (left.length() != right.length()) {
        return !idc.isNegated();
    }
    boolean result = false;
    for (int i = 0; i < left.length(); i++) {
        Object l = left.get(i);
        Object r = right.get(i);
        if (l == null) {
            if (r != null) {
                result = true;
                break;
            }
            continue;
        } else if (r == null) {
            result = true;
            break;
        }
        try {
            Boolean b = compare(CompareCriteria.EQ, l, r);
            if (b == null) {
                // shouldn't happen
                continue;
            }
            if (!b) {
                result = true;
                break;
            }
        } catch (Exception e) {
            // we'll consider this a difference
            // more than likely they are different types
            result = true;
            break;
        }
    }
    if (idc.isNegated()) {
        return !result;
    }
    return result;
}
Also used : LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) ComponentNotFoundException(org.teiid.core.ComponentNotFoundException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) BlockedException(org.teiid.common.buffer.BlockedException) SQLException(java.sql.SQLException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException)

Example 18 with ExpressionEvaluationException

use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.

the class Evaluator method evaluate.

private Object evaluate(List<?> tuple, ExceptionExpression ee) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    String msg = (String) internalEvaluate(ee.getMessage(), tuple);
    String sqlState = ee.getDefaultSQLState();
    if (ee.getSqlState() != null) {
        sqlState = (String) internalEvaluate(ee.getSqlState(), tuple);
    }
    Integer errorCode = null;
    if (ee.getErrorCode() != null) {
        errorCode = (Integer) internalEvaluate(ee.getErrorCode(), tuple);
    }
    Exception parent = null;
    if (ee.getParent() != null) {
        parent = (Exception) internalEvaluate(ee.getParent(), tuple);
    }
    Exception result = new TeiidSQLException(parent, msg, sqlState, errorCode != null ? errorCode : 0);
    result.setStackTrace(SourceWarning.EMPTY_STACK_TRACE);
    return result;
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) TeiidComponentException(org.teiid.core.TeiidComponentException) ComponentNotFoundException(org.teiid.core.ComponentNotFoundException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) BlockedException(org.teiid.common.buffer.BlockedException) SQLException(java.sql.SQLException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException)

Example 19 with ExpressionEvaluationException

use of org.teiid.api.exception.query.ExpressionEvaluationException 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 20 with ExpressionEvaluationException

use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.

the class MatchCriteria method getPattern.

public static Pattern getPattern(String newPattern, String originalPattern, int flags) throws ExpressionEvaluationException {
    List<?> key = Arrays.asList(newPattern, flags);
    Pattern p = patternCache.get(key);
    if (p == null) {
        try {
            p = Pattern.compile(newPattern, Pattern.DOTALL);
            patternCache.put(key, p);
        } catch (PatternSyntaxException e) {
            throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30448, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30448, new Object[] { originalPattern, e.getMessage() }));
        }
    }
    return p;
}
Also used : Pattern(java.util.regex.Pattern) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)23 LanguageObject (org.teiid.query.sql.LanguageObject)11 TeiidComponentException (org.teiid.core.TeiidComponentException)7 TeiidProcessingException (org.teiid.core.TeiidProcessingException)7 ArrayList (java.util.ArrayList)5 SQLException (java.sql.SQLException)4 BlockedException (org.teiid.common.buffer.BlockedException)4 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)4 List (java.util.List)3 NoSuchElementException (java.util.NoSuchElementException)3 Test (org.junit.Test)3 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)3 ComponentNotFoundException (org.teiid.core.ComponentNotFoundException)3 Evaluator (org.teiid.query.eval.Evaluator)3 ExceptionExpression (org.teiid.query.sql.proc.ExceptionExpression)3 Expression (org.teiid.query.sql.symbol.Expression)3 ValueIterator (org.teiid.query.sql.util.ValueIterator)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2