|
@@ -115,6 +115,7 @@ public class Range extends ScalarFunction implements TranslationAware.SingleValu
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean foldable() {
|
|
|
+ // NB: this is likely dead code. See note in areBoundariesInvalid
|
|
|
if (lower.foldable() && upper.foldable()) {
|
|
|
if (value().foldable()) {
|
|
|
return true;
|
|
@@ -130,6 +131,7 @@ public class Range extends ScalarFunction implements TranslationAware.SingleValu
|
|
|
|
|
|
@Override
|
|
|
public Object fold(FoldContext ctx) {
|
|
|
+ // NB: this is likely dead code. See note in areBoundariesInvalid
|
|
|
Object lowerValue = lower.fold(ctx);
|
|
|
Object upperValue = upper.fold(ctx);
|
|
|
if (areBoundariesInvalid(lowerValue, upperValue)) {
|
|
@@ -149,6 +151,19 @@ public class Range extends ScalarFunction implements TranslationAware.SingleValu
|
|
|
* If they are, the value does not have to be evaluated.
|
|
|
*/
|
|
|
protected boolean areBoundariesInvalid(Object lowerValue, Object upperValue) {
|
|
|
+ /*
|
|
|
+ NB: I am reasonably sure this code is dead. It can only be reached from foldable(), and as far as I can tell
|
|
|
+ we never fold ranges. There's no ES|QL syntax for ranges, so they can never be created by the parser. The
|
|
|
+ PropagateEquals optimizer rule can in theory create ranges, but only from existing ranges. The fact that this
|
|
|
+ class is not serializable (note that writeTo throws UnsupportedOperationException) is a clear indicator that
|
|
|
+ logical planning cannot output Range nodes.
|
|
|
+
|
|
|
+ PushFiltersToSource can also create ranges, but that is a Physical optimizer rule. Folding happens in the
|
|
|
+ Logical optimization layer, and should be done by the time we are calling PushFiltersToSource.
|
|
|
+
|
|
|
+ That said, if somehow you have arrived here while debugging something, know that this method is likely
|
|
|
+ completely broken for date_nanos, and possibly other types.
|
|
|
+ */
|
|
|
if (DataType.isDateTime(value.dataType()) || DataType.isDateTime(lower.dataType()) || DataType.isDateTime(upper.dataType())) {
|
|
|
try {
|
|
|
if (upperValue instanceof String upperString) {
|