Skip to content

Commit

Permalink
[CALCITE-6117] Converting SAFE_CAST from RexCall to SqlCall fails to …
Browse files Browse the repository at this point in the history
…add the type as an argument

Close apache#3520
  • Loading branch information
wnob authored and tanclary committed Nov 29, 2023
1 parent 578f44e commit bd7d4e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ private SqlNode callToSql(@Nullable RexProgram program, RexCall call0,
final List<SqlNode> nodeList = toSql(program, call.getOperands());
switch (call.getKind()) {
case CAST:
case SAFE_CAST:
// CURSOR is used inside CAST, like 'CAST ($0): CURSOR NOT NULL',
// convert it to sql call of {@link SqlStdOperatorTable#CURSOR}.
final RelDataType dataType = call.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,19 @@ private SqlDialect nonOrdinalDialect() {
.ok(expectedBqFormatDatetime);
}

/**
* Test that the type of a SAFE_CAST rex call is converted to an argument of the SQL call.
* See <a href="https://issues.apache.org/jira/browse/CALCITE-6117">[CALCITE-6117]</a>.
*/
@Test void testBigQuerySafeCast() {
final String query = "select safe_cast(\"product_name\" as date) "
+ "from \"foodmart\".\"product\"";
final String expected = "SELECT SAFE_CAST(\"product_name\" AS DATE)\n"
+ "FROM \"foodmart\".\"product\"";

sql(query).withLibrary(SqlLibrary.BIG_QUERY).ok(expected);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-3220">[CALCITE-3220]
* HiveSqlDialect should transform the SQL-standard TRIM function to TRIM,
Expand Down

0 comments on commit bd7d4e8

Please sign in to comment.