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 26, 2025
1 parent d83122b commit 0f77a0a
Show file tree
Hide file tree
Showing 2 changed files with 17 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);
// Refer: 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 @@ -9146,6 +9146,17 @@ private void checkLiteral2(String expression, String expected) {
sql(query).withOracle().ok(oracle);
}

/** 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);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6771">[CALCITE-6771]
* Convert Type from FLOAT to DOUBLE in PrestoDialect</a>. */
Expand All @@ -9160,6 +9171,8 @@ private void checkLiteral2(String expression, String expected) {
.withPresto().ok(expected);
}



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

0 comments on commit 0f77a0a

Please sign in to comment.