You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2023/11/27 01:08:39 UTC

[PR] ArraySum [arrow-datafusion]

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

   ## 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.
   -->
   
   Ref https://github.com/apache/arrow-datafusion/issues/7213
   Ref https://github.com/apache/arrow-datafusion/issues/7214
   
   ## 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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## 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.
   -->
   
   ## Additional Context
   * array_aggregate not yet support somethings like `SELECT list_aggregate([2, 4, 8, 42], 'string_agg', '|')`, so dont close #7213 .
   


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


Re: [PR] ArraySum [arrow-datafusion]

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #8325:
URL: https://github.com/apache/arrow-datafusion/pull/8325#discussion_r1425131251


##########
datafusion/sqllogictest/test_files/array_aggregate.slt:
##########
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#############
+## Array Aggregate Tests
+#############
+
+# sum
+
+query IRIIIRII
+select 
+array_aggregate([1, 3, 5, 7], 'sum'),

Review Comment:
   ```suggestion
   array_aggregate([], 'sum'),
   array_aggregate([null], 'sum'),
   select array_aggregate([1, 3, 5, 7], 'SUM'),
   array_aggregate([1, 3, 5, 7], 'sum'),
   ```



##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1588,6 +1590,7 @@ from_unixtime(expression)
 - [list_replace_n](#list_replace_n)
 - [list_replace_all](#list_replace_all)
 - [list_slice](#list_slice)
+- [list_sum](#list_sum)

Review Comment:
   This link is empty



##########
datafusion/sql/src/expr/function.rs:
##########
@@ -72,6 +73,24 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         // next, scalar built-in
         if let Ok(fun) = BuiltinScalarFunction::from_str(&name) {
             let args = self.function_args_to_expr(args, schema, planner_context)?;
+
+            // Translate array_aggregate to aggregate function with array argument.
+            if fun == BuiltinScalarFunction::ArrayAggregate {
+                let fun = match &args[1] {
+                    Expr::Literal(ScalarValue::Utf8(Some(name))) => match name.as_str() {
+                        "sum" => BuiltinScalarFunction::ArraySum,
+                        _ => {
+                            return not_impl_err!(
+                                "Aggregate function {name} is not implemented"
+                            )
+                        }
+                    },
+                    _ => return internal_err!("Aggregate function name is not a string"),
+                };

Review Comment:
   It would be better to use `enum` to represent these aggregate functions, like `sum`, and easy to extend later 🤔  But we could do it later pr.



##########
datafusion/sql/src/expr/function.rs:
##########
@@ -72,6 +73,24 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         // next, scalar built-in
         if let Ok(fun) = BuiltinScalarFunction::from_str(&name) {
             let args = self.function_args_to_expr(args, schema, planner_context)?;
+
+            // Translate array_aggregate to aggregate function with array argument.
+            if fun == BuiltinScalarFunction::ArrayAggregate {
+                let fun = match &args[1] {
+                    Expr::Literal(ScalarValue::Utf8(Some(name))) => match name.as_str() {
+                        "sum" => BuiltinScalarFunction::ArraySum,
+                        _ => {
+                            return not_impl_err!(
+                                "Aggregate function {name} is not implemented"
+                            )
+                        }
+                    },
+                    _ => return internal_err!("Aggregate function name is not a string"),
+                };

Review Comment:
   It would be better to use `enum` to represent these aggregate functions, like `sum`, and easy to extend later 🤔  But we could do it later pr.



##########
datafusion/sqllogictest/test_files/array_aggregate.slt:
##########
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#############
+## Array Aggregate Tests
+#############
+
+# sum
+
+query IRIIIRII
+select 
+array_aggregate([1, 3, 5, 7], 'sum'),
+array_aggregate([1.1, 2.2, 3.3], 'sum'),
+array_aggregate([1, -1, 0, 23], 'sum'),
+array_aggregate([1, null, 9, null], 'sum'),
+array_sum([1, 3, 5]),
+array_sum([1.1, 2.2]),
+array_sum([1, -1, 0, 22]),
+array_sum([1, -1, 0, null, 22]);

Review Comment:
   ```suggestion
   array_sum([1, -1, 0, null, 22]),
   array_sum([]),
   array_sum([null]);
   ```



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


Re: [PR] ArraySum [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #8325:
URL: https://github.com/apache/datafusion/pull/8325#issuecomment-2067843656

   Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.


-- 
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: commits-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


Re: [PR] ArraySum [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8325:
URL: https://github.com/apache/arrow-datafusion/pull/8325#issuecomment-1924747931

   I am trying to go through old PRs and make sure we don't lose any -- this one has not had much activity and has accumulated conflicts. Marking as draft so it isn't on the review queue. Please feel free to reopen / mark as ready for review if it is


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


Re: [PR] ArraySum [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #8325:
URL: https://github.com/apache/arrow-datafusion/pull/8325#discussion_r1435519946


##########
datafusion/sqllogictest/test_files/array_aggregate.slt:
##########
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#############
+## Array Aggregate Tests
+#############
+
+# sum
+
+query IRIIIRII
+select 
+array_aggregate([1, 3, 5, 7], 'sum'),

Review Comment:
   I intend to skip this since null is not yet handle correctly



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


Re: [PR] ArraySum [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #8325: ArraySum
URL: https://github.com/apache/datafusion/pull/8325


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

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


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