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