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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]