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

michaelsmolina pushed a commit to branch 5.0
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 3eda2223ca995fb5a6564e5c05e9b3a8b7001323
Author: Beto Dealmeida <[email protected]>
AuthorDate: Mon Feb 24 11:12:34 2025 -0500

    fix(firebolt): allow backslach escape for single quotes (#32350)
    
    (cherry picked from commit 22fe985cfc36a8d798fd53a3e21559511d382ebe)
---
 superset/sql/dialects/firebolt.py   |  5 ++++-
 tests/unit_tests/sql/parse_tests.py | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/superset/sql/dialects/firebolt.py 
b/superset/sql/dialects/firebolt.py
index a4767596f4..cfdfc2dfe6 100644
--- a/superset/sql/dialects/firebolt.py
+++ b/superset/sql/dialects/firebolt.py
@@ -17,7 +17,7 @@
 
 from __future__ import annotations
 
-from sqlglot import exp, generator, parser
+from sqlglot import exp, generator, parser, tokens
 from sqlglot.dialects.dialect import Dialect
 from sqlglot.helper import csv
 from sqlglot.tokens import TokenType
@@ -84,6 +84,9 @@ class FireboltOld(Firebolt):
     function.
     """
 
+    class Tokenizer(tokens.Tokenizer):
+        STRING_ESCAPES = ["'", "\\"]
+
     class Parser(Firebolt.Parser):
         TABLE_ALIAS_TOKENS = Firebolt.Parser.TABLE_ALIAS_TOKENS - 
{TokenType.UNNEST}
 
diff --git a/tests/unit_tests/sql/parse_tests.py 
b/tests/unit_tests/sql/parse_tests.py
index 2df24a1b3a..8dc06aeea3 100644
--- a/tests/unit_tests/sql/parse_tests.py
+++ b/tests/unit_tests/sql/parse_tests.py
@@ -1164,3 +1164,24 @@ def test_firebolt_old() -> None:
   *
 FROM t1 UNNEST(col1 AS foo)"""
     )
+
+
+def test_firebolt_old_escape_string() -> None:
+    """
+    Test the dialect for the old Firebolt syntax.
+    """
+    from superset.sql.dialects import FireboltOld
+    from superset.sql.parse import SQLGLOT_DIALECTS
+
+    SQLGLOT_DIALECTS["firebolt"] = FireboltOld
+
+    # both '' and \' are valid escape sequences
+    sql = r"SELECT 'foo''bar', 'foo\'bar'"
+
+    # but they normalize to ''
+    assert (
+        SQLStatement(sql, "firebolt").format()
+        == """SELECT
+  'foo''bar',
+  'foo''bar'"""
+    )

Reply via email to