You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "xuzifu666 (via GitHub)" <gi...@apache.org> on 2025/06/22 14:09:27 UTC
[PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
xuzifu666 opened a new pull request, #4431:
URL: https://github.com/apache/calcite/pull/4431
jira: https://issues.apache.org/jira/browse/CALCITE-7063
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "ILuffZhe (via GitHub)" <gi...@apache.org>.
ILuffZhe commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161497204
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I'm not sure if changing it to VARCHAR_NULLABLE is suitable, can we get binary's precision in ReturnTypes?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3882036763
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3383905398
I have tried the codegen solution for this part recently, but it has not been solved yet. Referring to other functions, the return type can be varbinary. In this pr, is it possible to return varbinary first instead of binary(N) type? @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176419360
##########
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:
The calculation of 4 is that the default logic of STRING_BYTESTRING_PRECISION was wrong before, but it has been deleted. The current situation is:
Execute
```f.checkString("concat(_UTF8'方煤石', x'61')", "e696b9e8a7a3e79fb361",
"BINARY(10) NOT NULL");```
SqlTester will perform two verifications:
The first is
```concat(_UTF8'方煤石', x'61')```, which infers that binary(10) is fine,
but it will also perform a second verification:
```select concat(p1, p0) from (values (x'61', _UTF8'方煤石')) as t(p0, p1)```
Here, whether it returns binary(10) or varbinary neither will be consistent with the expected result
```BINARY(10) NOT NULL```.
Because this situation will cause this case to fail.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176447664
##########
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:
The problem occurs when one of the two is of character type. In the subquery, the precision cannot be correctly deduced because it is not of literal 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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176704924
##########
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:
```f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT NULL"); ```This correctly calculates binary(6) probably because 'abc' is an English character, and the length of a character is 1, here would be char(3) and binary(3), result 6 is OK. But if it is a Chinese character, the number of bytes in 'calcite' should be 9, because Chinese characters occupy 3 bytes.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160367416
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
Review Comment:
According to the documentation, the concat function should be able to use both string and bytestring, so the previous definition is wrong and should be directly replaced with Object... instead of String...
case refer cases in MySQL as follow:
```
mysql> select concat(binary('a'),null);
+----------------------------------------------------+
| concat(binary('a'),null) |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat(binary('a'),'b');
+--------------------------------------------------+
| concat(binary('a'),'b') |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'));
+--------------------------------------------------+
| concat('a',binary('b')) |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'),null);
+------------------------------------------------------------+
| concat('a',binary('b'),null) |
+------------------------------------------------------------+
| NULL |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a','b');
+-----------------+
| concat('a','b') |
+-----------------+
| ab |
+-----------------+
1 row in set (0.00 sec)
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2175603911
##########
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:
please add here one test with Chinese characters and binary, I would like to see the size of the inferred type
that is not visible in the quidem tests
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176426421
##########
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:
Do you have an explanation why the other tests pass?
Why can it the type for the other ones and not for this one?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3488845561
> I don't understand the question. Who should return VARBINARY, and what does it mean to "return first?"
Sorry, I didn't see the PR information immediately and just noticed it recently. What I meant was, could this function directly return a **varbinary** type instead of **binary**(N), that is, a type without specifying the exact number of bits? @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3488864374
I expect that the type computed for the result will be inferred in a similar way as for CHAR/VARCHAR.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176426299
##########
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:
I am not sure if I have expressed it clearly, but this test case will execute two statements:
One is the origin sql, which is fine and can match binary(10) normally. However, SqlTester is still trying to determine the second subquery case. Since it is not literal, the result will not be consistent with binary(10).
This is what I found during debugging. This is why other function tests do not have this problem, because other functions do not have mixed types and only need to add precision directly according to data type. In this way, the second subquery verification can pass normally.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176230766
##########
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:
Had added the case, but currently Calcite type deduction can only identify calculations based on the type in advance. If Chinese characters are included, it seems difficult to accurately calculate the precision. For example, the following test returns binary(4) because Char(3) and binary(1) are received when the type is deduced. However, each Chinese character occupies 3 bytes. In addition, if the chars are mixed with Chinese and English, it is even more difficult to deduce. Can we use varbinary type when return binary type, a type without precision? @mihaibudiu
```
f.checkString("concat(_UTF8'方解石', x'61')", "e696b9e8a7a3e79fb361", "BINARY(4) NOT NULL");
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176458268
##########
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:
the query does not calculate precisions, the type inference does
your statement must be wrong, since here:
`f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT NULL");`
the precision has been computed for a binary and a char.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3021658367
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [10.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
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));
}
```
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "ILuffZhe (via GitHub)" <gi...@apache.org>.
ILuffZhe commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160577068
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
Why is it VARCHAR(3)?
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
- return String.join("", args);
+ public static String concatMulti(Object... args) {
Review Comment:
This function is also enabled in BIG_QUERY, do they behave the same?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3383971010
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [5 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [10.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161552178
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I have considered this precision issue before, but the concat function supports int/double/... (all types that can be cast as string) not only ```string/bytestring``` types. Even if we define a SqlReturnTypeInference, we cannot accurately calculate the exact precision of the int type.
For example, for INT, we can only get the precision of 10 from type. eg ```concat(x'61', 1, 'a')```, the type sequence we get is ```binary(1), int(10), varchar(1)```, It would definitely unreasonable to infer the length of 12, so I think VARCHAR_NULLABLE can only be used at this position. Choosing this ReturnTypes should not affect the result, such as SqlFunction BASE64. If you have other suggestions also can tell me.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "ILuffZhe (via GitHub)" <gi...@apache.org>.
ILuffZhe commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161485838
##########
site/_docs/reference.md:
##########
@@ -2832,7 +2832,8 @@ In the following:
| b | CODE_POINTS_TO_BYTES(integers) | Converts *integers*, an array of integers between 0 and 255 inclusive, into bytes; throws error if any element is out of range
| b | CODE_POINTS_TO_STRING(integers) | Converts *integers*, an array of integers between 0 and 0xD7FF or between 0xE000 and 0x10FFFF inclusive, into string; throws error if any element is out of range
| o r | CONCAT(string, string) | Concatenates two strings, returns null only when both string arguments are null, otherwise treats null as empty string
-| b m | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| b | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| m | CONCAT(any [, any ]*) | Concatenates one or more strings/bytestrings/..., if arguments contains bytestring would return bytes string and returns null if any of the arguments is null
Review Comment:
Except string and bytestring, what else is supported? If not, maybe you should remove ... .
How about "returns null if any of the arguments is null, and returns bytes string if any of the arguments is a bytestring"
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1200,6 +1200,21 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
SqlFunctionCategory.STRING)
.withOperandTypeInference(InferTypes.RETURN_TYPE);
+ /** The "CONCAT(arg, ...)" function that concatenates arguments.
+ * For example, "CONCAT('a', 'bc', 'd')" returns "abcd",
+ * "CONCAT(x'61', 'a')" returns "0x6161".
+ *
+ * <p>It accepts at least 1 argument and returns null if any of
+ * the arguments is null, if arguments contain bytestring, would return bytes string. */
Review Comment:
how about "... is null, and returns bytes string if any of the arguments is a bytestring"
##########
core/src/main/java/org/apache/calcite/util/BuiltInMethod.java:
##########
@@ -523,6 +523,7 @@ public enum BuiltInMethod {
PARSE_URL3(SqlFunctions.ParseUrlFunction.class, "parseUrl", String.class,
String.class, String.class),
MULTI_STRING_CONCAT(SqlFunctions.class, "concatMulti", String[].class),
+ MULTI_STRING_CONCAT_OBJECTS(SqlFunctions.class, "concatMultiObjects", Object[].class),
Review Comment:
MULTI_STRING_CONCAT_WITH_BINARY, WDYT?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176353948
##########
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 is no reason to infer a length 4.
it goes through the same function you wrote.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176419360
##########
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:
The calculation of 4 is that the default logic of STRING_BYTESTRING_PRECISION was wrong before, but it has been deleted. The current situation is:
Execute
```f.checkString("concat(_UTF8'方煤石', x'61')", "e696b9e8a7a3e79fb361", "BINARY(10) NOT NULL");```
SqlTester will perform two verifications:
The first is
```concat(_UTF8'方煤石', x'61')```, which infers that binary(10) is fine,
but then it will also perform a second verification:
```select concat(p1, p0) from (values (x'61', _UTF8'方煤石')) as t(p0, p1)```
Here, whether it returns binary(10) or varbinary neither will be consistent with the expected result
```BINARY(10) NOT NULL```.
Both of these validations need to be fully matched with a result.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176426421
##########
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:
Do you have an explanation why the other tests pass?
Why can it infer the type for the other ones and not for this one?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176466785
##########
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:
Yes, the latest submitted version returns varbinary for (binary, char), which is not a problem.
However, the previous version that calculates binary precision will definitely fail, because the subquery(```select concat(p1, p0) from (values (x'616263', 'abc')) as t(p0, p1)```) cannot calculate the accurate precision of non-literal, which leads to a conflict with the test case result.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2175156053
##########
core/src/test/resources/sql/functions.iq:
##########
@@ -184,6 +185,81 @@ SELECT CONCAT('a');
!ok
+SELECT CONCAT('a', 'b', 'c');
++--------+
+| EXPR$0 |
++--------+
+| abc |
++--------+
+(1 row)
+
+!ok
+
+SELECT CONCAT('a', x'61');
++--------+
+| EXPR$0 |
++--------+
+| 6161 |
++--------+
+(1 row)
+
+!ok
+
+SELECT CONCAT(x'61', x'62');
++--------+
+| EXPR$0 |
++--------+
+| 6162 |
++--------+
+(1 row)
+
+!ok
+
+SELECT CONCAT('a', x'61', null);
++--------+
+| EXPR$0 |
++--------+
+| |
++--------+
+(1 row)
+
+!ok
+
+SELECT CONCAT(cast(1 as varchar), 'a');
Review Comment:
https://issues.apache.org/jira/browse/CALCITE-7078 had been resolve now, I had some problems using it before,It can support Chinese characters, and I added Chinese and binary tests, and the results should be in line with expectations.
```
SELECT CONCAT(x'61', _UTF8'方解石');
+----------------------+
| EXPR$0 |
+----------------------+
| 61e696b9e8a7a3e79fb3 |
+----------------------+
(1 row)
```
PTAL @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176408531
##########
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:
first, the compiler may optimize this expression and perhaps may be able to compute the precision.
but even if it's not, the precision of the result computed this way should not be 4; it should be unlimited at least
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176426299
##########
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:
I am not sure if I have expressed it clearly, but this test case will execute two statements:
One is the origin sql, which is fine and can match binary(10) normally. However, SqlTester is still trying to determine the second subquery case. Since it is not literal, the result will not be consistent with binary(10).
This is what I found during debugging. This is why other function tests do not have this problem, because other functions do not have mixed types and only need to add directly according to data type. In this way, the second subquery verification can pass normally.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176448321
##########
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:
what is "direct precision addition"? there is no such thing
The tester also has to evaluate an expression with concat and values.
Why does it manage to compute the precision in this case?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176704924
##########
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:
```f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT NULL"); ```This correctly calculates binary(6) probably because 'abc' is an English character, and the length of a character is 1. But if it is a Chinese character, the number of bytes in 'calcite' should be 9, because Chinese characters occupy 3 bytes.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176237343
##########
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:
It is indeed possible to calculate the bytes length of char through SqlOperatorBinding and then deduce the precision, but there are some problems with the current Calcite Test process
SqlTester##checkType will still do a second check, but it will still be based on the Type.
```
@Override public void checkType(Supplier<String> sql, RelDataType type) {
String actual = **getTypeString**(type);
assertThat(sql.get(), actual, is(expected));
}
```
This will still infer that actual is 4, and will eventually lead to verification failure:
```
java.lang.AssertionError: Query: select concat(p1, p0) from (values (x'61', _UTF8'方解石')) as t(p0, p1)
Expected: is "BINARY(10) NOT NULL"
but: was "BINARY(4) NOT NULL"
```
So currently I return the varbinary type directly when return type is binary. @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176367957
##########
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:
I don't know what precision superposition is.
What has type char(3)?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160634639
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
```ReturnTypes.MULTIVALENT_STRING_SUM_PRECISION_NULLABLE``` is directly judged based on the type of the passed parameter, ```x'61'``` as ```binary(1)```, ```x'6162'``` as ```binary(2)```. However, currently MySQL needs to check whether the parameter exists as a bytestring, so for the sake of safety, I changed it to VARCHAR_NULLABLE. @ILuffZhe
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2162057050
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1655,6 +1655,34 @@ public static String concatMulti(String... args) {
return String.join("", args);
}
+ /** SQL {@code CONCAT(obj0, obj1, obj2, ...)} function. */
+ public static String concatMultiObjects(Object... args) {
Review Comment:
I am afraid this will cause problems for more general programs.
The Java code generated by the enumerable implementation is relatively strongly typed, and it will expect ByteArray for the result of some calls. Please add some quidem tests to check.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-2994251087
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160367416
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
Review Comment:
According to the documentation(https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_concat), the concat function should be able to use both string and bytestring, so the previous definition is wrong and should be directly replaced with Object... instead of String...
case refer cases in MySQL as follow:
```
mysql> select concat(binary('a'),null);
+----------------------------------------------------+
| concat(binary('a'),null) |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat(binary('a'),'b');
+--------------------------------------------------+
| concat(binary('a'),'b') |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'));
+--------------------------------------------------+
| concat('a',binary('b')) |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'),null);
+------------------------------------------------------------+
| concat('a',binary('b'),null) |
+------------------------------------------------------------+
| NULL |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a','b');
+-----------------+
| concat('a','b') |
+-----------------+
| ab |
+-----------------+
1 row in set (0.00 sec)
mysql> select concat(binary('a'), 1);
+------------------------------------------------+
| concat(binary('a'), 1) |
+------------------------------------------------+
| 0x6131 |
+------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160634639
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
```ReturnTypes.MULTIVALENT_STRING_SUM_PRECISION_NULLABLE``` is directly judged based on the type of the passed parameter, ```x'61'``` as ```binary(1)``` which length is 1, ```x'6162'``` as ```binary(2)``` which length is 2. However, currently MySQL needs to check whether the parameter exists as a bytestring, so for the sake of safety, I changed it to VARCHAR_NULLABLE. @ILuffZhe
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 closed pull request #4431: [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments
URL: https://github.com/apache/calcite/pull/4431
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176419360
##########
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:
The calculation of 4 is that the default logic of STRING_BYTESTRING_PRECISION was wrong before, but it has been deleted. The current situation is:
Execute
```f.checkString("concat(_UTF8'方煤石', x'61')", "e696b9e8a7a3e79fb361", "BINARY(10) NOT NULL");```
SqlTester will perform two verifications:
The first is
```concat(_UTF8'方煤石', x'61')```, which infers that binary(10) is fine,
but then it will also perform a second verification:
```select concat(p1, p0) from (values (x'61', _UTF8'方煤石')) as t(p0, p1)```
Here, whether it returns binary(10) or varbinary neither will be consistent with the expected result
```BINARY(10) NOT NULL```.
Because this situation will cause this case to fail.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176438746
##########
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:
What about this test you wrote:
`f.checkString("concat(x'61',x'62')", "6162", "BINARY(2) NOT NULL");`
This one has precision 2. Why does it 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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176455634
##########
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:
Yes,literal is not a type. SqlTester itself does not calculate precision, but it will call SqlReturnTypeInference##STRING_BYTESTRING_PRECISION to calculate precision. It is called twice, once with origin sql, and the result calculated by this method is completely correct. Then the second method will be called again with a subquery to get another result. Both results need to match the test case results to pass.
However, if it is (binary, char), the subquery cannot calculate the precision correctly, so unless the varbinary type is returned, the results will be inconsistent with the normal precision.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176704924
##########
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:
```f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT NULL"); ```This correctly calculates binary(6) probably because 'abc' is an English character, and the length of a character is 1, here would be char(3) and binary(3), result 6 is OK. But if it is a Chinese character such as '方解石', the number of bytes in 'calcite' should be 9, because a Chinese character occupy 3 bytes.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2162906660
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1655,6 +1655,34 @@ public static String concatMulti(String... args) {
return String.join("", args);
}
+ /** SQL {@code CONCAT(obj0, obj1, obj2, ...)} function. */
+ public static String concatMultiObjects(Object... args) {
Review Comment:
OK, it seems to be different from what I understand. Maybe I need to sort out these issues again. I will set this PR as a draft first, and reopen it after all the tests are completed.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "caicancai (via GitHub)" <gi...@apache.org>.
caicancai commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2203230453
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1191,7 +1191,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
*
* <p>It accepts at least 1 argument and returns null if any of
* the arguments is null. */
- @LibraryOperator(libraries = {MYSQL, BIG_QUERY})
+ @LibraryOperator(libraries = {BIG_QUERY})
Review Comment:
I have a BigQuery test environment and BigQuery does not support concat returning Binary 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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3488906760
> I expect that the type computed for the result will be inferred in a similar way as for CHAR/VARCHAR.
I think this suggestion is fine. The current issue is that when processing such as Chinese characters, a bug in the codegen prevents it from directly calculating the exact number of digits, while it works well for Latin characters. Considering other functions like ```SqlLibraryOperators.BASE64```, which also directly returns a varchar type without number of digits, if it's determined that a precise number of binary digits is required, then we may need to continue investigating this issue.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3615188912
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161552178
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I have considered this precision issue before, but the concat function supports int/double/... (all types that can be cast as string) not only ```string/binary``` types. Even if we define a ```SqlReturnTypeInference```, we cannot accurately calculate the exact precision of the int type.
For example, for ```INT```, we can only get the precision of 10 from type. eg ```concat(x'61', 1, 'a')```, the type sequence we get is ```binary(1), int(10), char(1)```, It would definitely unreasonable to infer the length of 12, so I think VARCHAR_NULLABLE can only be used at this position. Choosing this ReturnTypes should not affect the result, such as ```SqlFunction BASE64```. If you have other suggestions also can tell me.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161561656
##########
core/src/main/java/org/apache/calcite/util/BuiltInMethod.java:
##########
@@ -523,6 +523,7 @@ public enum BuiltInMethod {
PARSE_URL3(SqlFunctions.ParseUrlFunction.class, "parseUrl", String.class,
String.class, String.class),
MULTI_STRING_CONCAT(SqlFunctions.class, "concatMulti", String[].class),
+ MULTI_STRING_CONCAT_OBJECTS(SqlFunctions.class, "concatMultiObjects", Object[].class),
Review Comment:
As mentioned above support many types(string/binary/numberic...)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [WIP][CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2162906660
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1655,6 +1655,34 @@ public static String concatMulti(String... args) {
return String.join("", args);
}
+ /** SQL {@code CONCAT(obj0, obj1, obj2, ...)} function. */
+ public static String concatMultiObjects(Object... args) {
Review Comment:
OK, it seems to be different from what I understand. Maybe I need to sort out these issues again. I will set this PR as a WIP first, and reopen it after all the tests are completed.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176237343
##########
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:
OK, thanks~ would change it.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176406354
##########
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:
The reason is that a subquery will also be executed from the SqlTester:
```Query: select concat(p1, p0) from (values (x'61', _UTF8'方解石')) as t(p0, p1)```
Here, p0 and p1 are not literals, so the precision cannot be accurately calculated. This subquery is generated by the current SqlTester secondary verify. @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176435134
##########
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:
Yes, some of the problems I described have nothing to do with mixed types. As far as I know, other functions return varchar or varbinary types without precision directly, so there is no need to calculate the precision, and even if there is a subquery verification, it can be matched directly.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176427238
##########
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:
this has absolutely nothing to do with "mixed types"
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176466785
##########
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:
Yes, the latest submitted version returns varbinary for (binary, char), which is not a problem.
However, the previous version that calculates binary precision will definitely fail, because the subquery cannot calculate the accurate precision of non-literal, which leads to a conflict with the test case result.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2179103421
##########
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:
What probably happens is that the query optimizer generates code to try to optimize parts of the query, the code is compiled using Janino, it is executed, and it throws; the exception is caught, and the code is left unoptimized. It would be nice to figure out why it crashes and to fix the problem that causes the crash.
There are two places where you can place breakpoints: RexExecutorImpl.reduce, and EnumerableInterpretable.toBindable.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161569632
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1200,6 +1200,21 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
SqlFunctionCategory.STRING)
.withOperandTypeInference(InferTypes.RETURN_TYPE);
+ /** The "CONCAT(arg, ...)" function that concatenates arguments.
+ * For example, "CONCAT('a', 'bc', 'd')" returns "abcd",
+ * "CONCAT(x'61', 'a')" returns "0x6161".
+ *
+ * <p>It accepts at least 1 argument and returns null if any of
+ * the arguments is null, if arguments contain bytestring, would return bytes string. */
Review Comment:
Make sense, done.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160966046
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1191,7 +1191,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
*
* <p>It accepts at least 1 argument and returns null if any of
* the arguments is null. */
- @LibraryOperator(libraries = {MYSQL, BIG_QUERY})
+ @LibraryOperator(libraries = {BIG_QUERY})
Review Comment:
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#concat
From this document, it seems that BigQuery should not keep the same behavior as MySQL's concat function( BigQuery return string or bytes, MySQL return string or bytes string ), but I don't have a corresponding test environment to verify BigQuery. In addition, this issue is mainly to solve the MySQL concat compatibility issue, so I keep BigQuery's concat function as before. @NobiGo
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3119883804
According to discussion, codegen problem need to be fixed first,so close this pr first.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176237343
##########
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:
It is indeed possible to calculate the bytes length of char through SqlOperatorBinding and then deduce the precision, but there are some problems with the current Calcite Test process
SqlTester##checkType will still do a second check, but it will still be based on the Type.
```
@Override public void checkType(Supplier<String> sql, RelDataType type) {
String actual = getTypeString(type);
assertThat(sql.get(), actual, is(expected));
}
```
This will still infer that actual is 4, and will eventually lead to verification failure:
```
java.lang.AssertionError: Query: select concat(p1, p0) from (values (x'61', _UTF8'方解石')) as t(p0, p1)
Expected: is "BINARY(10) NOT NULL"
but: was "BINARY(4) NOT NULL"
```
So currently I return the varbinary type directly when return type is binary. @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
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 4 ( 3 + 1 => 4 directly).
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176376029
##########
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:
the test framework has no reason to add precisions.
you have to find out where the 4 is coming from.
there must be a bug somewhere else.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176419360
##########
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:
The calculation of 4 is that the default logic of STRING_BYTESTRING_PRECISION was wrong before, but it has been deleted. The current situation is:
Execute
```f.checkString("concat(_UTF8'方煤石', x'61')", "e696b9e8a7a3e79fb361", "BINARY(10) NOT NULL");```
SqlTester will perform two verifications:
The first is
```concat(_UTF8'方煤石', x'61')```, which infers that binary(10) is fine,
but it will also perform a second verification:
```select concat(p1, p0) from (values (x'61', _UTF8'方煤石')) as t(p0, p1)```
Here, whether it returns binary(10) or varbinary neither will be consistent with the expected result
```BINARY(10) NOT NULL```.
Because this situation will cause this case to fail.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176420950
##########
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:
still, what does the second verification return?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176423293
##########
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:
Because the second validation is not literal, the precision cannot be directly obtained, second verification return varbinary directly, which conflicts with the ```binary(10) not null``` of the test statement, resulting in failure.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176445852
##########
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:
Because in this case, whether it is a direct query or a subquery, both parameters are binary(1), and here the direct precision addition is binary(2). Regardless of whether it is a literal, its calculation logic is the same.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176450068
##########
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:
literal is not a 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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160966046
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1191,7 +1191,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
*
* <p>It accepts at least 1 argument and returns null if any of
* the arguments is null. */
- @LibraryOperator(libraries = {MYSQL, BIG_QUERY})
+ @LibraryOperator(libraries = {BIG_QUERY})
Review Comment:
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#concat
From this document, it seems that BigQuery should not keep the same behavior as MySQL's concat function( BigQuery return string or bytes, MySQL return string or bytes string ), but I don't have a corresponding test environment to verify BigQuery. In addition, this issue is mainly to solve the MySQL concat compatibility issue, so I keep BigQuery's concat function as before.
https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_concat
from MySQL document, The document clearly states that the returned results are all strings. @NobiGo
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160367416
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
Review Comment:
According to the documentation(https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_concat), the concat function should be able to use both string and bytestring, so the previous definition is wrong and should be directly replaced with Object... instead of String...
case refer cases in MySQL as follow:
```
mysql> select concat(binary('a'),null);
+----------------------------------------------------+
| concat(binary('a'),null) |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat(binary('a'),'b');
+--------------------------------------------------+
| concat(binary('a'),'b') |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'));
+--------------------------------------------------+
| concat('a',binary('b')) |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'),null);
+------------------------------------------------------------+
| concat('a',binary('b'),null) |
+------------------------------------------------------------+
| NULL |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a','b');
+-----------------+
| concat('a','b') |
+-----------------+
| ab |
+-----------------+
1 row in set (0.00 sec)
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-2995251696
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [7 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3021404988
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [4 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [10.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176447664
##########
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:
The problem occurs when one paramteris character type,the other is binary. In the subquery, the precision cannot be correctly deduced because it is not of literal 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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176704924
##########
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:
```f.checkString("concat(x'616263','abc')", "616263616263", "BINARY(6) NOT NULL"); ```This correctly calculates binary(6) probably because 'abc' is an English character, and the length of a character is 1, here would be char(3) and binary(3), result 6 is OK. But if it is a Chinese character such as '方解石', the number of bytes in 'calcite' should be 9, because Chinese characters occupy 3 bytes.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176230766
##########
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:
Had added the case, but currently Calcite type deduction can only identify calculations based on the type in advance. If Chinese characters are included, it seems difficult to accurately calculate the precision. For example, the following test returns binary(4) because Char(3) and binary(1) are received when the type is deduced. However, each Chinese character occupies 3 bytes. In addition, if the chars are mixed with Chinese and English, it is even more difficult to deduce. Can we use varbinary, a type without precision? @mihaibudiu
```
f.checkString("concat(_UTF8'方解石', x'61')", "e696b9e8a7a3e79fb361", "BINARY(4) NOT NULL");
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161552178
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I have considered this precision issue before, but the concat function supports int/double/... (all types that can be cast as string) not only ```string/bytestring``` types. Even if we define a SqlReturnTypeInference, we cannot accurately calculate the exact precision of the int type.
For example, for INT, we can only get the precision of 10 from type. eg ```concat(x'61', 1, 'a')```, the type sequence we get is ```binary(1), int(10), char(1)```, It would definitely unreasonable to infer the length of 12, so I think VARCHAR_NULLABLE can only be used at this position. Choosing this ReturnTypes should not affect the result, such as SqlFunction BASE64. If you have other suggestions also can tell me.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161964255
##########
site/_docs/reference.md:
##########
@@ -2832,7 +2832,8 @@ In the following:
| b | CODE_POINTS_TO_BYTES(integers) | Converts *integers*, an array of integers between 0 and 255 inclusive, into bytes; throws error if any element is out of range
| b | CODE_POINTS_TO_STRING(integers) | Converts *integers*, an array of integers between 0 and 0xD7FF or between 0xE000 and 0x10FFFF inclusive, into string; throws error if any element is out of range
| o r | CONCAT(string, string) | Concatenates two strings, returns null only when both string arguments are null, otherwise treats null as empty string
-| b m | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| b | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| m | CONCAT(any [, any ]*) | Concatenates one or more strings/bytestrings/..., if arguments contains bytestring would return bytes string and returns null if any of the arguments is null
Review Comment:
That's not correct. The function only accepts CHAR and BINARY arguments; the other arguments are accepted because the compiler ill insert implicit casts. That's a completely separate issue, which has no bearing to this function.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 closed pull request #4431: [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments
URL: https://github.com/apache/calcite/pull/4431
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3386736760
I don't understand the question. Who should return VARBINARY, and what does it mean to "return first?"
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-3019375429
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [4 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [11.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176231989
##########
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:
that's exactly what I wanted to see.
you can use VARBINARY, but since the character string is a literal, you should be able to evaluate the number of bytes it needs.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176466785
##########
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:
Yes, the latest submitted version returns varbinary for (binary, char), which is not a problem.
However, the previous version that calculates binary precision will definitely fail, because the subquery(```select concat(p1, p0) from (values (x'616263', abc')) as t(p0, p1)```) cannot calculate the accurate precision of non-literal, which leads to a conflict with the test case result.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176406354
##########
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:
The reason is that a subquery will also be executed from the SqlTester:
```Query: select concat(p1, p0) from (values (x'61', _UTF8'方解石')) as t(p0, p1)```
Here, p0 and p1 are not literals, so the precision cannot be accurately calculated. This subquery is generated by the current SqlTester secondary detection logic. @mihaibudiu
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2176419360
##########
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:
The calculation of 4 is that the default logic of STRING_BYTESTRING_PRECISION was wrong before, but it has been deleted. The current situation is:
Execute
```f.checkString("concat(_UTF8'方煤石', x'61')", "e696b9e8a7a3e79fb361",
"BINARY(10) NOT NULL");```
SqlTester will perform two verifications:
The first is
```concat(_UTF8'方煤石', x'61')```, which infers that binary(10) is fine,
but it will also perform a second verification:
```select concat(p1, p0) from (values (x'61', _UTF8'方煤石')) as t(p0, p1)```
Here, whether it returns binary(10) or varbinary neither will be consistent with the expected result ```BINARY(10) NOT NULL```.
Because this situation will cause this case to fail.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160367416
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
Review Comment:
According to the documentation(https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_concat), the concat function should be able to use both string and bytestring, so the previous definition is wrong and should be directly replaced with Object... instead of String...
case refer cases in MySQL as follow:
```
mysql> select concat(binary('a'),null);
+----------------------------------------------------+
| concat(binary('a'),null) |
+----------------------------------------------------+
| NULL |
+----------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat(binary('a'),'b');
+--------------------------------------------------+
| concat(binary('a'),'b') |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'));
+--------------------------------------------------+
| concat('a',binary('b')) |
+--------------------------------------------------+
| 0x6162 |
+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a',binary('b'),null);
+------------------------------------------------------------+
| concat('a',binary('b'),null) |
+------------------------------------------------------------+
| NULL |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select concat('a','b');
+-----------------+
| concat('a','b') |
+-----------------+
| ab |
+-----------------+
1 row in set (0.00 sec)
```
```
mysql> select concat(binary('a'), 1);
+------------------------------------------------+
| concat(binary('a'), 1) |
+------------------------------------------------+
| 0x6131 |
+------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
```
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160632255
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1651,8 +1651,31 @@ public static ByteString concat(ByteString s0, ByteString s1) {
}
/** SQL {@code CONCAT(arg0, arg1, arg2, ...)} function. */
- public static String concatMulti(String... args) {
- return String.join("", args);
+ public static String concatMulti(Object... args) {
Review Comment:
Thanks for reminder,I am not sure whether this is the case with BigQuery, and there is no relevant environment to test and verify it locally. In addition, the current main issue is the concat issue of MySQL, so for the sake of insurance, I had isolated MySQL and BigQuery separately.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161552178
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I have considered this precision issue before, but the concat function supports int/double/... (all types that can be cast as string) not only ```string/bytestring``` types. Even if we define a SqlReturnTypeInference, we cannot accurately calculate the exact precision of the int type.
For example, for INT, we can only get the precision of 10 from type. eg ```concat(x'61', 1, 'a')```, the type sequence we get is ```binary(1), int(10), varchar(1)```. It is definitely unreasonable to infer the length of 12, so I think VARCHAR_NULLABLE can only be used at this position. Choosing this ReturnTypes should not affect the result, such as SqlFunction BASE64. If you have other suggestions also can tell me.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4431:
URL: https://github.com/apache/calcite/pull/4431#issuecomment-2996498983
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431) **Quality Gate passed**
Issues
 [7 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4431&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4431&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [94.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4431&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4431)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161552178
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -2565,6 +2568,17 @@ private static void checkConcatFunc(SqlOperatorFixture f) {
f.checkString("concat('', '', 'a')", "a", "VARCHAR(1) NOT NULL");
f.checkString("concat('', '', '')", "", "VARCHAR(0) NOT NULL");
f.checkFails("^concat()^", INVALID_ARGUMENTS_NUMBER, false);
+
+ // test for ByteString
+ f.checkString("concat(x'61',x'62')", "0x6162", "VARCHAR(2) NOT NULL");
+ f.checkString("concat(cast(x'61' as binary), cast(x'62' as binary), "
+ + "cast(x'63' as binary))", "0x616263", "VARCHAR(3) NOT NULL");
Review Comment:
I have considered this precision issue before, but the concat function supports int/double/... (all types that can be cast as string) not only ```string/binary``` types. Even if we define a SqlReturnTypeInference, we cannot accurately calculate the exact precision of the int type.
For example, for INT, we can only get the precision of 10 from type. eg ```concat(x'61', 1, 'a')```, the type sequence we get is ```binary(1), int(10), char(1)```, It would definitely unreasonable to infer the length of 12, so I think VARCHAR_NULLABLE can only be used at this position. Choosing this ReturnTypes should not affect the result, such as SqlFunction BASE64. If you have other suggestions also can tell me.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2161557588
##########
site/_docs/reference.md:
##########
@@ -2832,7 +2832,8 @@ In the following:
| b | CODE_POINTS_TO_BYTES(integers) | Converts *integers*, an array of integers between 0 and 255 inclusive, into bytes; throws error if any element is out of range
| b | CODE_POINTS_TO_STRING(integers) | Converts *integers*, an array of integers between 0 and 0xD7FF or between 0xE000 and 0x10FFFF inclusive, into string; throws error if any element is out of range
| o r | CONCAT(string, string) | Concatenates two strings, returns null only when both string arguments are null, otherwise treats null as empty string
-| b m | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| b | CONCAT(string [, string ]*) | Concatenates one or more strings, returns null if any of the arguments is null
+| m | CONCAT(any [, any ]*) | Concatenates one or more strings/bytestrings/..., if arguments contains bytestring would return bytes string and returns null if any of the arguments is null
Review Comment:
As description above, MySQL concat function not only support string/bytestring, also support numberic types(which can cast to string type would all support). so IMO ```...``` maybe necessary.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "NobiGo (via GitHub)" <gi...@apache.org>.
NobiGo commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2160926908
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1191,7 +1191,7 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding operatorBinding,
*
* <p>It accepts at least 1 argument and returns null if any of
* the arguments is null. */
- @LibraryOperator(libraries = {MYSQL, BIG_QUERY})
+ @LibraryOperator(libraries = {BIG_QUERY})
Review Comment:
Does BigQuery offer different returns for Binary?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7063] Result type inferred for CONCAT_FUNCTION is incorrect for BINARY arguments [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4431:
URL: https://github.com/apache/calcite/pull/4431#discussion_r2179245775
##########
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:
OK,there is indeed a problem here.,I would do some research about this.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org