Search in sources :

Example 6 with ExpressionEvaluationException

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

the class Evaluator method evaluate.

private Object evaluate(ScalarSubquery scalarSubquery, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    Object result = null;
    ValueIterator valueIter;
    try {
        valueIter = evaluateSubquery(scalarSubquery, tuple);
    } catch (TeiidProcessingException e) {
        throw new ExpressionEvaluationException(e);
    }
    if (valueIter.hasNext()) {
        result = valueIter.next();
        if (valueIter.hasNext()) {
            // more than one result value - this is an exception case
            throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30345, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30345, scalarSubquery.getCommand()));
        }
    }
    return result;
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ValueIterator(org.teiid.query.sql.util.ValueIterator) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 7 with ExpressionEvaluationException

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

the class Evaluator method evaluate.

private Object evaluate(Function function, List<?> tuple) throws BlockedException, TeiidComponentException, ExpressionEvaluationException {
    // Get function based on resolved function info
    FunctionDescriptor fd = function.getFunctionDescriptor();
    // Evaluate args
    Expression[] args = function.getArgs();
    Object[] values = null;
    int start = 0;
    if (fd.requiresContext()) {
        values = new Object[args.length + 1];
        values[0] = context;
        start = 1;
    } else {
        values = new Object[args.length];
    }
    for (int i = 0; i < args.length; i++) {
        values[i + start] = internalEvaluate(args[i], tuple);
        if (values[i + start] instanceof Constant) {
            // $NON-NLS-1$
            throw new AssertionError("Multi-valued constant not allowed to be directly evaluated");
        }
    }
    if (fd.getPushdown() == PushDown.MUST_PUSHDOWN) {
        try {
            return evaluatePushdown(function, tuple, values);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    if (fd.getProcedure() != null) {
        try {
            return evaluateProcedure(function, tuple, values);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    // Check for special lookup function
    if (function.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
        if (dataMgr == null) {
            throw new ComponentNotFoundException(QueryPlugin.Event.TEIID30342, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30342));
        }
        String codeTableName = (String) values[0];
        String returnElementName = (String) values[1];
        String keyElementName = (String) values[2];
        try {
            return dataMgr.lookupCodeValue(context, codeTableName, returnElementName, keyElementName, values[3]);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    // Execute function
    return fd.invokeFunction(values, context, null);
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ComponentNotFoundException(org.teiid.core.ComponentNotFoundException) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) LanguageObject(org.teiid.query.sql.LanguageObject) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 8 with ExpressionEvaluationException

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

the class ComplexDocumentFilter method matches.

@Override
public boolean matches(Map<String, Object> parentProperties, Map<String, Object> childProperties) throws TranslatorException {
    try {
        List<Object> tuple = new ArrayList<>();
        int i = 0;
        for (Column column : parentTable.getMetadataObject().getColumns()) {
            tuple.add(i++, parentProperties.get(MarshallerBuilder.getDocumentAttributeName(column, false, metadata)));
        }
        for (Column column : childTable.getMetadataObject().getColumns()) {
            tuple.add(i++, childProperties.get(MarshallerBuilder.getDocumentAttributeName(column, true, metadata)));
        }
        org.teiid.query.util.CommandContext cc = new org.teiid.query.util.CommandContext();
        final Evaluator evaluator = new Evaluator(elementMap, null, cc);
        return evaluator.evaluate(criteria, tuple);
    } catch (ExpressionEvaluationException e) {
        throw new TranslatorException(e);
    } catch (BlockedException e) {
        throw new TranslatorException(e);
    } catch (TeiidComponentException e) {
        throw new TranslatorException(e);
    }
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) BlockedException(org.teiid.common.buffer.BlockedException) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 9 with ExpressionEvaluationException

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

the class SubqueryAwareEvaluator method evaluateProcedure.

/**
 * Implements procedure function handling.
 * TODO: cache results
 */
@Override
protected Object evaluateProcedure(Function function, List<?> tuple, Object[] values) throws TeiidComponentException, TeiidProcessingException {
    QueryProcessor qp = null;
    List<?> key = Arrays.asList(function, Arrays.asList(values));
    if (procedureState != null) {
        qp = this.procedureState.get(key);
    }
    if (qp == null) {
        String args = Collections.nCopies(values.length, '?').toString().substring(1);
        args = args.substring(0, args.length() - 1);
        String fullName = function.getFunctionDescriptor().getFullName();
        // $NON-NLS-1$
        String call = String.format("call %1$s(%2$s)", fullName, args);
        qp = this.context.getQueryProcessorFactory().createQueryProcessor(call, fullName, this.context, values);
        if (this.procedureState == null) {
            this.procedureState = new HashMap<List<?>, QueryProcessor>();
        }
        this.procedureState.put(key, qp);
    }
    // just in case validate the rows being returned
    TupleBatch tb = qp.nextBatch();
    TupleBatch next = tb;
    while (!next.getTerminationFlag()) {
        if (next.getEndRow() >= 2) {
            break;
        }
        next = qp.nextBatch();
    }
    if (next.getEndRow() >= 2) {
        throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30345, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30345, function));
    }
    Object result = null;
    if (next.getRowCount() > 0) {
        result = next.getTuples().get(0).get(0);
    }
    this.procedureState.remove(key);
    qp.closeProcessing();
    return result;
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) List(java.util.List) ArrayList(java.util.ArrayList) QueryProcessor(org.teiid.query.processor.QueryProcessor) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 10 with ExpressionEvaluationException

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

the class TestSelectNode method testTimeslicing.

@Test
public void testTimeslicing() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List elements = new ArrayList();
    elements.add(es1);
    CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
    List[] data = new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) };
    List childElements = new ArrayList();
    childElements.add(es1);
    helpTestSelect(elements, crit, childElements, null, data, new FakeRelationalNode(2, data), new SelectNode(3) {

        int i = 0;

        @Override
        protected Evaluator getEvaluator(Map elementMap) {
            return new Evaluator(elementMap, getDataManager(), getContext()) {

                @Override
                public Boolean evaluateTVL(Criteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
                    if (i++ == 1) {
                        throw new QueryProcessor.ExpiredTimeSliceException();
                    }
                    return super.evaluateTVL(criteria, tuple);
                }
            };
        }
    });
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Evaluator(org.teiid.query.eval.Evaluator) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

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