MartijnVisser commented on code in PR #30138:
URL: https://github.com/apache/flink/pull/30138#discussion_r4772737858


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/calcite/FlinkCalciteSqlValidator.java:
##########
@@ -172,6 +173,55 @@ public void validateLiteral(SqlLiteral literal) {
         super.validateLiteral(literal);
     }
 
+    @Override
+    public void validateCall(SqlCall call, SqlValidatorScope scope) {
+        super.validateCall(call, scope);
+        checkNoNumericAndCharacterStringComparison(call, scope);
+    }
+
+    /**
+     * Rejects a comparison of a numeric with a character string value, e.g. 
{@code int_col =
+     * str_col}. It would need an implicit type conversion, which isn't 
supported (see FLIP-154), so
+     * code generation would fail on it.
+     */
+    private void checkNoNumericAndCharacterStringComparison(SqlCall call, 
SqlValidatorScope scope) {
+        switch (call.getKind()) {
+            case EQUALS:
+            case NOT_EQUALS:
+            case IS_DISTINCT_FROM:
+            case IS_NOT_DISTINCT_FROM:
+                break;
+            default:
+                return;
+        }
+        final SqlValidatorScope operandScope = scope.getOperandScope(call);
+        final RelDataType leftType = deriveType(operandScope, call.operand(0));
+        final RelDataType rightType = deriveType(operandScope, 
call.operand(1));
+        final int stringOperand;
+        if (SqlTypeUtil.isNumeric(leftType) && 
SqlTypeUtil.isCharacter(rightType)) {

Review Comment:
   `ROW<a INT>` = `ROW<a STRING>` runs and is FALSE for `ROW(1)` and 
`ROW('1')`, ARRAY too, while MAP values compare as TRUE. Checking nested types 
here rejects all three and covers ROW constructors.



-- 
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]

Reply via email to