matriv opened a new pull request, #19379:
URL: https://github.com/apache/flink/pull/19379
## What is the purpose of the change
When in batch mode, the `getMonotonicity()` method of a function is
called, to determine possible optimisations. For `TRY_CAST` the
implementation needs to call `getOperandType(1)` to get the target (also
the function's return) type of the cast. This fails as for `CAST` and
`TRY_CAST` at this point we have only one operand.
`CAST` solves this in Calcite code, more specifically in
`RexCallBinding#create()` where in case the `kind` of the function is
`CAST`, a special `RexCastCallBinding` instance is created which stores
the return (target) type and returns it when `getOperandType(1)` is
called.
For `TRY_CAST` we don't have access to the stack to do something
similar, and we cannot set the kind of `TRY_CAST` to `CAST` (currently,
it's `OTHER_FUNCTION`, as this will allow the calcite stack to apply
rules and optimisations to the `TRY_CAST` call and at some point
convert it to a regular `CAST` call, thus breaking the functionality
of `TRY_CAST` (return null instead of failing).
As a solution to the problem, we simply don't implement the
`getMonotonicity()` method for `TRY_CAST`, lossing possible
optmisations.
## Brief change log
- Disable monotonicity for `TRY_CAST`
- Add tests
## Verifying this change
This change added tests and can be verified as follows:
- Added tests in `CalcITCase` which uses batch mode
- Added some additional tests to `ScalarOperatorsTest` for completeness
(these don't cover the bug fix)
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): **no**
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: **no**
- The serializers: **no**
- The runtime per-record code paths (performance sensitive): **no**
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: **no**
- The S3 file system connector: **no**
## Documentation
- Does this pull request introduce a new feature? **no**
- If yes, how is the feature documented? **not applicable**
--
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]