mirror of
https://github.com/apache/superset.git
synced 2026-07-13 10:15:58 +00:00
fix test lint (#17835)
This commit is contained in:
committed by
GitHub
parent
8057582b02
commit
96c18b4272
@@ -15,8 +15,8 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from superset.sql_parse import ParsedQuery
|
||||
|
||||
import unittest
|
||||
from typing import Set
|
||||
|
||||
import pytest
|
||||
import sqlparse
|
||||
@@ -535,22 +535,6 @@ def test_extract_tables_multistatement() -> None:
|
||||
}
|
||||
|
||||
|
||||
def test_extract_tables_keyword() -> None:
|
||||
"""
|
||||
Test that table names that are keywords work as expected.
|
||||
|
||||
If the table name is a ``sqlparse`` reserved keyword (eg, "table_name") the parser
|
||||
needs extra logic to identify it.
|
||||
"""
|
||||
assert extract_tables("SELECT * FROM table_name") == {Table("table_name")}
|
||||
assert extract_tables("SELECT * FROM table_name AS foo") == {Table("table_name")}
|
||||
|
||||
# these 3 are considered keywords
|
||||
assert extract_tables("SELECT * FROM catalog_name.schema_name.table_name") == {
|
||||
Table("table_name", "schema_name", "catalog_name")
|
||||
}
|
||||
|
||||
|
||||
def test_extract_tables_complex() -> None:
|
||||
"""
|
||||
Test a few complex queries.
|
||||
@@ -995,46 +979,6 @@ INNER JOIN blah2 ON blah2.team_id = blah.team_id"""
|
||||
assert sql.is_select()
|
||||
|
||||
|
||||
def test_cte_is_select() -> None:
|
||||
"""
|
||||
Some CTEs are not correctly identified as SELECTS.
|
||||
"""
|
||||
# `AS(` gets parsed as a function
|
||||
sql = ParsedQuery(
|
||||
"""WITH foo AS(
|
||||
SELECT
|
||||
FLOOR(__time TO WEEK) AS "week",
|
||||
name,
|
||||
COUNT(DISTINCT user_id) AS "unique_users"
|
||||
FROM "druid"."my_table"
|
||||
GROUP BY 1,2
|
||||
)
|
||||
SELECT
|
||||
f.week,
|
||||
f.name,
|
||||
f.unique_users
|
||||
FROM foo f"""
|
||||
)
|
||||
assert sql.is_select()
|
||||
|
||||
|
||||
def test_unknown_select() -> None:
|
||||
"""
|
||||
Test that `is_select` works when sqlparse fails to identify the type.
|
||||
"""
|
||||
sql = "WITH foo AS(SELECT 1) SELECT 1"
|
||||
assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN"
|
||||
assert ParsedQuery(sql).is_select()
|
||||
|
||||
sql = "WITH foo AS(SELECT 1) INSERT INTO my_table (a) VALUES (1)"
|
||||
assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN"
|
||||
assert not ParsedQuery(sql).is_select()
|
||||
|
||||
sql = "WITH foo AS(SELECT 1) DELETE FROM my_table"
|
||||
assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN"
|
||||
assert not ParsedQuery(sql).is_select()
|
||||
|
||||
|
||||
def test_get_query_with_new_limit_comment() -> None:
|
||||
"""
|
||||
Test that limit is applied correctly.
|
||||
|
||||
Reference in New Issue
Block a user