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

Add basic support for unnest unparsing #13129

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

sgrebnov
Copy link
Member

@sgrebnov sgrebnov commented Oct 26, 2024

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
Copy link
Contributor

@goldmedal goldmedal left a comment

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 👍

@@ -1340,6 +1341,29 @@ impl Unparser<'_> {
}
}

/// 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
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
26 checks passed
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