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);
}
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);
}
}
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;
}
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);
}
}
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();
}
}
Aggregations