Skip to content

Commit

Permalink
fix: filter empty statement cause some valid sql filtered (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Aug 12, 2019
1 parent d0c47dd commit d79057f
Show file tree
Hide file tree
Showing 2 changed files with 15 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 = [s for s in sqlparse.parse(sql.strip(), self._encoding) if s.get_type() != "UNKNOWN"]
self._stmt = [s for s in sqlparse.parse(sql.strip(), self._encoding) if s.token_first(skip_cm=True)]
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
14 changes: 14 additions & 0 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ def test_split_statements_with_comment():
-- SELECT 2;"""
assert len(LineageParser(sql).statements) == 1


def test_split_statements_with_show_create_table():
sql = """SELECT 1;
SHOW CREATE TABLE tab1;"""
assert len(LineageParser(sql).statements) == 2


def test_split_statements_with_desc():
sql = """SELECT 1;
DESC tab1;"""
assert len(LineageParser(sql).statements) == 2

0 comments on commit d79057f

Please sign in to comment.