mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
chore: set up ruff as a new linter/formatter (#28158)
This commit is contained in:
committed by
GitHub
parent
e8a678b75a
commit
2d63722150
@@ -118,9 +118,8 @@ def test_extract_tables_subselect() -> None:
|
||||
"""
|
||||
Test that tables inside subselects are parsed correctly.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT sub.*
|
||||
FROM (
|
||||
SELECT *
|
||||
@@ -129,13 +128,10 @@ FROM (
|
||||
) sub, s2.t2
|
||||
WHERE sub.resolution = 'NONE'
|
||||
"""
|
||||
)
|
||||
== {Table("t1", "s1"), Table("t2", "s2")}
|
||||
)
|
||||
) == {Table("t1", "s1"), Table("t2", "s2")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT sub.*
|
||||
FROM (
|
||||
SELECT *
|
||||
@@ -144,13 +140,10 @@ FROM (
|
||||
) sub
|
||||
WHERE sub.resolution = 'NONE'
|
||||
"""
|
||||
)
|
||||
== {Table("t1", "s1")}
|
||||
)
|
||||
) == {Table("t1", "s1")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT * FROM t1
|
||||
WHERE s11 > ANY (
|
||||
SELECT COUNT(*) /* no hint */ FROM t2
|
||||
@@ -162,9 +155,7 @@ WHERE s11 > ANY (
|
||||
)
|
||||
)
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t2"), Table("t3"), Table("t4")}
|
||||
)
|
||||
) == {Table("t1"), Table("t2"), Table("t3"), Table("t4")}
|
||||
|
||||
|
||||
def test_extract_tables_select_in_expression() -> None:
|
||||
@@ -235,30 +226,24 @@ def test_extract_tables_select_array() -> None:
|
||||
"""
|
||||
Test that queries selecting arrays work as expected.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT ARRAY[1, 2, 3] AS my_array
|
||||
FROM t1 LIMIT 10
|
||||
"""
|
||||
)
|
||||
== {Table("t1")}
|
||||
)
|
||||
) == {Table("t1")}
|
||||
|
||||
|
||||
def test_extract_tables_select_if() -> None:
|
||||
"""
|
||||
Test that queries with an ``IF`` work as expected.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT IF(CARDINALITY(my_array) >= 3, my_array[3], NULL)
|
||||
FROM t1 LIMIT 10
|
||||
"""
|
||||
)
|
||||
== {Table("t1")}
|
||||
)
|
||||
) == {Table("t1")}
|
||||
|
||||
|
||||
def test_extract_tables_with_catalog() -> None:
|
||||
@@ -326,38 +311,29 @@ def test_extract_tables_where_subquery() -> None:
|
||||
"""
|
||||
Test that tables in a ``WHERE`` subquery are parsed correctly.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT name
|
||||
FROM t1
|
||||
WHERE regionkey = (SELECT max(regionkey) FROM t2)
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t2")}
|
||||
)
|
||||
) == {Table("t1"), Table("t2")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT name
|
||||
FROM t1
|
||||
WHERE regionkey IN (SELECT regionkey FROM t2)
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t2")}
|
||||
)
|
||||
) == {Table("t1"), Table("t2")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT name
|
||||
FROM t1
|
||||
WHERE EXISTS (SELECT 1 FROM t2 WHERE t1.regionkey = t2.regionkey);
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t2")}
|
||||
)
|
||||
) == {Table("t1"), Table("t2")}
|
||||
|
||||
|
||||
def test_extract_tables_describe() -> None:
|
||||
@@ -371,15 +347,12 @@ def test_extract_tables_show_partitions() -> None:
|
||||
"""
|
||||
Test ``SHOW PARTITIONS``.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SHOW PARTITIONS FROM orders
|
||||
WHERE ds >= '2013-01-01' ORDER BY ds DESC
|
||||
"""
|
||||
)
|
||||
== {Table("orders")}
|
||||
)
|
||||
) == {Table("orders")}
|
||||
|
||||
|
||||
def test_extract_tables_join() -> None:
|
||||
@@ -391,9 +364,8 @@ def test_extract_tables_join() -> None:
|
||||
Table("t2"),
|
||||
}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT a.date, b.name
|
||||
FROM left_table a
|
||||
JOIN (
|
||||
@@ -404,13 +376,10 @@ JOIN (
|
||||
) b
|
||||
ON a.date = b.date
|
||||
"""
|
||||
)
|
||||
== {Table("left_table"), Table("right_table")}
|
||||
)
|
||||
) == {Table("left_table"), Table("right_table")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT a.date, b.name
|
||||
FROM left_table a
|
||||
LEFT INNER JOIN (
|
||||
@@ -421,13 +390,10 @@ LEFT INNER JOIN (
|
||||
) b
|
||||
ON a.date = b.date
|
||||
"""
|
||||
)
|
||||
== {Table("left_table"), Table("right_table")}
|
||||
)
|
||||
) == {Table("left_table"), Table("right_table")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT a.date, b.name
|
||||
FROM left_table a
|
||||
RIGHT OUTER JOIN (
|
||||
@@ -438,13 +404,10 @@ RIGHT OUTER JOIN (
|
||||
) b
|
||||
ON a.date = b.date
|
||||
"""
|
||||
)
|
||||
== {Table("left_table"), Table("right_table")}
|
||||
)
|
||||
) == {Table("left_table"), Table("right_table")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT a.date, b.name
|
||||
FROM left_table a
|
||||
FULL OUTER JOIN (
|
||||
@@ -455,18 +418,15 @@ FULL OUTER JOIN (
|
||||
) b
|
||||
ON a.date = b.date
|
||||
"""
|
||||
)
|
||||
== {Table("left_table"), Table("right_table")}
|
||||
)
|
||||
) == {Table("left_table"), Table("right_table")}
|
||||
|
||||
|
||||
def test_extract_tables_semi_join() -> None:
|
||||
"""
|
||||
Test ``LEFT SEMI JOIN``.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT a.date, b.name
|
||||
FROM left_table a
|
||||
LEFT SEMI JOIN (
|
||||
@@ -477,18 +437,15 @@ LEFT SEMI JOIN (
|
||||
) b
|
||||
ON a.data = b.date
|
||||
"""
|
||||
)
|
||||
== {Table("left_table"), Table("right_table")}
|
||||
)
|
||||
) == {Table("left_table"), Table("right_table")}
|
||||
|
||||
|
||||
def test_extract_tables_combinations() -> None:
|
||||
"""
|
||||
Test a complex case with nested queries.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT * FROM t1
|
||||
WHERE s11 > ANY (
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM (
|
||||
@@ -502,13 +459,10 @@ WHERE s11 > ANY (
|
||||
)
|
||||
)
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t3"), Table("t4"), Table("t6")}
|
||||
)
|
||||
) == {Table("t1"), Table("t3"), Table("t4"), Table("t6")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT * FROM (
|
||||
SELECT * FROM (
|
||||
SELECT * FROM (
|
||||
@@ -517,56 +471,45 @@ SELECT * FROM (
|
||||
) AS S2
|
||||
) AS S3
|
||||
"""
|
||||
)
|
||||
== {Table("EmployeeS")}
|
||||
)
|
||||
) == {Table("EmployeeS")}
|
||||
|
||||
|
||||
def test_extract_tables_with() -> None:
|
||||
"""
|
||||
Test ``WITH``.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
WITH
|
||||
x AS (SELECT a FROM t1),
|
||||
y AS (SELECT a AS b FROM t2),
|
||||
z AS (SELECT b AS c FROM t3)
|
||||
SELECT c FROM z
|
||||
"""
|
||||
)
|
||||
== {Table("t1"), Table("t2"), Table("t3")}
|
||||
)
|
||||
) == {Table("t1"), Table("t2"), Table("t3")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
WITH
|
||||
x AS (SELECT a FROM t1),
|
||||
y AS (SELECT a AS b FROM x),
|
||||
z AS (SELECT b AS c FROM y)
|
||||
SELECT c FROM z
|
||||
"""
|
||||
)
|
||||
== {Table("t1")}
|
||||
)
|
||||
) == {Table("t1")}
|
||||
|
||||
|
||||
def test_extract_tables_reusing_aliases() -> None:
|
||||
"""
|
||||
Test that the parser follows aliases.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
with q1 as ( select key from q2 where key = '5'),
|
||||
q2 as ( select key from src where key = '5')
|
||||
select * from (select key from q1) a
|
||||
"""
|
||||
)
|
||||
== {Table("src")}
|
||||
)
|
||||
) == {Table("src")}
|
||||
|
||||
# weird query with circular dependency
|
||||
assert (
|
||||
@@ -603,9 +546,8 @@ def test_extract_tables_complex() -> None:
|
||||
"""
|
||||
Test a few complex queries.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT sum(m_examples) AS "sum__m_example"
|
||||
FROM (
|
||||
SELECT
|
||||
@@ -626,29 +568,23 @@ FROM (
|
||||
ORDER BY "sum__m_example" DESC
|
||||
LIMIT 10;
|
||||
"""
|
||||
)
|
||||
== {
|
||||
Table("my_l_table"),
|
||||
Table("my_b_table"),
|
||||
Table("my_t_table"),
|
||||
Table("inner_table"),
|
||||
}
|
||||
)
|
||||
) == {
|
||||
Table("my_l_table"),
|
||||
Table("my_b_table"),
|
||||
Table("my_t_table"),
|
||||
Table("inner_table"),
|
||||
}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT *
|
||||
FROM table_a AS a, table_b AS b, table_c as c
|
||||
WHERE a.id = b.id and b.id = c.id
|
||||
"""
|
||||
)
|
||||
== {Table("table_a"), Table("table_b"), Table("table_c")}
|
||||
)
|
||||
) == {Table("table_a"), Table("table_b"), Table("table_c")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT somecol AS somecol
|
||||
FROM (
|
||||
WITH bla AS (
|
||||
@@ -692,63 +628,51 @@ FROM (
|
||||
LIMIT 50000
|
||||
)
|
||||
"""
|
||||
)
|
||||
== {Table("a"), Table("b"), Table("c"), Table("d"), Table("e"), Table("f")}
|
||||
)
|
||||
) == {Table("a"), Table("b"), Table("c"), Table("d"), Table("e"), Table("f")}
|
||||
|
||||
|
||||
def test_extract_tables_mixed_from_clause() -> None:
|
||||
"""
|
||||
Test that the parser handles a ``FROM`` clause with table and subselect.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
SELECT *
|
||||
FROM table_a AS a, (select * from table_b) AS b, table_c as c
|
||||
WHERE a.id = b.id and b.id = c.id
|
||||
"""
|
||||
)
|
||||
== {Table("table_a"), Table("table_b"), Table("table_c")}
|
||||
)
|
||||
) == {Table("table_a"), Table("table_b"), Table("table_c")}
|
||||
|
||||
|
||||
def test_extract_tables_nested_select() -> None:
|
||||
"""
|
||||
Test that the parser handles selects inside functions.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
select (extractvalue(1,concat(0x7e,(select GROUP_CONCAT(TABLE_NAME)
|
||||
from INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA like "%bi%"),0x7e)));
|
||||
""",
|
||||
"mysql",
|
||||
)
|
||||
== {Table("COLUMNS", "INFORMATION_SCHEMA")}
|
||||
)
|
||||
"mysql",
|
||||
) == {Table("COLUMNS", "INFORMATION_SCHEMA")}
|
||||
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
select (extractvalue(1,concat(0x7e,(select GROUP_CONCAT(COLUMN_NAME)
|
||||
from INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME="bi_achievement_daily"),0x7e)));
|
||||
""",
|
||||
"mysql",
|
||||
)
|
||||
== {Table("COLUMNS", "INFORMATION_SCHEMA")}
|
||||
)
|
||||
"mysql",
|
||||
) == {Table("COLUMNS", "INFORMATION_SCHEMA")}
|
||||
|
||||
|
||||
def test_extract_tables_complex_cte_with_prefix() -> None:
|
||||
"""
|
||||
Test that the parser handles CTEs with prefixes.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
WITH CTE__test (SalesPersonID, SalesOrderID, SalesYear)
|
||||
AS (
|
||||
SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear
|
||||
@@ -760,26 +684,21 @@ FROM CTE__test
|
||||
GROUP BY SalesYear, SalesPersonID
|
||||
ORDER BY SalesPersonID, SalesYear;
|
||||
"""
|
||||
)
|
||||
== {Table("SalesOrderHeader")}
|
||||
)
|
||||
) == {Table("SalesOrderHeader")}
|
||||
|
||||
|
||||
def test_extract_tables_identifier_list_with_keyword_as_alias() -> None:
|
||||
"""
|
||||
Test that aliases that are keywords are parsed correctly.
|
||||
"""
|
||||
assert (
|
||||
extract_tables(
|
||||
"""
|
||||
assert extract_tables(
|
||||
"""
|
||||
WITH
|
||||
f AS (SELECT * FROM foo),
|
||||
match AS (SELECT * FROM f)
|
||||
SELECT * FROM match
|
||||
"""
|
||||
)
|
||||
== {Table("foo")}
|
||||
)
|
||||
) == {Table("foo")}
|
||||
|
||||
|
||||
def test_update() -> None:
|
||||
|
||||
Reference in New Issue
Block a user