You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/05 20:02:06 UTC

[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #3684: Simplify the `CONCAT` function

HaoYang670 commented on code in PR #3684:
URL: https://github.com/apache/arrow-datafusion/pull/3684#discussion_r985580412


##########
datafusion/optimizer/src/simplify_expressions.rs:
##########
@@ -849,12 +849,61 @@ impl<'a, S: SimplifyInfo> ExprRewriter for Simplifier<'a, S> {
                 out_expr.rewrite(self)?
             }
 
+            // concat
+            ScalarFunction {
+                fun: BuiltinScalarFunction::Concat,
+                args,
+            } => {
+                let mut new_args = Vec::with_capacity(args.len());
+                let mut contiguous_scalar = "".to_string();
+                for e in args {
+                    match e {
+                        // ignore `null` scalar and concatenate it with `contiguous scalar`.
+                        Expr::Literal(x) => {
+                            match x {
+                                // true --> '1', false --> '0'
+                                ScalarValue::Boolean(b) => {
+                                    contiguous_scalar += b
+                                        .map(|b| if b { "1" } else { "0" })

Review Comment:
   The behavior of `to_string` doesn't 100% match the `cast_to_utf8` kernel in `arrow-rs`. 
   (BooleanType -> '1' / '0', and `null -> empty string)
   Maybe we should reimplement it or add a `cast_to_utf8` function for `ScalarValue`.



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

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