xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176362585


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2545,6 +2545,30 @@ void testCastToBoolean(CastType castType, 
SqlOperatorFixture f) {
     f.checkNull("cast(null as integer array) || array[1]");
   }
 
+  /** Test case for <a 
href="https://issues.apache.org/jira/browse/CALCITE-7063";>
+   * Result type inferred for CONCAT_FUNCTION is incorrect for BINARY 
arguments</a>. */
+  @Test void testConcatFuncMysql() {
+    final SqlOperatorFixture f = fixture().withLibrary(SqlLibrary.MYSQL);
+
+    // test for ByteString
+    f.setFor(SqlLibraryOperators.CONCAT_FUNCTION_MYSQL);
+    f.checkString("concat('a', x'61')", "6161", "BINARY(2) NOT NULL");
+    f.checkString("concat('abc', 'bb', 'cc')", "abcbbcc", "VARCHAR(7) NOT 
NULL");
+    f.checkString("concat(x'616263',x'62')", "61626362", "BINARY(4) NOT NULL");
+    f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT 
NULL");
+    f.checkString("concat(x'61',x'62')", "6162", "BINARY(2) NOT NULL");
+    f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "

Review Comment:
   There may be some problems with my description. 
   The current precision logic is directly based on the type precision. For 
example, the precision of char(3) and char(1) is varchar(4), and binary(3) and 
char(1) return varbinary type without clear precision.
   
   If the length of binary and char is inferred in returnType, the test 
framework will do a secondary verification. For details, you can see the 
StringTypeChecker##checkType method:
   ```
       @Override public void checkType(Supplier<String> sql, RelDataType type) {
         String actual = getTypeString(type);
         assertThat(sql.get(), actual, is(expected));
       }
   ```
   
   ```
     public static String getTypeString(RelDataType sqlType) {
       switch (sqlType.getSqlTypeName()) {
       case VARCHAR:
       case CHAR:
         String actual = sqlType.getSqlTypeName().name();
         if (sqlType.getPrecision() != RelDataType.PRECISION_NOT_SPECIFIED) {
           actual = actual + "(" + sqlType.getPrecision() + ")";
         }
         if (!sqlType.isNullable()) {
           actual += RelDataTypeImpl.NON_NULLABLE_SUFFIX;
         }
         return actual;
   
       default:
         return sqlType.getFullTypeString();
       }
     }
   ```
   
   The function(```SqlReturnTypeInference##STRING_BYTESTRING_PRECISION```) can 
be modified to return the correct length of binary(10) type, but the 
verification in ```StringTypeChecker##checkType``` here is completely based on 
the Type to do precision superposition. Here, char(3) and binary(1) will be 
calculated as 4, which conflicts with the correct test result.
   So I changed binary(N) to varbinary return type.



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