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

rusackas pushed a commit to branch tdd/issue-36939-starrocks-sqlglot-dialect
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b0fd51fe2432a5d905220ca94918fd95cebe9e7e
Author: Claude Code <[email protected]>
AuthorDate: Wed Jul 29 16:29:34 2026 -0700

    test(sql): SHOW statements must not get a forced LIMIT (#36939)
    
    set_limit_value's FORCE_LIMIT path unconditionally sets
    _parsed.args["limit"] on any statement, including SHOW TABLES/
    DATABASES/CREATE TABLE. sqlglot's Show expression has no real LIMIT
    slot to hold that value, so it renders a malformed statement with two
    LIMIT keywords instead of rejecting cleanly. StarRocks (and likely
    other engines using FORCE_LIMIT) reject the result outright, which is
    exactly the "Unexpected input 'LIMIT'" error reported in #36939 for
    SHOW TABLES / SHOW DATABASES / SHOW CREATE TABLE.
    
    This is unrelated to the other two statements in that issue (REFRESH
    EXTERNAL TABLE, DROP ... FORCE) — those fail to parse at the sqlglot
    layer entirely, confirmed still true against the pinned sqlglot
    30.12.0 for every dialect tried, not just starrocks. That's an
    upstream sqlglot dialect gap, not something fixable in this repo, so
    it's out of scope here.
    
    This is a test-only PR; the test is expected to be RED (confirms the
    bug, does not fix it). Not using a closing keyword since merging this
    alone won't resolve #36939.
    
    Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---
 tests/unit_tests/sql/parse_tests.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/unit_tests/sql/parse_tests.py 
b/tests/unit_tests/sql/parse_tests.py
index bec1849a196..d5dc161b738 100644
--- a/tests/unit_tests/sql/parse_tests.py
+++ b/tests/unit_tests/sql/parse_tests.py
@@ -2243,6 +2243,34 @@ def test_set_limit_value(
     assert statement.format() == expected
 
 
[email protected](
+    "sql",
+    [
+        "SHOW TABLES",
+        "SHOW DATABASES",
+        "SHOW CREATE TABLE test.will_test1",
+    ],
+)
+def test_set_limit_value_leaves_show_statements_unchanged(sql: str) -> None:
+    """
+    Regression for #36939: FORCE_LIMIT must not touch ``SHOW`` statements.
+
+    ``SHOW`` statements have no `LIMIT` clause in sqlglot's expression tree,
+    so forcing one via ``args["limit"]`` doesn't reject cleanly, it produces
+    a malformed statement with two ``LIMIT`` keywords (one from a stray
+    rendering of the bare ``Limit`` expression, one from the forced value).
+    StarRocks (and presumably other engines) reject that outright: "Getting
+    syntax error ... Unexpected input 'LIMIT'". The statement should be
+    left untouched instead, matching how ``SELECT`` statements without a
+    scannable row source aren't force-limited either.
+    """
+    statement = SQLStatement(sql, "starrocks")
+    original = statement.format()
+    statement.set_limit_value(1000, LimitMethod.FORCE_LIMIT)
+    assert statement.format() == original
+    assert "LIMIT" not in statement.format()
+
+
 @pytest.mark.parametrize(
     "kql, limit, expected",
     [

Reply via email to