Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlparser): fix sqlparser breaking due to # sign #4662

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, sql_query: str) -> None:
r"(\bdate\b)", rf"{self._DATE_SWAP_TOKEN}", sql_query, flags=re.IGNORECASE
)

sql_query = re.sub(r"#([^ ])", r"# \1", sql_query)

# SqlLineageParser lowercarese tablenames and we need to replace Looker specific token which should be uppercased
sql_query = re.sub(
rf"(\${{{self._MYVIEW_LOOKER_TOKEN}}})",
Expand Down
19 changes: 19 additions & 0 deletions metadata-ingestion/tests/unit/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,22 @@ def test_sqllineage_sql_parser_tables_from_redash_query():
table_list = SqlLineageSQLParser(sql_query).get_tables()
table_list.sort()
assert table_list == ["order_items", "orders", "staffs"]


def test_hash_in_sql_query_with_no_space():
parser = SqlLineageSQLParser(
sql_query="""
/*
HERE IS A STANDARD COMMENT BLOCK
THIS WILL NOT BREAK sqllineage
*/
CREATE OR REPLACE TABLE `foo.bar.trg_tbl`AS
#This, comment will not break sqllineage
SELECT foo
-- this comment will not break sqllineage either
# this comment will not break sqllineage either
FROM `foo.bar.src_tbl`
"""
)

assert parser.get_tables() == ["foo.bar.src_tbl"]