xiangfu0 commented on code in PR #20070:
URL: https://github.com/apache/pinot/pull/20070#discussion_r4420677731
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rex/PinotRexExecutor.java:
##########
@@ -105,6 +120,48 @@ Function1<DataContext, Object[]> getCast(RexBuilder
builder, RelDataType source,
});
}
+ /// Returns whether the expression casts a non-null numeric literal to an
approximate type (DOUBLE, FLOAT, REAL) and
+ /// the result is finite. Overflow to infinity is left to the fallback,
which decides how to represent it.
+ @VisibleForTesting
+ static boolean isNumericToApproximateCast(RexNode expression) {
+ if (!(expression instanceof RexCall)) {
+ return false;
+ }
+ RexCall call = (RexCall) expression;
+ if (call.getOperator() != SqlStdOperatorTable.CAST ||
call.getOperands().size() != 1
+ || !SqlTypeUtil.isApproximateNumeric(call.getType())) {
+ return false;
+ }
+ RexNode operand = call.getOperands().get(0);
+ return operand instanceof RexLiteral && !((RexLiteral) operand).isNull()
+ && SqlTypeUtil.isNumeric(operand.getType()) &&
Double.isFinite(approximateValue(call));
Review Comment:
Minor, latent: approximate source literals don't match Calcite here.
`getValueAs(BigDecimal.class)` rounds a DOUBLE literal to DECIMAL64 (16
digits), so `CAST(<DOUBLE 0.30000000000000004> AS DOUBLE)` folds to `0.3`. For
NaN or Infinity it throws `NumberFormatException` from this check, which runs
outside the `try`, so the exception escapes `reduce()` instead of the batch
being kept. A local fuzz found 3101 of 10k DOUBLE-source cases differing from
Calcite, and none with exact sources. I couldn't reach either case from SQL,
because `canRemoveCastFromLiteral` folds approximate-to-approximate casts
before the executor runs. Restricting this check to
`SqlTypeUtil.isExactNumeric(operand.getType())` would close the gap and still
cover query vectors. Separately, a nullable target loses the cast that keeps it
nullable, which the string path preserves through `makeLiteral(value, type,
true)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]