Search in sources :

Example 1 with Evaluator

use of org.teiid.query.eval.Evaluator in project teiid by teiid.

the class EvaluatorIterator method init.

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        GroupSymbol gs = null;
        String query = options.get(QUERYSTRING);
        TransformationMetadata tm = createTransformationMetadata(options.get(DDL));
        this.criteria = QueryParser.getQueryParser().parseCriteria(query);
        this.elementsInExpression = ElementCollectorVisitor.getElements(this.criteria, false);
        for (ElementSymbol es : this.elementsInExpression) {
            gs = es.getGroupSymbol();
            ResolverUtil.resolveGroup(gs, tm);
        }
        ResolverVisitor.resolveLanguageObject(this.criteria, tm);
        this.evaluatorUtil = new EvaluatorUtil(gs);
    } catch (QueryParserException e) {
        throw new IOException(e);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } catch (QueryResolverException e) {
        throw new IOException(e);
    } catch (TeiidComponentException e) {
        throw new IOException(e);
    }
    CommandContext cc = new CommandContext();
    this.evaluator = new Evaluator(this.evaluatorUtil.getElementMap(), null, cc);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryParserException(org.teiid.api.exception.query.QueryParserException) CommandContext(org.teiid.query.util.CommandContext) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) Evaluator(org.teiid.query.eval.Evaluator) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 2 with Evaluator

use of org.teiid.query.eval.Evaluator 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 3 with Evaluator

use of org.teiid.query.eval.Evaluator in project teiid by teiid.

the class WindowFunctionProjectNode method saveInput.

/**
 * Save the input generating any necessary expressions and adding a row id
 * @param collectedExpressions
 * @return
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
private void saveInput() throws TeiidComponentException, TeiidProcessingException {
    if (inputTs == null) {
        List<Expression> collectedExpressions = new ArrayList<Expression>(expressionIndexes.keySet());
        Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext());
        final RelationalNode sourceNode = this.getChildren()[0];
        inputTs = new ProjectingTupleSource(sourceNode, eval, collectedExpressions, elementMap) {

            int index = 0;

            @Override
            public List<Object> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                List<Object> tuple = super.nextTuple();
                if (tuple != null) {
                    tuple.add(index++);
                }
                return tuple;
            }
        };
        List<ElementSymbol> schema = new ArrayList<ElementSymbol>(collectedExpressions.size() + 1);
        int index = 0;
        for (Expression ex : collectedExpressions) {
            ElementSymbol es = new ElementSymbol(String.valueOf(index++));
            es.setType(ex.getType());
            schema.add(es);
        }
        // add in the row id
        ElementSymbol es = new ElementSymbol(String.valueOf(index++));
        es.setType(DataTypeManager.DefaultDataClasses.INTEGER);
        schema.add(es);
        tb = this.getBufferManager().createTupleBuffer(schema, this.getConnectionID(), TupleSourceType.PROCESSOR);
    }
    List<?> tuple = null;
    while ((tuple = inputTs.nextTuple()) != null) {
        tb.addTuple(tuple);
    }
    tb.close();
    inputTs.closeSource();
    inputTs = null;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) ProjectingTupleSource(org.teiid.query.processor.relational.GroupingNode.ProjectingTupleSource) Evaluator(org.teiid.query.eval.Evaluator) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Evaluator

use of org.teiid.query.eval.Evaluator in project teiid by teiid.

the class XMLTableNode method evaluate.

private void evaluate(final boolean useFinalBuffer) throws TeiidComponentException, ExpressionEvaluationException, BlockedException, TeiidProcessingException {
    if (result != null || this.buffer != null) {
        return;
    }
    setReferenceValues(this.table);
    final HashMap<String, Object> parameters = new HashMap<String, Object>();
    Evaluator eval = getEvaluator(Collections.emptyMap());
    eval.evaluateParameters(this.table.getPassing(), null, parameters);
    final Object contextItem;
    if (parameters.containsKey(null)) {
        contextItem = parameters.remove(null);
        // null context item mean no rows
        if (contextItem == null) {
            result = new Result();
            result.iter = EmptyIterator.emptyIterator();
            streaming = false;
            return;
        }
    } else {
        contextItem = null;
    }
    if (this.table.getXQueryExpression().isStreaming()) {
        if (this.buffer == null) {
            this.buffer = this.getBufferManager().createTupleBuffer(getOutputElements(), getConnectionID(), TupleSourceType.PROCESSOR);
            if (!useFinalBuffer) {
                this.buffer.setForwardOnly(true);
            }
        }
        Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    XQueryEvaluator.evaluateXQuery(table.getXQueryExpression(), contextItem, parameters, XMLTableNode.this, getContext());
                } catch (TeiidRuntimeException e) {
                    if (e != EARLY_TERMINATION) {
                        asynchException = e;
                    }
                } catch (Throwable e) {
                    asynchException = new TeiidRuntimeException(e);
                } finally {
                    synchronized (XMLTableNode.this) {
                        if (buffer != null && asynchException == null) {
                            try {
                                buffer.close();
                            } catch (TeiidComponentException e) {
                                asynchException = new TeiidRuntimeException(e);
                            }
                        }
                        state = State.DONE;
                        XMLTableNode.this.notifyAll();
                    }
                }
            }
        };
        this.getContext().getExecutor().execute(r);
        return;
    }
    try {
        result = XQueryEvaluator.evaluateXQuery(this.table.getXQueryExpression(), contextItem, parameters, null, this.getContext());
    } catch (TeiidRuntimeException e) {
        unwrapException(e);
    }
}
Also used : HashMap(java.util.HashMap) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) XQueryEvaluator(org.teiid.query.xquery.saxon.XQueryEvaluator) Evaluator(org.teiid.query.eval.Evaluator) ConversionResult(net.sf.saxon.type.ConversionResult) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result)

Example 5 with Evaluator

use of org.teiid.query.eval.Evaluator in project teiid by teiid.

the class ObjectTableNode method evaluate.

private void evaluate() throws TeiidComponentException, ExpressionEvaluationException, BlockedException, TeiidProcessingException {
    if (result != null) {
        return;
    }
    setReferenceValues(this.table);
    Evaluator eval = getEvaluator(Collections.emptyMap());
    eval.evaluateParameters(this.table.getPassing(), null, scriptContext.getBindings(ScriptContext.ENGINE_SCOPE));
    Object value = evalScript(this.table.getCompiledScript(), this.table.getRowScript());
    if (value instanceof Iterable<?>) {
        result = ((Iterable<?>) value).iterator();
    } else if (value instanceof Iterator<?>) {
        result = (Iterator<?>) value;
    } else if (value != null && value.getClass().isArray()) {
        result = new ReflectiveArrayIterator(value);
    } else if (value instanceof Array) {
        try {
            result = new ReflectiveArrayIterator(((Array) value).getArray());
        } catch (SQLException e) {
            throw new TeiidProcessingException(e);
        }
    } else {
        result = Arrays.asList(value).iterator();
    }
}
Also used : Array(java.sql.Array) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) LanguageObject(org.teiid.query.sql.LanguageObject) Evaluator(org.teiid.query.eval.Evaluator) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

Evaluator (org.teiid.query.eval.Evaluator)20 ArrayList (java.util.ArrayList)12 List (java.util.List)7 CommandContext (org.teiid.query.util.CommandContext)7 TeiidComponentException (org.teiid.core.TeiidComponentException)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)6 HashMap (java.util.HashMap)5 Map (java.util.Map)4 Test (org.junit.Test)4 Expression (org.teiid.query.sql.symbol.Expression)4 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)3 BlockedException (org.teiid.common.buffer.BlockedException)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 LanguageBridgeFactory (org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)2 Call (org.teiid.language.Call)2 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)2 FakeDataManager (org.teiid.query.processor.FakeDataManager)2