use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class Evaluator method evaluate.
private Boolean evaluate(CompareCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate left expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch (ExpressionEvaluationException e) {
// $NON-NLS-1$
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30312, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30312, "left", criteria));
}
// Shortcut if null
if (leftValue == null) {
return null;
}
// Evaluate right expression
Object rightValue = null;
try {
rightValue = evaluate(criteria.getRightExpression(), tuple);
} catch (ExpressionEvaluationException e) {
// $NON-NLS-1$
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30312, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30312, "right", criteria));
}
// Shortcut if null
if (rightValue == null) {
return null;
}
// Compare two non-null values using specified operator
return compare(criteria.getOperator(), leftValue, rightValue);
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class Evaluator method evaluateIsDistinct.
private Boolean evaluateIsDistinct(IsDistinctCriteria idc, List<?> tuple) throws AssertionError, ExpressionEvaluationException, BlockedException, TeiidComponentException {
RowValue left = getRowValue(tuple, idc.getLeftRowValue());
RowValue right = getRowValue(tuple, idc.getRightRowValue());
if (left.length() != right.length()) {
return !idc.isNegated();
}
boolean result = false;
for (int i = 0; i < left.length(); i++) {
Object l = left.get(i);
Object r = right.get(i);
if (l == null) {
if (r != null) {
result = true;
break;
}
continue;
} else if (r == null) {
result = true;
break;
}
try {
Boolean b = compare(CompareCriteria.EQ, l, r);
if (b == null) {
// shouldn't happen
continue;
}
if (!b) {
result = true;
break;
}
} catch (Exception e) {
// we'll consider this a difference
// more than likely they are different types
result = true;
break;
}
}
if (idc.isNegated()) {
return !result;
}
return result;
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class Evaluator method evaluate.
private Object evaluate(List<?> tuple, ExceptionExpression ee) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
String msg = (String) internalEvaluate(ee.getMessage(), tuple);
String sqlState = ee.getDefaultSQLState();
if (ee.getSqlState() != null) {
sqlState = (String) internalEvaluate(ee.getSqlState(), tuple);
}
Integer errorCode = null;
if (ee.getErrorCode() != null) {
errorCode = (Integer) internalEvaluate(ee.getErrorCode(), tuple);
}
Exception parent = null;
if (ee.getParent() != null) {
parent = (Exception) internalEvaluate(ee.getParent(), tuple);
}
Exception result = new TeiidSQLException(parent, msg, sqlState, errorCode != null ? errorCode : 0);
result.setStackTrace(SourceWarning.EMPTY_STACK_TRACE);
return result;
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class Evaluator method evaluate.
private Boolean evaluate(SubqueryCompareCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch (ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, criteria));
}
// Need to be careful to initialize this variable carefully for the case
// where valueIterator has no values, and the block below is not entered.
// If there are no rows, and ALL is the predicate quantifier, the result
// should be true. If SOME is the predicate quantifier, or no quantifier
// is used, the result should be false.
Boolean result = Boolean.FALSE;
if (criteria.getPredicateQuantifier() == SubqueryCompareCriteria.ALL) {
result = Boolean.TRUE;
}
ValueIterator valueIter;
if (criteria.getCommand() != null) {
try {
valueIter = evaluateSubquery(criteria, tuple);
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e);
}
} else {
Object array = evaluate(criteria.getArrayExpression(), tuple);
final Object[] vals;
if (array instanceof Object[]) {
vals = (Object[]) array;
} else {
ArrayImpl arrayImpl = (ArrayImpl) array;
vals = arrayImpl.getValues();
}
valueIter = new ValueIterator() {
int index = 0;
@Override
public void reset() {
index = 0;
}
@Override
public boolean hasNext() {
return index < vals.length;
}
@Override
public Object next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return vals[index++];
}
};
}
while (valueIter.hasNext()) {
Object value = valueIter.next();
// Shortcut if null
if (leftValue == null) {
return null;
}
if (value != null) {
Boolean comp = compare(criteria.getOperator(), leftValue, value);
switch(criteria.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
if (Boolean.FALSE.equals(comp)) {
return Boolean.FALSE;
}
break;
case SubqueryCompareCriteria.SOME:
if (Boolean.TRUE.equals(comp)) {
return Boolean.TRUE;
}
break;
default:
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
}
} else {
// value is null
switch(criteria.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
if (Boolean.TRUE.equals(result)) {
result = null;
}
break;
case SubqueryCompareCriteria.SOME:
if (Boolean.FALSE.equals(result)) {
result = null;
}
break;
default:
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
}
}
}
return result;
}
use of org.teiid.api.exception.query.ExpressionEvaluationException in project teiid by teiid.
the class MatchCriteria method getPattern.
public static Pattern getPattern(String newPattern, String originalPattern, int flags) throws ExpressionEvaluationException {
List<?> key = Arrays.asList(newPattern, flags);
Pattern p = patternCache.get(key);
if (p == null) {
try {
p = Pattern.compile(newPattern, Pattern.DOTALL);
patternCache.put(key, p);
} catch (PatternSyntaxException e) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30448, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30448, new Object[] { originalPattern, e.getMessage() }));
}
}
return p;
}
Aggregations