This is an automated email from the ASF dual-hosted git repository. jbalint pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/calcite.git
commit bae84c7e17e038169fefb7119bfd43af6707f8da Author: Aymeric <ayme...@firebolt.io> AuthorDate: Sat Jul 23 09:50:04 2022 +0100 [CALCITE-5217] Add support for INTERVAL qualifier for Firebolt --- .../apache/calcite/sql/dialect/FireboltSqlDialect.java | 15 +++++++++++++++ .../apache/calcite/rel/rel2sql/RelToSqlConverterTest.java | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java index 25a4859fd8..d76e902a27 100644 --- a/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/dialect/FireboltSqlDialect.java @@ -23,6 +23,7 @@ import org.apache.calcite.sql.SqlAlienSystemTypeNameSpec; import org.apache.calcite.sql.SqlCall; import org.apache.calcite.sql.SqlDataTypeSpec; import org.apache.calcite.sql.SqlDialect; +import org.apache.calcite.sql.SqlIntervalLiteral; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlLiteral; import org.apache.calcite.sql.SqlNode; @@ -200,4 +201,18 @@ public class FireboltSqlDialect extends SqlDialect { } } } + + @Override public void unparseSqlIntervalLiteral(SqlWriter writer, + SqlIntervalLiteral literal, int leftPrec, int rightPrec) { + SqlIntervalLiteral.IntervalValue interval = + literal.getValueAs(SqlIntervalLiteral.IntervalValue.class); + writer.keyword("INTERVAL"); + writer.print("'"); + if (interval.getSign() == -1) { + writer.print("-"); + } + writer.literal(interval.getIntervalLiteral()); + writer.print(interval.getIntervalQualifier().toString()); + writer.print("'"); + } } 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 5ef9e02126..05ef6e03c4 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 @@ -4004,6 +4004,16 @@ class RelToSqlConverterTest { sql(sql2).withBigQuery().throws_("Only INT64 is supported as the interval value for BigQuery."); } + @Test void testUnparseSqlIntervalQualifierFirebolt() { + final String sql = "select * from \"employee\" where \"hire_date\" + " + + "INTERVAL '10' HOUR > TIMESTAMP '2005-10-17 00:00:00' "; + + final String expect = "SELECT *\n" + + "FROM \"foodmart\".\"employee\"\n" + + "WHERE (\"hire_date\" + INTERVAL '10 HOUR')" + + " > TIMESTAMP '2005-10-17 00:00:00'"; + sql(sql).withFirebolt().ok(expect); + } @Test void testFloorMysqlWeek() { String query = "SELECT floor(\"hire_date\" TO WEEK) FROM \"employee\""; String expected = "SELECT STR_TO_DATE(DATE_FORMAT(`hire_date` , '%x%v-1'), '%x%v-%w')\n"