alamb commented on code in PR #8636:
URL: https://github.com/apache/arrow-datafusion/pull/8636#discussion_r1438886040


##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -98,11 +99,184 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 StackEntry::Operator(op) => {
                     let right = eval_stack.pop().unwrap();
                     let left = eval_stack.pop().unwrap();
-                    let expr = Expr::BinaryExpr(BinaryExpr::new(
-                        Box::new(left),
-                        op,
-                        Box::new(right),
-                    ));
+
+                    // Summary of the logic below:
+                    // array || array -> array concat
+                    // array || scalar -> array append
+                    // scalar || array -> array prepend
+                    // (arry concat, array append, array prepend) || array -> 
array concat
+                    // (arry concat, array append, array prepend) || scalar -> 
array append
+
+                    // Convert `Array StringConcat Array` to 
ScalarFunction::ArrayConcat
+                    let expr = match (op, &left, &right) {
+                        // Chain concat operator (a || b) || array,

Review Comment:
   It seems like the rule to convert `Operator::StringConcat` ==> ArrayConcat 
depends on the type of the arguments and this code is effectively rewriting the 
originally created Expr tree. 
   
   What do you think about putting this logic in an analyzer rule: 
https://github.com/apache/arrow-datafusion/tree/main/datafusion/optimizer/src/analyzer?
   
   



-- 
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]

Reply via email to