mirror of
https://github.com/apache/superset.git
synced 2026-04-07 18:35:15 +00:00
fix: sqlparse fallback for formatting queries (#30578)
This commit is contained in:
@@ -284,6 +284,40 @@ def test_extract_tables_show_tables_from() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_format_show_tables() -> None:
|
||||
"""
|
||||
Test format when `ast.sql()` raises an exception.
|
||||
|
||||
In that case sqlparse should be used instead.
|
||||
"""
|
||||
assert (
|
||||
SQLScript("SHOW TABLES FROM s1 like '%order%'", "mysql").format()
|
||||
== "SHOW TABLES FROM s1 LIKE '%order%'"
|
||||
)
|
||||
|
||||
|
||||
def test_format_no_dialect() -> None:
|
||||
"""
|
||||
Test format with an engine that has no corresponding dialect.
|
||||
"""
|
||||
assert (
|
||||
SQLScript("SELECT col FROM t WHERE col NOT IN (1, 2)", "firebolt").format()
|
||||
== "SELECT col\nFROM t\nWHERE col NOT IN (1,\n 2)"
|
||||
)
|
||||
|
||||
|
||||
def test_split_no_dialect() -> None:
|
||||
"""
|
||||
Test the statement split when the engine has no corresponding dialect.
|
||||
"""
|
||||
sql = "SELECT col FROM t WHERE col NOT IN (1, 2); SELECT * FROM t; SELECT foo"
|
||||
statements = SQLScript(sql, "firebolt").statements
|
||||
assert len(statements) == 3
|
||||
assert statements[0]._sql == "SELECT col FROM t WHERE col NOT IN (1, 2)"
|
||||
assert statements[1]._sql == "SELECT * FROM t"
|
||||
assert statements[2]._sql == "SELECT foo"
|
||||
|
||||
|
||||
def test_extract_tables_show_columns_from() -> None:
|
||||
"""
|
||||
Test `SHOW COLUMNS FROM`.
|
||||
|
||||
Reference in New Issue
Block a user