Skip to content

Commit

Permalink
[CALCITE-6796] Convert Type from BINARY to VARBINARY in PrestoDialect
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochen-zhou committed Jan 25, 2025
1 parent d83122b commit ba8be32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ private static void unparseUsingLimit(SqlWriter writer, @Nullable SqlNode offset
case FLOAT:
return new SqlDataTypeSpec(
new SqlBasicTypeNameSpec(SqlTypeName.DOUBLE, SqlParserPos.ZERO), SqlParserPos.ZERO);
// https://prestodb.io/docs/current/language/types.html#varbinary
case BINARY:
return new SqlDataTypeSpec(
new SqlBasicTypeNameSpec(SqlTypeName.VARBINARY, SqlParserPos.ZERO), SqlParserPos.ZERO);
default:
return super.getCastSpec(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9160,6 +9160,20 @@ private void checkLiteral2(String expression, String expected) {
.withPresto().ok(expected);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6796">[CALCITE-6796]
* Convert Type from BINARY to VARBINARY in PrestoDialect</a>. */
@Test void testPrestoBinaryCast() {
String query = "SELECT cast(cast(\"employee_id\" as varchar) as binary)"
+ "from \"foodmart\".\"reserve_employee\" ";
String expected = "SELECT CAST(CAST(\"employee_id\" AS VARCHAR) AS VARBINARY)"
+ "\nFROM \"foodmart\".\"reserve_employee\"";
sql(query)
.withPresto().ok(expected);
}



/** Fluid interface to run tests. */
static class Sql {
private final CalciteAssert.SchemaSpec schemaSpec;
Expand Down

0 comments on commit ba8be32

Please sign in to comment.