-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support unparsing Array plan to SQL string #13418
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
match func_name { | ||
"make_array" => self.make_array_to_sql(args), | ||
"array_element" => self.array_element_to_sql(args), | ||
// TODO: support for the construct and access functions of the `map` and `struct` types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar cases exist for map
and struct
. I'll file another issue for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me -- thank you @goldmedal
@@ -182,6 +184,11 @@ fn roundtrip_statement() -> Result<()> { | |||
SUM(id) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total | |||
FROM person | |||
GROUP BY GROUPING SETS ((id, first_name, last_name), (first_name, last_name), (last_name))"#, | |||
"SELECT ARRAY[1, 2, 3]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Thanks again @goldmedal |
Thanks @alamb |
Which issue does this PR close?
Closes #11144.
Rationale for this change
DataFusion will plan the array construction and the elements' access to the corresponding scalar functions. If we don't handle those cases, they will be unparsed to
ast::Expr::ScalarFunction
which isn't a common SQL syntax.Array Construction
Elements accessing
This PR tries to allow the array SQL to do SQL-Plan-SQL roundtrip.
What changes are included in this PR?
make_array
toast::Expr::Array
array_element
toast::Expr::Subscript
Are these changes tested?
expr unit tests and SQL roundtrip tests.
Are there any user-facing changes?
no