This is an automated email from the ASF dual-hosted git repository.

mihaibudiu 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 8c3696e5ef Firebolt dialect should quote identifiers that need quoting
8c3696e5ef is described below

commit 8c3696e5efda7cdf8be3af5fb083e8af134e9861
Author: bibi samina <[email protected]>
AuthorDate: Thu Jul 16 15:26:40 2026 +0530

    Firebolt dialect should quote identifiers that need quoting
---
 .../calcite/sql/dialect/FireboltSqlDialect.java    |  2 +-
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 32 ++++++++++------------
 2 files changed, 16 insertions(+), 18 deletions(-)

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 49b74d07ed..0b2d9e0e34 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
@@ -122,7 +122,7 @@ public FireboltSqlDialect(Context context) {
   }
 
   @Override protected boolean identifierNeedsQuote(String val) {
-    return IDENTIFIER_REGEX.matcher(val).matches()
+    return !IDENTIFIER_REGEX.matcher(val).matches()
         || RESERVED_KEYWORDS.contains(val.toUpperCase(Locale.ROOT));
   }
 
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 a534d8c206..affb7093f0 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
@@ -463,13 +463,7 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
         + "FROM foodmart.product\n"
         + "WHERE product_id > 0\n"
         + "GROUP BY product_id";
-    final String expectedFirebolt = "SELECT"
-        + " SUM(CASE WHEN \"net_weight\" > 0E0 IS TRUE"
-        + " THEN \"shelf_width\" ELSE NULL END), "
-        + "SUM(\"shelf_width\")\n"
-        + "FROM \"foodmart\".\"product\"\n"
-        + "WHERE \"product_id\" > 0\n"
-        + "GROUP BY \"product_id\"";
+    final String expectedFirebolt = expectedBigQuery;
     final String expectedMysql = "SELECT"
         + " SUM(CASE WHEN `net_weight` > 0E0 IS TRUE"
         + " THEN `shelf_width` ELSE NULL END), SUM(`shelf_width`)\n"
@@ -4043,12 +4037,16 @@ private SqlDialect nonOrdinalDialect() {
         + " 4 AS \"fo$ur\", 5 AS \"ignore\", 6 AS \"si`x\"\n"
         + "FROM foodmart.days) AS t\n"
         + "WHERE one < tWo AND THREE < \"fo$ur\"";
+    // Firebolt quotes like Exasol, except that IGNORE is not reserved
+    final String expectedFirebolt =
+        expectedExasol.replace("\"ignore\"", "ignore");
     sql(query)
         .withBigQuery().ok(expectedBigQuery)
         .withMysql().ok(expectedMysql)
         .withOracle().ok(expectedOracle)
         .withPostgresql().ok(expectedPostgresql)
-        .withExasol().ok(expectedExasol);
+        .withExasol().ok(expectedExasol)
+        .withFirebolt().ok(expectedFirebolt);
   }
 
   @Test void testModFunctionForHive() {
@@ -6210,7 +6208,7 @@ private void checkLiteral2(String expression, String 
expected) {
     String expectedPresto = "SELECT DATE_TRUNC('MINUTE', \"hire_date\")\n"
         + "FROM \"foodmart\".\"employee\"";
     String expectedTrino = expectedPresto;
-    String expectedFirebolt = expectedPostgresql;
+    String expectedFirebolt = expectedPostgresql.replace("\"", "");
     String expectedStarRocks = "SELECT DATE_TRUNC('MINUTE', `hire_date`)\n"
         + "FROM `foodmart`.`employee`";
     String expectedDoris = "SELECT DATE_TRUNC(`hire_date`, 'MINUTE')\n"
@@ -6510,16 +6508,16 @@ private void checkLiteral2(String expression, String 
expected) {
     final String sql0 = "select  * from \"employee\" where  \"hire_date\" - "
         + "INTERVAL '19800' SECOND(5) > TIMESTAMP '2005-10-17 00:00:00' ";
     final String expect0 = "SELECT *\n"
-        + "FROM \"foodmart\".\"employee\"\n"
-        + "WHERE (\"hire_date\" - INTERVAL '19800 SECOND ')"
+        + "FROM foodmart.employee\n"
+        + "WHERE (hire_date - INTERVAL '19800 SECOND ')"
         + " > TIMESTAMP '2005-10-17 00:00:00'";
     sql(sql0).withFirebolt().ok(expect0);
 
     final String sql1 = "select  * from \"employee\" where  \"hire_date\" + "
         + "INTERVAL '10' HOUR > TIMESTAMP '2005-10-17 00:00:00' ";
     final String expect1 = "SELECT *\n"
-        + "FROM \"foodmart\".\"employee\"\n"
-        + "WHERE (\"hire_date\" + INTERVAL '10 HOUR ')"
+        + "FROM foodmart.employee\n"
+        + "WHERE (hire_date + INTERVAL '10 HOUR ')"
         + " > TIMESTAMP '2005-10-17 00:00:00'";
     sql(sql1).withFirebolt().ok(expect1);
 
@@ -6617,7 +6615,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + " DATE_FORMAT(`hire_date`, '%Y-%m-%d %H:%i:00')\n"
         + "FROM `foodmart`.`employee`\n"
         + "GROUP BY DATE_FORMAT(`hire_date`, '%Y-%m-%d %H:%i:00')";
-    final String expectedFirebolt = expectedPostgresql;
+    final String expectedFirebolt = expectedPostgresql.replace("\"", "");
     sql(query)
         .withClickHouse().ok(expectedClickHouse)
         .withFirebolt().ok(expectedFirebolt)
@@ -6644,7 +6642,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"product\"";
     final String expectedSnowflake = expectedPostgresql;
     final String expectedRedshift = expectedPostgresql;
-    final String expectedFirebolt = expectedPresto;
+    final String expectedFirebolt = expectedPresto.replace("\"", "");
     final String expectedMysql = "SELECT SUBSTRING(`brand_name`, 2)\n"
         + "FROM `foodmart`.`product`";
     final String expectedStarRocks = "SELECT SUBSTRING(`brand_name`, 2)\n"
@@ -6684,7 +6682,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM \"foodmart\".\"product\"";
     final String expectedSnowflake = expectedPostgresql;
     final String expectedRedshift = expectedPostgresql;
-    final String expectedFirebolt = expectedPresto;
+    final String expectedFirebolt = expectedPresto.replace("\"", "");
     final String expectedMysql = "SELECT SUBSTRING(`brand_name`, 2, 3)\n"
         + "FROM `foodmart`.`product`";
     final String expectedMssql = "SELECT SUBSTRING([brand_name], 2, 3)\n"
@@ -8098,7 +8096,7 @@ private void checkLiteral2(String expression, String 
expected) {
         + "FROM (SELECT 1 AS a, 'x' AS b\n"
         + "UNION ALL\n"
         + "SELECT 2 AS a, 'yy' AS b)";
-    final String expectedFirebolt = expectedPostgresql;
+    final String expectedFirebolt = expectedPostgresql.replace("\"", "");
     final String expectedSnowflake = expectedPostgresql;
     final String expectedRedshift = "SELECT \"a\"\n"
         + "FROM (SELECT 1 AS \"a\", 'x ' AS \"b\"\n"

Reply via email to