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

Snowflake join table(flatten(.)) parsed as anonymous table #4861

Open
mattijsdp opened this issue Mar 10, 2025 · 0 comments
Open

Snowflake join table(flatten(.)) parsed as anonymous table #4861

mattijsdp opened this issue Mar 10, 2025 · 0 comments

Comments

@mattijsdp
Copy link

Fully reproducible code snippet
Please include a fully reproducible code snippet or the input sql, dialect, and expected output.

In Snowflake SQL it is possible to flatten objects in (at least) the following two ways: using a lateral flatten and using a join table flatten. If we then compute the lineage of a column taken from the flattened source, the catalog and db of the source is accounted for in the former but not the lateral. I think this is because the lateral is parsed as an Anonymous table.

sql_lateral = """
select f.value:external_id::string as external_id
from database_name.schema_name.table_name raw,
lateral flatten(events) f
"""
sql_join = """
select f.value:external_id::string as external_id
from database_name.schema_name.table_name raw
join table(flatten(events)) f
"""

lat_expression = parse_one(sql_lateral, dialect="snowflake")
join_expression = parse_one(sql_join, dialect="snowflake")

lat_root_node = lineage("external_id", lat_expression, dialect="snowflake")
join_root_node = lineage("external_id", join_expression, dialect="snowflake")

def print_source(root_node):
    for node in root_node.walk():
        source = node.source
        if isinstance(source, exp.Table):
            print(f"{source.catalog}.{source.db}.{source.this}")

print_source(lat_root_node) # DATABASE_NAME.SCHEMA_NAME.TABLE_NAME
print_source(join_root_node) # ..TABLE(EXPLODE(EVENTS))

Official Documentation
Please include links to official SQL documentation related to your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant