You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "delamarch3 (via GitHub)" <gi...@apache.org> on 2024/11/22 17:18:09 UTC
[PR] Unparse map to sql [datafusion]
delamarch3 opened a new pull request, #13532:
URL: https://github.com/apache/datafusion/pull/13532
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Implements `map` for #13478. For `get_field` it doesn't look like there is a way to distinguish if it is a map access from the expression.
## Rationale for this change
Support roundtrip for statements containing `map`
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
Implement `expr_to_sql` for `map`.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Unparse map to sql [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13532:
URL: https://github.com/apache/datafusion/pull/13532#issuecomment-2495461561
Thanks @delamarch3 !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Unparse map to sql [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13532:
URL: https://github.com/apache/datafusion/pull/13532#discussion_r1854484463
##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -567,6 +568,43 @@ impl Unparser<'_> {
Ok(ast::Expr::CompoundIdentifier(id))
}
+ fn map_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
+ if args.len() != 2 {
+ return internal_err!("map must have exactly 2 arguments");
+ }
+
+ let keys = match self.expr_to_sql(&args[0])? {
+ ast::Expr::Array(Array { elem, .. }) => elem,
+ other => {
+ return internal_err!(
+ "map expects first argument to be an array, but received: {:?}",
+ other
+ )
+ }
+ };
Review Comment:
You can also write this in the following way which may be more concise:
```suggestion
let ast::Expr::Array(Array { elem: keys, .. })) = self.expr_to_sql(&args[0])? else {
return internal_err!(
"map expects first argument to be an array, but received: {:?}",
other
)
};
```
##########
datafusion/functions-nested/src/map.rs:
##########
@@ -214,9 +214,9 @@ impl ScalarUDFImpl for MapFunc {
}
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- if arg_types.len() % 2 != 0 {
+ if arg_types.len() != 2 {
Review Comment:
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Unparse map to sql [datafusion]
Posted by "delamarch3 (via GitHub)" <gi...@apache.org>.
delamarch3 commented on PR #13532:
URL: https://github.com/apache/datafusion/pull/13532#issuecomment-2494608235
Thanks for the review @alamb
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Unparse map to sql [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #13532:
URL: https://github.com/apache/datafusion/pull/13532
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org