Skip to content

Commit

Permalink
fix: filter empty statement (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Aug 11, 2019
1 parent c7ea5d8 commit d0c47dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqllineage/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, sql: str, encoding=None):
self._encoding = encoding
self._source_tables = set()
self._target_tables = set()
self._stmt = sqlparse.parse(sql.strip(), self._encoding)
self._stmt = [s for s in sqlparse.parse(sql.strip(), self._encoding) if s.get_type() != "UNKNOWN"]
for stmt in self._stmt:
if stmt.get_type() == "DROP":
self._target_tables -= {t.get_real_name() for t in stmt.tokens if isinstance(t, Identifier)}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ def test_split_statements():
def test_split_statements_with_heading_and_ending_new_line():
sql = "\nSELECT * FROM tab1;\nSELECT * FROM tab2;\n"
assert len(LineageParser(sql).statements) == 2


def test_split_statements_with_comment():
sql = """SELECT 1;
-- SELECT 2;"""
assert len(LineageParser(sql).statements) == 1

0 comments on commit d0c47dd

Please sign in to comment.