in java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java [800:895]
private static TruthValue evaluatePredicateMinMax(PredicateLeaf predicate,
Comparable predObj,
ValueRange range) {
Location loc;
switch (predicate.getOperator()) {
case NULL_SAFE_EQUALS:
loc = range.compare(predObj);
if (loc == Location.BEFORE || loc == Location.AFTER) {
return TruthValue.NO;
} else {
return TruthValue.YES_NO;
}
case EQUALS:
loc = range.compare(predObj);
if (range.isSingleton() && loc == Location.MIN) {
return range.addNull(TruthValue.YES);
} else if (loc == Location.BEFORE || loc == Location.AFTER) {
return range.addNull(TruthValue.NO);
} else {
return range.addNull(TruthValue.YES_NO);
}
case LESS_THAN:
loc = range.compare(predObj);
if (loc == Location.AFTER) {
return range.addNull(TruthValue.YES);
} else if (loc == Location.BEFORE || loc == Location.MIN) {
return range.addNull(TruthValue.NO);
} else {
return range.addNull(TruthValue.YES_NO);
}
case LESS_THAN_EQUALS:
loc = range.compare(predObj);
if (loc == Location.AFTER || loc == Location.MAX ||
(loc == Location.MIN && range.isSingleton())) {
return range.addNull(TruthValue.YES);
} else if (loc == Location.BEFORE) {
return range.addNull(TruthValue.NO);
} else {
return range.addNull(TruthValue.YES_NO);
}
case IN:
if (range.isSingleton()) {
// for a single value, look through to see if that value is in the
// set
for (Object arg : predicate.getLiteralList()) {
predObj = getBaseObjectForComparison(predicate.getType(), (Comparable) arg);
if (range.compare(predObj) == Location.MIN) {
return range.addNull(TruthValue.YES);
}
}
return range.addNull(TruthValue.NO);
} else {
// are all of the values outside of the range?
for (Object arg : predicate.getLiteralList()) {
predObj = getBaseObjectForComparison(predicate.getType(), (Comparable) arg);
loc = range.compare(predObj);
if (loc == Location.MIN || loc == Location.MIDDLE ||
loc == Location.MAX) {
return range.addNull(TruthValue.YES_NO);
}
}
return range.addNull(TruthValue.NO);
}
case BETWEEN:
List<Object> args = predicate.getLiteralList();
if (args == null || args.isEmpty()) {
return range.addNull(TruthValue.YES_NO);
}
Comparable predObj1 = getBaseObjectForComparison(predicate.getType(),
(Comparable) args.get(0));
loc = range.compare(predObj1);
if (loc == Location.BEFORE || loc == Location.MIN) {
Comparable predObj2 = getBaseObjectForComparison(predicate.getType(),
(Comparable) args.get(1));
Location loc2 = range.compare(predObj2);
if (loc2 == Location.AFTER || loc2 == Location.MAX) {
return range.addNull(TruthValue.YES);
} else if (loc2 == Location.BEFORE) {
return range.addNull(TruthValue.NO);
} else {
return range.addNull(TruthValue.YES_NO);
}
} else if (loc == Location.AFTER) {
return range.addNull(TruthValue.NO);
} else {
return range.addNull(TruthValue.YES_NO);
}
case IS_NULL:
// min = null condition above handles the all-nulls YES case
return range.hasNulls ? TruthValue.YES_NO : TruthValue.NO;
default:
return range.addNull(TruthValue.YES_NO);
}
}