Skip to content

Commit

Permalink
allow all system tables
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagara committed Dec 17, 2021
1 parent 68e3aaa commit 3cb17de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
14 changes: 1 addition & 13 deletions snuba/admin/clickhouse/system_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,14 @@ def run_system_query_on_host_by_name(
\s
(FROM|from)
\s
system.(?P<system_table_name>\w+)
system.[a-z_]+
(?P<extra>\s[\w\s,=+\(\)']+)?
;? # Optional semicolon
$ # End
""",
re.VERBOSE,
)

# An incomplete list
VALID_SYSTEM_TABLES = [
"clusters",
"merges",
"parts",
]


def run_system_query_on_host_with_sql(
clickhouse_host: str, clickhouse_port: int, storage_name: str, system_query_sql: str
Expand Down Expand Up @@ -213,11 +206,6 @@ def validate_system_query(sql_query: str) -> None:
if kw in select_statement.lower():
raise InvalidCustomQuery(f"{kw} is not allowed here")

system_table_name = match.group("system_table_name")

if system_table_name not in VALID_SYSTEM_TABLES:
raise InvalidCustomQuery("Invalid table")

extra = match.group("extra")

# Unfortunately "extra" is pretty permissive right now, just ensure
Expand Down
1 change: 1 addition & 0 deletions tests/admin/test_system_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_valid_system_query(sql_query: str) -> None:
"with sum(bytes) as s select s from system.parts group by table;", # sorry not allowed WITH
"SELECT 1; SELECT 2;" # no multiple statements
"SELECT * FROM system.clusters c INNER JOIN my_table m ON c.cluster == m.something", # no join
"SELECT * from system.as1", # invalid system table format
],
)
def test_invalid_system_query(sql_query: str) -> None:
Expand Down

0 comments on commit 3cb17de

Please sign in to comment.