You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "libenchao (via GitHub)" <gi...@apache.org> on 2023/09/14 11:38:22 UTC

[GitHub] [calcite] libenchao commented on a diff in pull request #3419: [CALCITE-5988] SqlImplementor.toSql cannot emit VARBINARY literals

libenchao commented on code in PR #3419:
URL: https://github.com/apache/calcite/pull/3419#discussion_r1325816333


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -220,6 +220,16 @@ private static String toSql(RelNode root, SqlDialect dialect,
         .getSql();
   }
 
+  /**
+   * Test for <a href="https://issues.apache.org/jira/browse/CALCITE-5988">[CALCITE-5988]</a>
+   * SqlImplementor.toSql cannot emit VARBINARY literals.
+   */
+  @Test void testBinary() {

Review Comment:
   how about name it `testBinaryLiteral`, it's more precise.



##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -220,6 +220,16 @@ private static String toSql(RelNode root, SqlDialect dialect,
         .getSql();
   }
 
+  /**
+   * Test for <a href="https://issues.apache.org/jira/browse/CALCITE-5988">[CALCITE-5988]</a>
+   * SqlImplementor.toSql cannot emit VARBINARY literals.
+   */
+  @Test void testBinary() {
+    String query = "SELECT x'ABCD'";
+    String expected = "SELECT X'ABCD'";
+    sql(query).withMysql().ok(expected);

Review Comment:
   Is `withMysql` necessary to reproduce the issue, if not, I'd suggest to just use `sql(query).ok(exptected)`



##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -1437,6 +1437,8 @@ public static SqlNode toSql(RexLiteral literal) {
       return SqlLiteral.createTimestamp(typeName,
           castNonNull(literal.getValueAs(TimestampString.class)),
           literal.getType().getPrecision(), POS);
+    case BINARY:
+      return SqlLiteral.createBinaryString(requireNonNull(literal.getValueAs(byte[].class)), POS);

Review Comment:
   I'm wondering if `select cast(null as binary)` would work for current implementation. It's true that all other types does not consider `null`, they may suffer from the same problem.



##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -1437,6 +1437,8 @@ public static SqlNode toSql(RexLiteral literal) {
       return SqlLiteral.createTimestamp(typeName,
           castNonNull(literal.getValueAs(TimestampString.class)),
           literal.getType().getPrecision(), POS);
+    case BINARY:
+      return SqlLiteral.createBinaryString(requireNonNull(literal.getValueAs(byte[].class)), POS);

Review Comment:
   NIT: why not use `castNonNull` to keep it the same with other 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