mihaibudiu commented on code in PR #3558:
URL: https://github.com/apache/calcite/pull/3558#discussion_r1412903187
##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -6827,6 +6827,35 @@ private void checkGetTimestamp(Connection con) throws
SQLException {
"Cannot apply = to the two different charsets ISO-8859-1 and
UTF-16LE");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6146">[CALCITE-6146]
+ * Target charset should be used when comparing two strings through
+ * CONVERT/TRANSLATE function during validation</a>. */
+ @Test void testStringComparisonWithConvertFunc() {
+ CalciteAssert.AssertThat with = CalciteAssert.hr();
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where convert(\"name\" using GBK)=_GBK'Eric'")
+ .returns("name=Eric; empid=200\n");
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where _BIG5'Eric'=translate(\"name\" using BIG5)")
+ .returns("name=Eric; empid=200\n");
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where convert(convert(\"name\" using GBK) using BIG5)=_BIG5'Eric'")
+ .returns("name=Eric; empid=200\n");
+ // the charset of char(5) is ISO-8859-1 preserved in Collate
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where cast(convert(\"name\" using GBK) as char(5))=_BIG5'Eric'")
+ .throws_(
+ "Cannot apply = to the two different charsets ISO-8859-1 and
Big5");
Review Comment:
Have you tried a similar test as a SqlOperatorTest as well, just to make
sure that it triggers there as well?
I don't think this change is JDBC specific.
##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -6827,6 +6827,35 @@ private void checkGetTimestamp(Connection con) throws
SQLException {
"Cannot apply = to the two different charsets ISO-8859-1 and
UTF-16LE");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6146">[CALCITE-6146]
+ * Target charset should be used when comparing two strings through
+ * CONVERT/TRANSLATE function during validation</a>. */
+ @Test void testStringComparisonWithConvertFunc() {
+ CalciteAssert.AssertThat with = CalciteAssert.hr();
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where convert(\"name\" using GBK)=_GBK'Eric'")
+ .returns("name=Eric; empid=200\n");
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where _BIG5'Eric'=translate(\"name\" using BIG5)")
+ .returns("name=Eric; empid=200\n");
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where convert(convert(\"name\" using GBK) using BIG5)=_BIG5'Eric'")
+ .returns("name=Eric; empid=200\n");
+ // the charset of char(5) is ISO-8859-1 preserved in Collate
+ with.query("select \"name\", \"empid\" from \"hr\".\"emps\"\n"
+ + "where cast(convert(\"name\" using GBK) as char(5))=_BIG5'Eric'")
+ .throws_(
+ "Cannot apply = to the two different charsets ISO-8859-1 and
Big5");
Review Comment:
I know you didn't write this error message, but I think it can be improved.
I would write "Cannot apply operation '=' to strings with different charsets
'ISO-8859-1' and 'Big5'`
##########
core/src/main/java/org/apache/calcite/sql/SqlBinaryOperator.java:
##########
@@ -140,7 +140,13 @@ private RelDataType convertType(SqlValidator validator,
SqlCall call, RelDataTyp
if (SqlTypeUtil.inCharFamily(operandType0)
&& SqlTypeUtil.inCharFamily(operandType1)) {
Charset cs0 = operandType0.getCharset();
+ if (call.operand(0) instanceof SqlBasicCall) {
Review Comment:
Is this the right place for this check?
Why does the operandType0 have the wrong charset?
Maybe the bug is in the place where the charset for operand0 type was
inferred.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]