lowka commented on code in PR #2368:
URL: https://github.com/apache/ignite-3/pull/2368#discussion_r1279089223


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/IgniteSqlValidator.java:
##########
@@ -399,6 +403,54 @@ public RelDataType deriveType(SqlValidatorScope scope, 
SqlNode expr) {
         return dataType;
     }
 
+    /** Check appropriate type cast availability. */
+    private void checkCastCorrectness(SqlValidatorScope scope, SqlNode expr) {
+        if (expr.getKind() == SqlKind.CAST) {
+            SqlBasicCall expr0 = (SqlBasicCall) expr;
+            SqlNode first = expr0.getOperandList().get(0);
+            SqlNode ret = expr0.getOperandList().get(1);
+
+            RelDataType firstType;
+            RelDataType returnType = super.deriveType(scope, ret);
+
+            if (first instanceof SqlDynamicParam) {
+                firstType = getDynamicParamType((SqlDynamicParam) first);
+            } else {
+                firstType = super.deriveType(scope, first);
+            }
+
+            RelDataType returnCustomType = returnType instanceof 
IgniteCustomType ? returnType : null;
+            RelDataType fromCustomType = firstType instanceof IgniteCustomType 
? firstType : null;
+
+            boolean customTypeCheck = true;
+
+            if (returnCustomType != null) {
+                customTypeCheck = 
returnType.toString().equals(firstType.toString());
+
+                if (!customTypeCheck) {
+                    IgniteCustomTypeCoercionRules coercionRules = 
((IgniteTypeFactory) typeFactory).getCustomTypeCoercionRules();
+
+                    String returnTypeName = returnType.toString();
+                    SqlTypeName firstTypeName = firstType.getSqlTypeName();
+
+                    customTypeCheck = SqlTypeUtil.inCharFamily(returnType)
+                            || 
coercionRules.canCastFrom(returnTypeName).contains(firstTypeName);

Review Comment:
   `returnType.toString` returns more than a type name, so 
`coercionRules.canCastFrom(returnTypeName)` might fail when it shouldn't. 
   
   In addition to that comparing string representation of types != comparing 
types, so it does not guarantee to work.
   



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