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

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


The following commit(s) were added to refs/heads/master by this push:
     new 30021f8ede fix(pinot): `SUBSTR` function (#35427)
30021f8ede is described below

commit 30021f8edef43849e30f942b2ed44e0d8888000c
Author: Beto Dealmeida <[email protected]>
AuthorDate: Thu Oct 2 10:29:18 2025 -0400

    fix(pinot): `SUBSTR` function (#35427)
---
 superset/sql/dialects/pinot.py               |  6 ++++++
 tests/unit_tests/sql/dialects/pinot_tests.py | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/superset/sql/dialects/pinot.py b/superset/sql/dialects/pinot.py
index 417d5fd111..ef8ad14be5 100644
--- a/superset/sql/dialects/pinot.py
+++ b/superset/sql/dialects/pinot.py
@@ -108,6 +108,12 @@ class Pinot(MySQL):
                 e.args.get("expression"),
                 e.this,
             ),
+            exp.Substring: lambda self, e: self.func(
+                "SUBSTR",
+                e.this,
+                e.args.get("start"),
+                e.args.get("length"),
+            ),
         }
         # Remove DATE_TRUNC transformation - Pinot supports standard SQL 
DATE_TRUNC
         TRANSFORMS.pop(exp.DateTrunc, None)
diff --git a/tests/unit_tests/sql/dialects/pinot_tests.py 
b/tests/unit_tests/sql/dialects/pinot_tests.py
index 88dcfb9384..16169c6849 100644
--- a/tests/unit_tests/sql/dialects/pinot_tests.py
+++ b/tests/unit_tests/sql/dialects/pinot_tests.py
@@ -590,3 +590,25 @@ def test_pinot_date_sub_unit_quoted() -> None:
     # The unit should be quoted: 'DAY' not DAY
     assert "DATE_SUB('DAY', -180, NOW())" in result
     assert "DATE_SUB(DAY," not in result
+
+
+def test_substr_cross_dialect_generation() -> None:
+    """
+    Test that SUBSTR is preserved when generating Pinot SQL.
+
+    Note that the MySQL dialect (in which Pinot is based) uses SUBSTRING 
instead of
+    SUBSTR.
+    """
+    # Parse with Pinot dialect
+    pinot_sql = "SELECT SUBSTR('hello', 0, 3) FROM users"
+    parsed = sqlglot.parse_one(pinot_sql, Pinot)
+
+    # Generate back to Pinot → should preserve SUBSTR
+    pinot_output = parsed.sql(dialect=Pinot)
+    assert "SUBSTR(" in pinot_output
+    assert "SUBSTRING(" not in pinot_output
+
+    # Generate to MySQL → should convert to SUBSTRING
+    mysql_output = parsed.sql(dialect="mysql")
+    assert "SUBSTRING(" in mysql_output
+    assert pinot_output != mysql_output  # They should be different

Reply via email to