Skip to content

Conversation

@osipovartem
Copy link
Contributor

Which issue does this PR close?

Closes #16568

Rationale for this change

Allows usage of table functions in relations

SELECT col1, f.* FROM json_tbl, LATERAL FLATTEN(INPUT => col1, PATH => 'name') f;

What changes are included in this PR?

Added section for TableFactor::Function

Are these changes tested?

Tested in fork with registered flatten table function

Are there any user-facing changes?

No

@github-actions github-actions bot added the sql SQL Planner label Jun 26, 2025
@alamb alamb changed the title Allow usage of table funstions in relations Allow usage of table functions in relations Jun 26, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for this contribution @osipovartem -- the code looks great to me but I think we should write test in the datafusion codebase to ensure we don't accidentally break this feature in the future

I think I could write a reproducer using the generate_series function:

> create or replace table json_table (c int) as values (1), (2);

> SELECT c, f.*  FROM json_table, LATERAL generate_series(1,2) f;
This feature is not implemented: Unsupported ast node Function { lateral: true, name: ObjectName([Identifier(Ident { value: "generate_series", quote_style: None, span: Span(Location(1,41)..Location(1,56)) })]), args: [Unnamed(Expr(Value(ValueWithSpan { value: Number("1", false), span: Span(Location(1,57)..Location(1,58)) }))), Unnamed(Expr(Value(ValueWithSpan { value: Number("2", false), span: Span(Location(1,59)..Location(1,60)) })))], alias: Some(TableAlias { name: Ident { value: "f", quote_style: None, span: Span(Location(1,62)..Location(1,63)) }, columns: [] }) } in create_relation

Could you please add a sqllogictest

The instructions how to do so are here: https://github.com/apache/datafusion/blob/main/datafusion/sqllogictest/README.md

I think you could just add a few statements to the end of

# Test generate_series table function

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jun 27, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @osipovartem

@alamb
Copy link
Contributor

alamb commented Jun 28, 2025

Screenshot 2025-06-28 at 6 47 54 AM

I can't merge this PR because it has a conflict that must be resolved. I can't push to the Embucket fork to do it myself. @osipovartem is there any chance you can resolve the conflicts?

@osipovartem
Copy link
Contributor Author

Let me fix it

@osipovartem osipovartem force-pushed the aosipov/16568_table_funcs_in_relations branch from e817e7b to 30f8ee1 Compare June 30, 2025 09:56
@alamb alamb merged commit 649a36f into apache:main Jun 30, 2025
27 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 30, 2025

Thank you @osipovartem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow table fucntion in joins

2 participants