Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
We found a bug in RelJson#toRex for the TIMESTAMP_DIFF call for Big Query dialect.
TIMESTAMP_DIFF is translated to the MINUS_DATE operator with a return type explicitly declared as the interval.
MINUS_DATE uses an ARG2_NULLABLE return type inference which requires 3 operands. This is fine in most cases where the RexCall is then used to generate SQL or for native implementations.
However, in RelJson#toRex, when it tries to reconstruct the entire call to a RexNode, it attempts to derive the return type of the MINUS_DATE operator using the ARG2_NULLABLE inference. This throws an error as there are only 2 operands given to the MINUS_DATE operator.
The solution here is to do something similar to how we handle CAST and to add in "type" when serializing to JSON in RelJson.toJson(RexNode node) for SqlKind.MINUS so that jsonType will be defined in toRex.