hanyuzheng7 opened a new pull request, #30138:
URL: https://github.com/apache/flink/pull/30138
## What is the purpose of the change
Comparing a numeric with a character string value with `=`, `<>` or `IS
[NOT] DISTINCT FROM` passes validation, but code generation rejects it because
implicit type conversion between them isn't supported (FLIP-154). The error
names only the two type roots, doesn't say which expression failed or how to
fix it, and "now" reads like a temporary limitation:
```sql
SELECT * FROM T WHERE int_col = str_col;
```
```
org.apache.flink.table.api.ValidationException: implicit type conversion
between INTEGER and VARCHAR is not supported now
```
In a join condition, `JoinConditionTypeCoerceRule` fails with its own
message (FLINK-29556).
With this change, validation fails with:
```
Cannot compare INT with STRING in '`T`.`int_col` = `T`.`str_col`'. Implicit
type conversion between numeric and character string types is not supported.
Use CAST to convert one side explicitly, e.g. CAST(`T`.`str_col` AS INT).
```
`<`, `>`, `BETWEEN` and `IN` with a list of values don't change: they
already convert their operands to a common type. A query in which the optimizer
removes such a comparison before code generation, e.g. `WHERE int_col = str_col
OR TRUE`, used to run and now fails validation.
## Brief change log
- `FlinkCalciteSqlValidator#validateCall` rejects `=`, `<>`, `IS DISTINCT
FROM` and `IS NOT DISTINCT FROM` between a numeric and a character string, also
in a join condition and in the comparisons that `CASE value WHEN ...` and
`NULLIF` are rewritten to.
- The check in `ScalarOperatorGens` stays for the comparisons that the
validator doesn't see, e.g. of the fields of two ROWs.
## Verifying this change
- Added
`ScalarOperatorsValidationTest#testNumericAndCharacterStringComparison`.
- `ImplicitConversionEqualsFunctionITCase`,
`JoinTestBase#testJoinNonMatchingKeyTypes` and the lookup join cases in
`LookupJoinTest` (batch and stream) now expect the new error during validation.
- Some tests compared a numeric with a character string by mistake, so their
queries couldn't run. They now compare values of the same type, without
changing what they test:
- `SimplifyFilterConditionRuleTest`: `c = 3` is now `c = '3'`, as `c` is a
STRING.
- `ChangelogModeInferenceTest#testTemporalJoinWithEqualConditionOnKey`:
`o.currency = 5` is now `o.currency = '5'`.
- `FlinkLogicalRankRuleForConstantRangeTest` and
`FlinkLogicalRankRuleForRangeEndTest`, `testRankValueFilterWithVariableField4`:
`rk = b` (a STRING) is now `rk = c` (a BIGINT). The rank end is still the
variable field, `rankEnd=c` instead of `rankEnd=b`.
- `MatchRecognizeValidationTest#testMatchPythonFunction`: `b = 'b'` is now
`b = 2`, as `b` is an INT.
- `StateTtlHintTest#testJoinStateTtlHintWithSubQueryContainsJoin`: `T1.a1
= TMP.b2` is now `T1.a1 = TMP.a2`.
## 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]