Skip to content

Add basic support for unnest unparsing - #13129

Merged
goldmedal merged 2 commits into
apache:mainfrom
spiceai:sgrebnov/unnest-unparsing-upstream
Oct 28, 2024
Merged

goldmedal merged 2 commits into
apache:mainfrom
spiceai:sgrebnov/unnest-unparsing-upstream

Conversation

@sgrebnov

@sgrebnov sgrebnov commented Oct 26, 2024 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

PR adds basic support for UNNEST unparsing: Lists/Arrays only (structs support needs some extra work and could be added as incremental improvement).

What changes are included in this PR?

  1. PR adds handler for LogicalPlan::Unnest and updates reconstruct_select_statement to check if there is Unnest child so that corresponding columns are correctly unprojected via unproject_unnest_expr. For example column("unnest_placeholder([Int64(1),Int64(2),Int64(2),Int64(5),NULL],depth=1)") is transformed into UNNEST([1, 2, 2, 5, NULL]).

  2. Adds unnest_to_sql to convert an UNNEST expression to an AST. Since there is no dedicated representation for UNNEST in the AST, the implementation converts the expression to a function call.

Are these changes tested?

Added unit tests, tested as part of internal https://github.com/spiceai/spiceai functionality.

Are there any user-facing changes?

Can now unparse plans with unnest (lists/arrays only).

@github-actions github-actions Bot added the sql SQL Planner label Oct 26, 2024
Comment thread datafusion/sql/Cargo.toml Resolved

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @sgrebnov it looks good to me 👍

}

/// Converts an UNNEST operation to an AST expression by wrapping it as a function call,
/// since there is no direct representation for UNNEST in the AST.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It makes sense to me. On the SQL parser side, it also uses a function call to present UNNEST.

@goldmedal
goldmedal merged commit 1fd6116 into apache:main Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants