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


##########
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:
   For example, in the function call concat(x'61', UTF8'方解石'), the Chinese 
varchar '方解石' will be parsed as char(3), because it is three Chinese 
characters. The test framework performs secondary verification by directly 
adding the precision 3 of the char(3) and the precision 1 of the binary(1) 
x'61' to calculate 4.
   
   By modifying SqlReturnTypeInference##STRING_BYTESTRING_PRECISION, it can be 
calculated that the binary here should be binary(10). However, during the 
secondary verification of the current test 
framework(```StringTypeChecker##checkType```), it will fail because it 
calculates binary(4) itself.
   
   So I wonder if I should return the varbinary type directly here.



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