Skip to content

Commit

Permalink
[CALCITE-5988] SqlImplementor.toSql cannot emit VARBINARY literals
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaibudiu authored and libenchao committed Sep 17, 2023
1 parent f136c13 commit d9dd3ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(castNonNull(literal.getValueAs(byte[].class)), POS);
case ANY:
case NULL:
switch (typeName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ 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 testBinaryLiteral() {
String query = "SELECT x'ABCD'";
String expected = "SELECT X'ABCD'";
// We use Mysql here because using the default Calcite dialect
// the expected string is a bit too verbose:
// "SELECT *\nFROM (VALUES (X'ABCD')) AS \"t\" (\"EXPR$0\")"
sql(query).withMysql().ok(expected);
sql("SELECT cast(null as binary)").withMysql().ok("SELECT NULL");
}

@Test void testGroupByBooleanLiteral() {
String query = "select avg(\"salary\") from \"employee\" group by true";
String expectedRedshift = "SELECT AVG(\"employee\".\"salary\")\n"
Expand Down

0 comments on commit d9dd3ac

Please sign in to comment.