use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluateParameter.
private Object evaluateParameter(List<?> tuple, DerivedColumn passing) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (passing.getExpression() instanceof Function) {
Function f = (Function) passing.getExpression();
// narrow optimization of json based documents to allow for lower overhead streaming
if (f.getName().equalsIgnoreCase(SourceSystemFunctions.JSONTOXML)) {
String rootName = (String) this.evaluate(f.getArg(0), tuple);
Object lob = this.evaluate(f.getArg(1), tuple);
if (rootName == null || lob == null) {
return null;
}
try {
if (lob instanceof Blob) {
return XMLSystemFunctions.jsonToXml(context, rootName, (Blob) lob, true);
}
return XMLSystemFunctions.jsonToXml(context, rootName, (Clob) lob, true);
} catch (IOException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
} catch (SQLException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
}
}
} else if (passing.getExpression() instanceof XMLParse) {
XMLParse xmlParse = (XMLParse) passing.getExpression();
xmlParse.setWellFormed(true);
}
Object value = this.evaluate(passing.getExpression(), tuple);
return value;
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluateJSONObject.
private Object evaluateJSONObject(List<?> tuple, JSONObject function, JSONBuilder builder) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
List<DerivedColumn> args = function.getArgs();
Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, false, false);
boolean returnValue = false;
try {
if (builder == null) {
returnValue = true;
// preevaluate subqueries to prevent blocked exceptions
for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(function)) {
evaluateSubquery(container, tuple);
}
builder = new JSONBuilder(context.getBufferManager());
}
builder.start(false);
for (NameValuePair<Object> nameValuePair : nameValuePairs) {
addValue(tuple, builder, nameValuePair.name, nameValuePair.value);
}
builder.end(false);
if (returnValue) {
ClobType result = builder.close(context);
builder = null;
return result;
}
return null;
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e);
} finally {
if (returnValue && builder != null) {
builder.remove();
}
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluateTextLine.
private Object evaluateTextLine(List<?> tuple, TextLine function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
List<DerivedColumn> args = function.getExpressions();
Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, true, true);
try {
return new ArrayImpl(TextLine.evaluate(Arrays.asList(nameValuePairs), defaultExtractor, function));
} catch (TransformationException e) {
throw new ExpressionEvaluationException(e);
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e);
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluateXMLElement.
private Object evaluateXMLElement(List<?> tuple, XMLElement function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
List<Expression> content = function.getContent();
List<Object> values = new ArrayList<Object>(content.size());
for (Expression exp : content) {
values.add(internalEvaluate(exp, tuple));
}
try {
Evaluator.NameValuePair<Object>[] attributes = null;
if (function.getAttributes() != null) {
attributes = getNameValuePairs(tuple, function.getAttributes().getArgs(), true, true);
}
return XMLSystemFunctions.xmlElement(context, function.getName(), namespaces(function.getNamespaces()), attributes, values);
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e);
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluate.
private Boolean evaluate(AbstractSetCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getExpression(), tuple);
} catch (ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, criteria));
}
Boolean result = Boolean.FALSE;
ValueIterator valueIter = null;
if (criteria instanceof SetCriteria) {
SetCriteria set = (SetCriteria) criteria;
// Shortcut if null
if (leftValue == null) {
if (!set.getValues().isEmpty()) {
return null;
}
return criteria.isNegated();
}
if (set.isAllConstants()) {
boolean exists = set.getValues().contains(new Constant(leftValue, criteria.getExpression().getType()));
if (!exists) {
if (set.getValues().contains(Constant.NULL_CONSTANT)) {
return null;
}
return criteria.isNegated();
}
return !criteria.isNegated();
}
valueIter = new CollectionValueIterator(((SetCriteria) criteria).getValues());
} else if (criteria instanceof DependentSetCriteria) {
DependentSetCriteria ref = (DependentSetCriteria) criteria;
VariableContext vc = getContext(criteria).getVariableContext();
ValueIteratorSource vis = (ValueIteratorSource) vc.getGlobalValue(ref.getContextSymbol());
if (leftValue == null) {
return null;
}
Set<Object> values;
try {
values = vis.getCachedSet(ref.getValueExpression());
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e);
}
if (values != null) {
return values.contains(leftValue);
}
vis.setUnused(true);
// them in memory
return true;
} else if (criteria instanceof SubquerySetCriteria) {
try {
valueIter = evaluateSubquery((SubquerySetCriteria) criteria, tuple);
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e);
}
} else {
// $NON-NLS-1$
throw new AssertionError("unknown set criteria type");
}
while (valueIter.hasNext()) {
if (leftValue == null) {
return null;
}
Object possibleValue = valueIter.next();
Object value = null;
if (possibleValue instanceof Expression) {
try {
value = evaluate((Expression) possibleValue, tuple);
} catch (ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, possibleValue));
}
} else {
value = possibleValue;
}
if (value != null) {
if (Constant.COMPARATOR.compare(leftValue, value) == 0) {
return Boolean.valueOf(!criteria.isNegated());
}
// else try next value
} else {
result = null;
}
}
if (result == null) {
return null;
}
return Boolean.valueOf(criteria.isNegated());
}
Aggregations