// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch(ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(e, "ERR.015.006.0015", QueryPlugin.Util.getString("ERR.015.006.0015", criteria)); //$NON-NLS-1$ //$NON-NLS-2$
}
// Shortcut if null
if(leftValue == null) {
return null;
}
// 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;
try {
valueIter = evaluateSubquery(criteria, tuple);
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e, e.getMessage());
}
while(valueIter.hasNext()) {
Object value = valueIter.next();
if(value != null) {
int compare = compareValues(leftValue, value);
// Compare two non-null values using specified operator
switch(criteria.getOperator()) {
case SubqueryCompareCriteria.EQ:
result = Boolean.valueOf(compare == 0);
break;
case SubqueryCompareCriteria.NE:
result = Boolean.valueOf(compare != 0);
break;
case SubqueryCompareCriteria.LT:
result = Boolean.valueOf(compare < 0);
break;
case SubqueryCompareCriteria.LE:
result = Boolean.valueOf(compare <= 0);
break;
case SubqueryCompareCriteria.GT:
result = Boolean.valueOf(compare > 0);
break;
case SubqueryCompareCriteria.GE:
result = Boolean.valueOf(compare >= 0);
break;
default:
throw new ExpressionEvaluationException("ERR.015.006.0012", QueryPlugin.Util.getString("ERR.015.006.0012", criteria.getOperator())); //$NON-NLS-1$ //$NON-NLS-2$
}
switch(criteria.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
if (Boolean.FALSE.equals(result)){
return Boolean.FALSE;
}
break;
case SubqueryCompareCriteria.SOME:
if (Boolean.TRUE.equals(result)){
return Boolean.TRUE;
}
break;
default:
throw new ExpressionEvaluationException("ERR.015.006.0057", QueryPlugin.Util.getString("ERR.015.006.0057", criteria.getPredicateQuantifier())); //$NON-NLS-1$ //$NON-NLS-2$
}
} else { // value is null
result = null;
}