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:01:32 UTC

[GitHub] [arrow-datafusion] HaoYang670 opened a new pull request, #3684: Simplify the `CONCAT` function

HaoYang670 opened a new pull request, #3684:
URL: https://github.com/apache/arrow-datafusion/pull/3684

   Signed-off-by: remzi <13...@gmail.com>
   
   # 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.
   -->
   
   Closes #3683 .
   
    # Rationale for this change
   <!--
    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?
   <!--
   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 there any user-facing changes?
   <!--
   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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #3684: Add simplification rules for the `CONCAT` function

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #3684:
URL: https://github.com/apache/arrow-datafusion/pull/3684#discussion_r992253421


##########
datafusion/optimizer/src/simplify_expressions.rs:
##########
@@ -1352,6 +1396,30 @@ mod tests {
         }
     }
 
+    #[test]
+    fn test_simplify_concat() {
+        fn build_concat_expr(args: &[Expr]) -> Expr {
+            Expr::ScalarFunction {
+                fun: BuiltinScalarFunction::Concat,
+                args: args.to_vec(),
+            }
+        }
+
+        let null = Expr::Literal(ScalarValue::Utf8(None));
+        let expr = build_concat_expr(&[
+            null.clone(),
+            col("c0"),
+            lit("hello "),
+            null.clone(),
+            lit("rust"),
+            col("c1"),
+            lit(""),
+            null,
+        ]);
+        let expected = build_concat_expr(&[col("c0"), lit("hello rust"), col("c1")]);

Review Comment:
   this is very clever



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


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

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [arrow-datafusion] ursabot commented on pull request #3684: Add simplification rules for the `CONCAT` function

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3684:
URL: https://github.com/apache/arrow-datafusion/pull/3684#issuecomment-1274599867

   Benchmark runs are scheduled for baseline = 0cf5630626ba7e3d814ef00477bcae2bc3cae9c2 and contender = ac1631aa6db411c78b38d3a70ccaeb6a89a83673. ac1631aa6db411c78b38d3a70ccaeb6a89a83673 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c223927e21544405b8389a110c85019b...9110901132bd41589babb4c2a1fde906/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/49eb572a124f414d9df627d04e8f44e6...e3e0062f169543bc99baa6e1f446b78c/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/e11b8a1e3f8c4fec93a35a079abce456...ba2ea43598b3449f91522e4fdd5d9551/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/221653cf1e6e4e558165fd8f50adcf41...c088751e07624cdbbced2093b93fd063/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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


[GitHub] [arrow-datafusion] alamb merged pull request #3684: Add simplification rules for the `CONCAT` function

Posted by GitBox <gi...@apache.org>.
alamb merged PR #3684:
URL: https://github.com/apache/arrow-datafusion/pull/3684


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