Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6796] Convert Type from BINARY to VARBINARY in PrestoDialect #4167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the link to VARBINARY for presto, as presto does not support varbinary(n) and this may cause confusion

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
Loading