-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of function calls in materialized view queries (#4)
- Loading branch information
Showing
4 changed files
with
42 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import re | ||
|
||
from typing import Iterable | ||
|
||
TABLE_RE = re.compile(r"from\s\"?(\S+)\b", re.I) | ||
|
||
|
||
def generate_schema_tables(view_select_query: str) -> Iterable[str]: | ||
""" | ||
Given a view select query, return a list of tables that are referenced in the query. | ||
Skip anything that looks like a function call. | ||
:param view_select_query: The select query from the view | ||
""" | ||
for table_candidate in TABLE_RE.findall(view_select_query): | ||
if "(" not in table_candidate: | ||
yield table_candidate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from sinker.utils import generate_schema_tables | ||
|
||
|
||
def test_generate_schema_tables(): | ||
view_select_query = """select id, | ||
json_build_object( | ||
'name', "name", | ||
'emailDomains',(select array_agg(split_part(email, '@', 2)) FROM unnest(emails) as email), | ||
) as "person" | ||
from "person" | ||
""" | ||
assert list(generate_schema_tables(view_select_query)) == ["person"] |