Skip to content

Commit ece24e2

Browse files
authored
Merge pull request bruin-data#306 from bruin-data/sparkhealth/bugs
2 parents 572b276 + 5c15e97 commit ece24e2

File tree

2 files changed

+593
-6
lines changed

2 files changed

+593
-6
lines changed

pythonsrc/parser/main.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def extract_non_selected_columns(parsed: exp.Select) -> list[Column]:
2222
table_alias = {}
2323
for table in tables:
2424
if table.alias:
25-
table_alias[table.alias] = table.name
25+
table_alias[table.alias] = merge_parts(table)
2626

2727
table_names = {}
2828
for table in tables:
29-
table_names[table.name] = table
29+
table_key = merge_parts(table)
30+
table_names[table_key] = table
3031

3132
for scopes in [where, join, group]:
3233
for scope in scopes:
@@ -133,9 +134,13 @@ def get_column_lineage(query: str, schema: dict, dialect: str):
133134
):
134135
continue
135136

136-
cl.append(
137-
{"column": ds.name.split(".")[-1], "table": ds.expression.this.name}
138-
)
137+
if isinstance(ds.expression, exp.Table):
138+
cl.append(
139+
{
140+
"column": ds.name.split(".")[-1],
141+
"table": merge_parts(ds.expression),
142+
}
143+
)
139144

140145
# Deduplicate based on column-table combination
141146
cl = [dict(t) for t in {tuple(d.items()) for d in cl}]
@@ -169,3 +174,7 @@ def find_leaf_nodes(node: Node, leaf_nodes):
169174
else:
170175
for child in node.downstream:
171176
find_leaf_nodes(child, leaf_nodes)
177+
178+
179+
def merge_parts(table: exp.Table) -> str:
180+
return ".".join(part.name for part in table.parts if isinstance(part, exp.Identifier))

0 commit comments

Comments
 (0)