This is an automated email from the ASF dual-hosted git repository.
tanner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new bd7d4e89c5 [CALCITE-6117] Converting SAFE_CAST from RexCall to SqlCall
fails to add the type as an argument
bd7d4e89c5 is described below
commit bd7d4e89c5c4a01d4e5897fc04be224dcddaecae
Author: Will Noble <[email protected]>
AuthorDate: Mon Nov 13 17:24:13 2023 -0800
[CALCITE-6117] Converting SAFE_CAST from RexCall to SqlCall fails to add
the type as an argument
Close #3520
---
.../java/org/apache/calcite/rel/rel2sql/SqlImplementor.java | 1 +
.../apache/calcite/rel/rel2sql/RelToSqlConverterTest.java | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git
a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 9d39dbf9cb..c9b3c4eb09 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -814,6 +814,7 @@ public abstract class SqlImplementor {
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();
diff --git
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 1578d0112e..79b6b0b983 100644
---
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -2251,6 +2251,19 @@ class RelToSqlConverterTest {
.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,