bito-code-review[bot] commented on code in PR #43809:
URL: https://github.com/apache/superset/pull/43809#discussion_r3921826223
##########
tests/unit_tests/sql/parse_tests.py:
##########
@@ -2756,6 +2785,336 @@ def
test_set_limit_value_leaves_show_statements_unchanged(
assert "LIMIT" not in statement.format()
[email protected](
+ "sql, expected_catalog, expected_db",
+ [
+ ("SHOW TABLES IN catalog_1.schema_a", "catalog_1", "schema_a"),
+ ("SHOW TABLES FROM catalog_1.schema_a", "catalog_1", "schema_a"),
+ ("SHOW TABLES IN schema_a", None, "schema_a"),
+ ("SHOW TABLES FROM schema_a", None, "schema_a"),
+ ("SHOW DATABASES IN catalog_1", None, "catalog_1"),
+ ],
+)
+def test_show_tables_in_catalog_qualified_schema(
+ sql: str, expected_catalog: str | None, expected_db: str
+) -> None:
+ """
+ StarRocks supports a catalog-qualified schema reference in
+ ``SHOW TABLES/DATABASES FROM|IN <schema>``, e.g.
+ ``SHOW TABLES IN catalog.schema``, which sqlglot's MySQL-derived parser
+ doesn't support: the schema is parsed with ``_parse_id_var()``, which only
+ ever consumes a single identifier, leaving the ``.schema`` part dangling
+ and rejected as an unexpected token. The
``superset.sql.dialects.StarRocks``
+ override reparses the schema with
``_parse_table_parts(is_db_reference=True)``
+ so a dotted ``catalog.schema`` (or a plain schema) both parse correctly.
+ """
+ show = SQLStatement(sql, "starrocks")._parsed
+ assert isinstance(show, exp.Show)
+
+ db = show.args.get("db")
+ assert isinstance(db, exp.Table)
+ catalog = db.args.get("catalog")
+ assert (catalog.name if catalog else None) == expected_catalog
+ assert db.args.get("db").name == expected_db
+
+
+def test_show_binlog_events_in_log_name_still_parses() -> None:
+ """
+ Regression guard: the override must not break the pre-existing meaning of
+ ``IN`` for ``SHOW BINLOG/RELAYLOG EVENTS IN 'log_name'``, where ``IN``
+ introduces a string log name rather than a schema reference.
+ """
+ show = SQLStatement(
+ "SHOW BINLOG EVENTS IN 'log.000001' FROM 4", "starrocks"
+ )._parsed
+ assert isinstance(show, exp.Show)
+ assert show.args.get("log").name == "log.000001"
+ assert show.args.get("position").name == "4"
+
+
[email protected](
+ "sql",
+ [
+ # Admin / cluster / job-control statements sqlglot's MySQL-derived
+ # grammar has no dedicated handling for, so it used to try (and
+ # fail) to read the head keyword as a generic expression.
+ 'ADMIN SET FRONTEND CONFIG ("disable_balance" = "true")',
+ 'ADMIN CHECK TABLET (10000, 10001) PROPERTIES("type" = "consistency")',
+ "ADMIN REPAIR TABLE tbl1 PARTITION (p1, p2)",
+ "BACKUP SNAPSHOT example_db.snapshot_label1 TO example_repo "
+ 'PROPERTIES ("type" = "full")',
+ "RESTORE SNAPSHOT example_db.snapshot_label1 FROM example_repo "
+ 'ON (backup_tbl) PROPERTIES("backup_timestamp"="2018-05-04-16-45-08")',
+ "RECOVER DATABASE example_db",
+ "RECOVER TABLE example_db.example_tbl",
+ "RECOVER PARTITION p1 FROM example_tbl",
+ "CANCEL BACKUP FROM example_db",
+ "CANCEL RESTORE FROM example_db",
+ 'CANCEL LOAD WHERE LABEL = "example_label"',
+ 'CANCEL EXPORT WHERE queryid = "921d8f80-7c9d-11eb-9342-acde48001121"',
+ "CANCEL ALTER TABLE COLUMN FROM example_db.my_table",
+ 'EXPORT TABLE testTbl TO "hdfs://h:9000/a/b/c/testTbl_" WITH BROKER',
+ "PAUSE ROUTINE LOAD FOR example_db.example_tbl1_ordertest1",
+ "RESUME ROUTINE LOAD FOR example_db.example_tbl1_ordertest1",
+ "STOP ROUTINE LOAD FOR example_db.example_tbl1_ordertest1",
+ "SUBMIT TASK etl0 AS CREATE TABLE tbl1 AS SELECT * FROM src_tbl",
+ "SUBMIT TASK AS INSERT OVERWRITE tbl2 SELECT * FROM src_tbl",
+ "DEALLOCATE PREPARE select_by_id_stmt",
+ # StarRocks blacklist management. ADD/DELETE already mean something
+ # else in the grammar (ALTER TABLE ADD ..., the DML DELETE
+ # statement), so these need the specific-phrase peek in
+ # `_parse_statement`, not a blanket keyword remap.
+ 'ADD SQLBLACKLIST "select count(*) from .+"',
+ "DELETE SQLBLACKLIST 3, 4",
+ "ADD BACKEND BLACKLIST 10001",
+ "DELETE BACKEND BLACKLIST 10001",
+ "ADD COMPUTE NODE BLACKLIST 10005",
+ # Ordinary ADD/DELETE must be unaffected by the blacklist peek.
+ "ALTER TABLE t ADD COLUMN c INT",
+ "DELETE FROM my_table WHERE k1 = 3",
+ # TRANSLATE TRINO translates a Trino SELECT into StarRocks SQL. Like
+ # ADD/DELETE, TRANSLATE can't be remapped to TokenType.COMMAND
+ # outright -- it also names the ordinary TRANSLATE(string, from, to)
+ # scalar function -- so this needs the same specific-phrase peek.
+ "TRANSLATE TRINO SELECT 1",
+ "TRANSLATE TRINO SELECT id, name FROM products WHERE category =
'Electronics'",
+ # Ordinary use of the scalar function must be unaffected by the peek.
+ "SELECT TRANSLATE(col, 'a', 'b') FROM t",
+ ],
+)
+def test_starrocks_admin_and_job_control_statements_parse(sql: str) -> None:
+ SQLStatement(sql, "starrocks")
+
+
[email protected](
+ "sql",
+ [
+ "KILL ANALYZE 266030",
+ "KILL QUERY 5",
+ "KILL 20",
+ "REFRESH DICTIONARY dict_obj",
+ "REFRESH CONNECTIONS",
+ "REFRESH MATERIALIZED VIEW lo_mv1",
+ "REFRESH MATERIALIZED VIEW lo_mv1 FORCE",
+ 'REFRESH MATERIALIZED VIEW lo_mv1 PARTITION START ("2020-02-01") '
+ 'END ("2020-03-01") FORCE',
+ "REFRESH MATERIALIZED VIEW lo_mv1 WITH SYNC MODE",
+ "CANCEL REFRESH MATERIALIZED VIEW lo_mv1",
+ "CANCEL REFRESH MATERIALIZED VIEW lo_mv1 FORCE",
+ "CANCEL REFRESH DICTIONARY dict_obj",
+ "SHOW CREATE FUNCTION default_db.python_add(BIGINT)",
+ "SHOW CREATE FUNCTION default_db.python_add",
+ "CREATE MATERIALIZED VIEW lo_mv3 DISTRIBUTED BY HASH(`lo_orderkey`) "
+ "REFRESH SCHEDULE START ('2023-07-01 10:00:00') EVERY (INTERVAL 1 DAY)
"
+ "AS SELECT lo_orderkey FROM lineorder",
+ "SHOW COLUMNS FROM t1",
+ "REFRESH TABLE t1",
+ "SHOW PROFILE",
+ # No REFRESH kind keyword matches; falls back to an opaque Command
+ # rather than raising.
+ "REFRESH foo",
+ # No START/EVERY schedule at all.
+ "CREATE MATERIALIZED VIEW mv1 DISTRIBUTED BY HASH(x) REFRESH MANUAL "
+ "AS SELECT x FROM t",
+ # Existing forms these overrides must not regress.
+ "REFRESH EXTERNAL TABLE t1",
+ "CREATE MATERIALIZED VIEW lo_mv1 DISTRIBUTED BY HASH(`lo_orderkey`) "
+ "REFRESH ASYNC START ('2023-07-01 10:00:00') EVERY (INTERVAL 1 DAY) "
+ "AS SELECT lo_orderkey FROM lineorder",
+ ],
+)
+def test_starrocks_kill_refresh_show_create_function_parse(sql: str) -> None:
+ SQLStatement(sql, "starrocks")
+
+
[email protected](
+ "sql",
+ [
+ # Aggregate/unique-key column agg-function suffix.
+ "CREATE TABLE t(k1 INT, v2 INT SUM) AGGREGATE KEY(k1) DISTRIBUTED BY
HASH(k1)",
+ 'CREATE TABLE t(k1 INT, v2 INT REPLACE_IF_NOT_NULL DEFAULT "10") '
+ "AGGREGATE KEY(k1) DISTRIBUTED BY HASH(k1)",
+ # Generated columns without the parenthesized `AS (expr)` form.
+ "CREATE TABLE t1(id INT, newcol1 INT AS id + 1)",
+ "CREATE TABLE test_tbl1(id INT NOT NULL, data_array ARRAY<int> NOT
NULL, "
+ "newcol1 DOUBLE AS array_avg(data_array)) PRIMARY KEY (id) "
+ "DISTRIBUTED BY HASH(id)",
+ "CREATE TABLE t1(id INT, newcol1 INT AS (id + 1))", # existing form
+ # Bare, unnamed inline KEY constraint (a primary/duplicate key marker
+ # with no name or column list is also accepted; see the CONSTRAINT_
+ # PARSERS override below).
+ "CREATE TABLE t (k1 INT, KEY (k1))",
+ # GIN/NGRAM full-text index with an inline properties list.
+ "CREATE TABLE t(k1 INT, INDEX idx (k1) USING GIN ('parser' =
'english')) "
+ "DUPLICATE KEY(k1) DISTRIBUTED BY HASH(k1)",
+ "CREATE TABLE t(k1 INT, INDEX idx (k1) USING BITMAP) "
+ "DUPLICATE KEY(k1) DISTRIBUTED BY HASH(k1)", # existing form
+ # Inherited MySQL inline-index forms/options, unrelated to the
+ # StarRocks-specific GIN case above, but reachable through the same
+ # overridden method.
+ "CREATE TABLE t (c TEXT, FULLTEXT idx (c))",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) KEY_BLOCK_SIZE = 1024)",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) WITH PARSER ngram)",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) COMMENT 'my index')",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) VISIBLE)",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) INVISIBLE)",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) ENGINE_ATTRIBUTE = 'foo')",
+ "CREATE TABLE t (k1 INT, INDEX idx (k1) SECONDARY_ENGINE_ATTRIBUTE =
'foo')",
+ # Range partition VALUES forms.
+ "CREATE TABLE t(k1 INT) PARTITION BY RANGE (k1) "
+ '(PARTITION p1 VALUES LESS THAN ("10")) DISTRIBUTED BY HASH(k1)',
+ "CREATE TABLE t(k1 INT) PARTITION BY RANGE (k1) "
+ "(PARTITION p1 VALUES LESS THAN MAXVALUE) DISTRIBUTED BY HASH(k1)",
+ # Legacy parenthesized MAXVALUE form, distinct from the bare form
+ # immediately above.
+ "CREATE TABLE t(k1 INT) PARTITION BY RANGE (k1) "
+ "(PARTITION p1 VALUES LESS THAN (MAXVALUE)) DISTRIBUTED BY HASH(k1)",
+ "CREATE TABLE t(k1 INT) PARTITION BY RANGE (k1) "
+ '(PARTITION p1 VALUES [("2021-01-01"), ("2021-01-31"))) '
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Mismatched bracket in test SQL</b></div>
<div id="fix">
The test SQL opens a `[` list but closes it with `)` instead of `]`: `VALUES
[("2021-01-01"), ("2021-01-31"))`. This mismatched bracket raises a ParseError,
so `test_starrocks_create_alter_table_clauses_parse` fails for this
parametrized case. Fix the closing bracket to `]`.
</div>
</div>
<small><i>Code Review Run #b66f1f</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]