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 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-07-29 16:29:34 -07:00
parent 23d5b63421
commit b0fd51fe24

View File

@@ -2243,6 +2243,34 @@ def test_set_limit_value(
assert statement.format() == expected
@pytest.mark.parametrize(
"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",
[