Skip to content

Commit

Permalink
fix: column lineage using boolean expression
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Mar 26, 2022
1 parent e17d9b1 commit 983524e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
12 changes: 4 additions & 8 deletions sqllineage/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,12 @@ def _extract_source_columns(token: Token) -> List[ColumnQualifierTuple]:
ColumnQualifierTuple(token.get_real_name(), token.get_parent_name())
]
else:
# Handle literals other than *
if (
token.ttype is not None
and token.ttype[0] == T.Literal[0]
and token.value != "*"
):
source_columns = []
else:
if token.ttype == T.Wildcard:
# select *
source_columns = [ColumnQualifierTuple(token.value, None)]
else:
# typically, T.Literal here
source_columns = []
return source_columns

def to_source_columns(self, alias_mapping: Dict[str, Union[Table, SubQuery]]):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ def test_select_column_using_expression_in_parenthesis():
)


def test_select_column_using_boolean_expression_in_parenthesis():
sql = """INSERT OVERWRITE TABLE tab1
SELECT (col1 > 0 AND col2 > 0) AS col3
FROM tab2"""
assert_column_lineage_equal(
sql,
[
(
ColumnQualifierTuple("col1", "tab2"),
ColumnQualifierTuple("col3", "tab1"),
),
(
ColumnQualifierTuple("col2", "tab2"),
ColumnQualifierTuple("col3", "tab1"),
),
],
)


def test_select_column_using_expression_with_table_qualifier_without_column_alias():
sql = """INSERT OVERWRITE TABLE tab1
SELECT a.col1 + a.col2 + a.col3 + a.col4
Expand Down

0 comments on commit 983524e

Please sign in to comment.