jonathanc-n commented on code in PR #13493:
URL: https://github.com/apache/datafusion/pull/13493#discussion_r1850920747


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -514,6 +516,52 @@ impl Unparser<'_> {
         })
     }
 
+    fn named_struct_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
+        if args.len() % 2 != 0 {
+            return internal_err!("named_struct must have an even number of 
arguments");
+        }
+
+        let args = args
+            .chunks_exact(2)
+            .map(|chunk| {
+                let key = match &chunk[0] {
+                    Expr::Literal(lit) => 
self.new_ident_quoted_if_needs(lit.to_string()),
+                    _ => return internal_err!("named_struct arg is invalid"),
+                };
+
+                Ok(ast::DictionaryField {
+                    key,
+                    value: Box::new(self.expr_to_sql(&chunk[1])?),
+                })
+            })
+            .collect::<Result<Vec<_>>>()?;
+
+        Ok(ast::Expr::Dictionary(args))
+    }
+
+    fn get_field_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
+        if args.len() != 2 {
+            return internal_err!("get_field must have exactly 2 arguments");
+        }
+
+        let mut id = match &args[0] {
+            Expr::Column(col) => match self.col_to_sql(col)? {
+                ast::Expr::Identifier(ident) => vec![ident],
+                ast::Expr::CompoundIdentifier(idents) => idents,
+                _ => unreachable!(),

Review Comment:
   ```suggestion
                   _ => return internal_err!("get_field expects an Identifier 
or CompoundIdentifier, but received: {:?}", other)
   ```
   I feel like unreachable should be avoided



##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -514,6 +516,52 @@ impl Unparser<'_> {
         })
     }
 
+    fn named_struct_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
+        if args.len() % 2 != 0 {
+            return internal_err!("named_struct must have an even number of 
arguments");
+        }
+
+        let args = args
+            .chunks_exact(2)
+            .map(|chunk| {
+                let key = match &chunk[0] {
+                    Expr::Literal(lit) => 
self.new_ident_quoted_if_needs(lit.to_string()),
+                    _ => return internal_err!("named_struct arg is invalid"),
+                };
+
+                Ok(ast::DictionaryField {
+                    key,
+                    value: Box::new(self.expr_to_sql(&chunk[1])?),
+                })
+            })
+            .collect::<Result<Vec<_>>>()?;
+
+        Ok(ast::Expr::Dictionary(args))
+    }
+
+    fn get_field_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
+        if args.len() != 2 {
+            return internal_err!("get_field must have exactly 2 arguments");
+        }
+
+        let mut id = match &args[0] {
+            Expr::Column(col) => match self.col_to_sql(col)? {
+                ast::Expr::Identifier(ident) => vec![ident],
+                ast::Expr::CompoundIdentifier(idents) => idents,
+                _ => unreachable!(),
+            },
+            _ => return internal_err!("get_field column is invalid"),

Review Comment:
   ```suggestion
               _ => return internal_err!("get_field expects first argument to 
be column, but received {:?}", args[0]),
   ```
   Error message should be more clear here for feedback



-- 
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-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to