You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2024/07/13 07:37:02 UTC
[PR] Convert `ArrayAgg` to UDAF [datafusion]
jayzhan211 opened a new pull request, #11448:
URL: https://github.com/apache/datafusion/pull/11448
## 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 #.
## 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.
-->
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #11448:
URL: https://github.com/apache/datafusion/pull/11448
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1683606268
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
Review Comment:
I'm not sure why they are upper case initially, however we plan to convert them all to lowercase
--
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
Re: [PR] `ArrayAgg` UDAF [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1680464606
##########
datafusion/physical-expr/src/aggregate/array_agg_distinct.rs:
##########
@@ -1,433 +0,0 @@
-// 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.
-
-//! Implementations for DISTINCT expressions, e.g. `COUNT(DISTINCT c)`
-
-use std::any::Any;
-use std::collections::HashSet;
-use std::fmt::Debug;
-use std::sync::Arc;
-
-use arrow::array::ArrayRef;
-use arrow::datatypes::{DataType, Field};
-use arrow_array::cast::AsArray;
-
-use crate::aggregate::utils::down_cast_any_ref;
-use crate::expressions::format_state_name;
-use crate::{AggregateExpr, PhysicalExpr};
-
-use datafusion_common::{Result, ScalarValue};
-use datafusion_expr::Accumulator;
-
-/// Expression for a ARRAY_AGG(DISTINCT) aggregation.
-#[derive(Debug)]
-pub struct DistinctArrayAgg {
- /// Column name
- name: String,
- /// The DataType for the input expression
- input_data_type: DataType,
- /// The input expression
- expr: Arc<dyn PhysicalExpr>,
-}
-
-impl DistinctArrayAgg {
- /// Create a new DistinctArrayAgg aggregate function
- pub fn new(
- expr: Arc<dyn PhysicalExpr>,
- name: impl Into<String>,
- input_data_type: DataType,
- ) -> Self {
- let name = name.into();
- Self {
- name,
- input_data_type,
- expr,
- }
- }
-}
-
-impl AggregateExpr for DistinctArrayAgg {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
- fn field(&self) -> Result<Field> {
- Ok(Field::new_list(
- &self.name,
- // This should be the same as return type of AggregateFunction::ArrayAgg
- Field::new("item", self.input_data_type.clone(), true),
- true,
- ))
- }
-
- fn create_accumulator(&self) -> Result<Box<dyn Accumulator>> {
- Ok(Box::new(DistinctArrayAggAccumulator::try_new(
- &self.input_data_type,
- )?))
- }
-
- fn state_fields(&self) -> Result<Vec<Field>> {
- Ok(vec![Field::new_list(
- format_state_name(&self.name, "distinct_array_agg"),
- Field::new("item", self.input_data_type.clone(), true),
- true,
- )])
- }
-
- fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
- vec![Arc::clone(&self.expr)]
- }
-
- fn name(&self) -> &str {
- &self.name
- }
-}
-
-impl PartialEq<dyn Any> for DistinctArrayAgg {
- fn eq(&self, other: &dyn Any) -> bool {
- down_cast_any_ref(other)
- .downcast_ref::<Self>()
- .map(|x| {
- self.name == x.name
- && self.input_data_type == x.input_data_type
- && self.expr.eq(&x.expr)
- })
- .unwrap_or(false)
- }
-}
-
-#[derive(Debug)]
-struct DistinctArrayAggAccumulator {
- values: HashSet<ScalarValue>,
- datatype: DataType,
-}
-
-impl DistinctArrayAggAccumulator {
- pub fn try_new(datatype: &DataType) -> Result<Self> {
- Ok(Self {
- values: HashSet::new(),
- datatype: datatype.clone(),
- })
- }
-}
-
-impl Accumulator for DistinctArrayAggAccumulator {
- fn state(&mut self) -> Result<Vec<ScalarValue>> {
- Ok(vec![self.evaluate()?])
- }
-
- fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
- assert_eq!(values.len(), 1, "batch input should only include 1 column!");
-
- let array = &values[0];
-
- for i in 0..array.len() {
- let scalar = ScalarValue::try_from_array(&array, i)?;
- self.values.insert(scalar);
- }
-
- Ok(())
- }
-
- fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
- if states.is_empty() {
- return Ok(());
- }
-
- states[0]
- .as_list::<i32>()
- .iter()
- .flatten()
- .try_for_each(|val| self.update_batch(&[val]))
- }
-
- fn evaluate(&mut self) -> Result<ScalarValue> {
- let values: Vec<ScalarValue> = self.values.iter().cloned().collect();
- if values.is_empty() {
- return Ok(ScalarValue::new_null_list(self.datatype.clone(), true, 1));
- }
- let arr = ScalarValue::new_list(&values, &self.datatype, true);
- Ok(ScalarValue::List(arr))
- }
-
- fn size(&self) -> usize {
- std::mem::size_of_val(self) + ScalarValue::size_of_hashset(&self.values)
- - std::mem::size_of_val(&self.values)
- + self.datatype.size()
- - std::mem::size_of_val(&self.datatype)
- }
-}
-
-#[cfg(test)]
-mod tests {
Review Comment:
The test for distinct array agg is already coverdd in
https://github.com/apache/datafusion/blob/d67b0fbf52a2c428399811fabac3eec6cf15da41/datafusion/sqllogictest/test_files/aggregate.slt#L173-L192
Remove the test here doesn't reduce test coverage
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1683410472
##########
datafusion/proto/tests/cases/roundtrip_logical_plan.rs:
##########
@@ -702,6 +702,7 @@ async fn roundtrip_expr_api() -> Result<()> {
string_agg(col("a").cast_to(&DataType::Utf8, &schema)?, lit("|")),
bool_and(lit(true)),
bool_or(lit(true)),
+ array_agg(lit(1)),
Review Comment:
I think @jayzhan211 means that there is a single `array_agg` udf function now, and internally it has special accumulators for distinct and non distinct
Thus there is no difference in how to serialize it I think
Maybe we could use the builder to test
```rust
array_agg(lit(1)).distinct().build().unwrap(),
```
🤔
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
Review Comment:
```suggestion
//! `ARRAY_AGG` aggregate implementation: [`ArrayAgg`]
```
##########
datafusion/physical-expr/src/aggregate/array_agg_distinct.rs:
##########
@@ -1,433 +0,0 @@
-// 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.
-
-//! Implementations for DISTINCT expressions, e.g. `COUNT(DISTINCT c)`
-
-use std::any::Any;
-use std::collections::HashSet;
-use std::fmt::Debug;
-use std::sync::Arc;
-
-use arrow::array::ArrayRef;
-use arrow::datatypes::{DataType, Field};
-use arrow_array::cast::AsArray;
-
-use crate::aggregate::utils::down_cast_any_ref;
-use crate::expressions::format_state_name;
-use crate::{AggregateExpr, PhysicalExpr};
-
-use datafusion_common::{Result, ScalarValue};
-use datafusion_expr::Accumulator;
-
-/// Expression for a ARRAY_AGG(DISTINCT) aggregation.
-#[derive(Debug)]
-pub struct DistinctArrayAgg {
- /// Column name
- name: String,
- /// The DataType for the input expression
- input_data_type: DataType,
- /// The input expression
- expr: Arc<dyn PhysicalExpr>,
-}
-
-impl DistinctArrayAgg {
- /// Create a new DistinctArrayAgg aggregate function
- pub fn new(
- expr: Arc<dyn PhysicalExpr>,
- name: impl Into<String>,
- input_data_type: DataType,
- ) -> Self {
- let name = name.into();
- Self {
- name,
- input_data_type,
- expr,
- }
- }
-}
-
-impl AggregateExpr for DistinctArrayAgg {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
- fn field(&self) -> Result<Field> {
- Ok(Field::new_list(
- &self.name,
- // This should be the same as return type of AggregateFunction::ArrayAgg
- Field::new("item", self.input_data_type.clone(), true),
- true,
- ))
- }
-
- fn create_accumulator(&self) -> Result<Box<dyn Accumulator>> {
- Ok(Box::new(DistinctArrayAggAccumulator::try_new(
- &self.input_data_type,
- )?))
- }
-
- fn state_fields(&self) -> Result<Vec<Field>> {
- Ok(vec![Field::new_list(
- format_state_name(&self.name, "distinct_array_agg"),
- Field::new("item", self.input_data_type.clone(), true),
- true,
- )])
- }
-
- fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
- vec![Arc::clone(&self.expr)]
- }
-
- fn name(&self) -> &str {
- &self.name
- }
-}
-
-impl PartialEq<dyn Any> for DistinctArrayAgg {
- fn eq(&self, other: &dyn Any) -> bool {
- down_cast_any_ref(other)
- .downcast_ref::<Self>()
- .map(|x| {
- self.name == x.name
- && self.input_data_type == x.input_data_type
- && self.expr.eq(&x.expr)
- })
- .unwrap_or(false)
- }
-}
-
-#[derive(Debug)]
-struct DistinctArrayAggAccumulator {
- values: HashSet<ScalarValue>,
- datatype: DataType,
-}
-
-impl DistinctArrayAggAccumulator {
- pub fn try_new(datatype: &DataType) -> Result<Self> {
- Ok(Self {
- values: HashSet::new(),
- datatype: datatype.clone(),
- })
- }
-}
-
-impl Accumulator for DistinctArrayAggAccumulator {
- fn state(&mut self) -> Result<Vec<ScalarValue>> {
- Ok(vec![self.evaluate()?])
- }
-
- fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
- assert_eq!(values.len(), 1, "batch input should only include 1 column!");
-
- let array = &values[0];
-
- for i in 0..array.len() {
- let scalar = ScalarValue::try_from_array(&array, i)?;
- self.values.insert(scalar);
- }
-
- Ok(())
- }
-
- fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
- if states.is_empty() {
- return Ok(());
- }
-
- states[0]
- .as_list::<i32>()
- .iter()
- .flatten()
- .try_for_each(|val| self.update_batch(&[val]))
- }
-
- fn evaluate(&mut self) -> Result<ScalarValue> {
- let values: Vec<ScalarValue> = self.values.iter().cloned().collect();
- if values.is_empty() {
- return Ok(ScalarValue::new_null_list(self.datatype.clone(), true, 1));
- }
- let arr = ScalarValue::new_list(&values, &self.datatype, true);
- Ok(ScalarValue::List(arr))
- }
-
- fn size(&self) -> usize {
- std::mem::size_of_val(self) + ScalarValue::size_of_hashset(&self.values)
- - std::mem::size_of_val(&self.values)
- + self.datatype.size()
- - std::mem::size_of_val(&self.datatype)
- }
-}
-
-#[cfg(test)]
-mod tests {
Review Comment:
(though it looks like the comments should be adjusted):
https://github.com/apache/datafusion/blob/d67b0fbf52a2c428399811fabac3eec6cf15da41/datafusion/sqllogictest/test_files/aggregate.slt#L186
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
Review Comment:
Interestingly it is inconsistent with `count` which uses lower case: https://github.com/apache/datafusion/blob/b685e2d4f1f245dd1dbe468b32b115ae99316689/datafusion/functions-aggregate/src/count.rs#L112-L113
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#issuecomment-2238069272
Thanks @dharanad and @alamb
--
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
Re: [PR] `ArrayAgg` UDAF [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1683225628
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
Review Comment:
Any specific reason for having this in uppercase ?
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
+ }
+
+ fn aliases(&self) -> &[String] {
+ &self.alias
+ }
+
+ fn signature(&self) -> &Signature {
+ &self.signature
+ }
+
+ fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+ Ok(DataType::List(Arc::new(Field::new(
+ "item",
+ arg_types[0].clone(),
+ true,
+ ))))
+ }
+
+ fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
+ if args.is_distinct {
+ return Ok(vec![Field::new_list(
+ format_state_name(args.name, "distinct_array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )]);
+ }
+
+ Ok(vec![Field::new_list(
+ format_state_name(args.name, "array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )])
+ }
+
+ fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
+ if acc_args.is_distinct {
+ return Ok(Box::new(DistinctArrayAggAccumulator::try_new(
+ acc_args.input_type,
+ )?));
+ }
+
+ Ok(Box::new(ArrayAggAccumulator::try_new(acc_args.input_type)?))
+ }
+}
+
+#[derive(Debug)]
+pub struct ArrayAggAccumulator {
+ values: Vec<ArrayRef>,
+ datatype: DataType,
+}
+
+impl ArrayAggAccumulator {
+ /// new array_agg accumulator based on given item data type
+ pub fn try_new(datatype: &DataType) -> Result<Self> {
+ Ok(Self {
+ values: vec![],
+ datatype: datatype.clone(),
+ })
+ }
+}
+
+impl Accumulator for ArrayAggAccumulator {
+ // Append value like Int64Array(1,2,3)
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ if values.is_empty() {
+ return Ok(());
+ }
+ assert!(values.len() == 1, "array_agg can only take 1 param!");
Review Comment:
This will invoke the `panic!`, should we return an Err here ?
##########
datafusion/proto/src/physical_plan/to_proto.rs:
##########
@@ -260,14 +259,9 @@ struct AggrFn {
fn aggr_expr_to_aggr_fn(expr: &dyn AggregateExpr) -> Result<AggrFn> {
let aggr_expr = expr.as_any();
- let mut distinct = false;
- let inner = if aggr_expr.downcast_ref::<ArrayAgg>().is_some() {
- protobuf::AggregateFunction::ArrayAgg
- } else if aggr_expr.downcast_ref::<DistinctArrayAgg>().is_some() {
- distinct = true;
- protobuf::AggregateFunction::ArrayAgg
- } else if aggr_expr.downcast_ref::<OrderSensitiveArrayAgg>().is_some() {
+ // TODO: remove
Review Comment:
Nit: I think it can be removed.
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
+ }
+
+ fn aliases(&self) -> &[String] {
+ &self.alias
+ }
+
+ fn signature(&self) -> &Signature {
+ &self.signature
+ }
+
+ fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+ Ok(DataType::List(Arc::new(Field::new(
+ "item",
+ arg_types[0].clone(),
+ true,
+ ))))
+ }
+
+ fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
+ if args.is_distinct {
+ return Ok(vec![Field::new_list(
+ format_state_name(args.name, "distinct_array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )]);
+ }
+
+ Ok(vec![Field::new_list(
+ format_state_name(args.name, "array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )])
+ }
+
+ fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
+ if acc_args.is_distinct {
+ return Ok(Box::new(DistinctArrayAggAccumulator::try_new(
+ acc_args.input_type,
+ )?));
+ }
+
+ Ok(Box::new(ArrayAggAccumulator::try_new(acc_args.input_type)?))
+ }
+}
+
+#[derive(Debug)]
+pub struct ArrayAggAccumulator {
+ values: Vec<ArrayRef>,
+ datatype: DataType,
+}
+
+impl ArrayAggAccumulator {
+ /// new array_agg accumulator based on given item data type
+ pub fn try_new(datatype: &DataType) -> Result<Self> {
+ Ok(Self {
+ values: vec![],
+ datatype: datatype.clone(),
+ })
+ }
+}
+
+impl Accumulator for ArrayAggAccumulator {
+ // Append value like Int64Array(1,2,3)
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ if values.is_empty() {
+ return Ok(());
+ }
+ assert!(values.len() == 1, "array_agg can only take 1 param!");
+
+ let val = Arc::clone(&values[0]);
+ if val.len() > 0 {
+ self.values.push(val);
+ }
+ Ok(())
+ }
+
+ // Append value like ListArray(Int64Array(1,2,3), Int64Array(4,5,6))
Review Comment:
Nit: If this is code document, then we can move this inside the function.
##########
datafusion/proto/tests/cases/roundtrip_logical_plan.rs:
##########
@@ -702,6 +702,7 @@ async fn roundtrip_expr_api() -> Result<()> {
string_agg(col("a").cast_to(&DataType::Utf8, &schema)?, lit("|")),
bool_and(lit(true)),
bool_or(lit(true)),
+ array_agg(lit(1)),
Review Comment:
What is builder mode ? You mean a builder for `array_agg`
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
+ }
+ }
+}
+
+impl AggregateUDFImpl for ArrayAgg {
+ fn as_any(&self) -> &dyn std::any::Any {
+ self
+ }
+
+ // TODO: change name to lowercase
+ fn name(&self) -> &str {
+ "ARRAY_AGG"
+ }
+
+ fn aliases(&self) -> &[String] {
+ &self.alias
+ }
+
+ fn signature(&self) -> &Signature {
+ &self.signature
+ }
+
+ fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+ Ok(DataType::List(Arc::new(Field::new(
+ "item",
+ arg_types[0].clone(),
+ true,
+ ))))
+ }
+
+ fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
+ if args.is_distinct {
+ return Ok(vec![Field::new_list(
+ format_state_name(args.name, "distinct_array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )]);
+ }
+
+ Ok(vec![Field::new_list(
+ format_state_name(args.name, "array_agg"),
+ Field::new("item", args.input_type.clone(), true),
+ true,
+ )])
+ }
+
+ fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
+ if acc_args.is_distinct {
+ return Ok(Box::new(DistinctArrayAggAccumulator::try_new(
+ acc_args.input_type,
+ )?));
+ }
+
+ Ok(Box::new(ArrayAggAccumulator::try_new(acc_args.input_type)?))
+ }
+}
+
+#[derive(Debug)]
+pub struct ArrayAggAccumulator {
+ values: Vec<ArrayRef>,
+ datatype: DataType,
+}
+
+impl ArrayAggAccumulator {
+ /// new array_agg accumulator based on given item data type
+ pub fn try_new(datatype: &DataType) -> Result<Self> {
+ Ok(Self {
+ values: vec![],
+ datatype: datatype.clone(),
+ })
+ }
+}
+
+impl Accumulator for ArrayAggAccumulator {
+ // Append value like Int64Array(1,2,3)
+ fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+ if values.is_empty() {
+ return Ok(());
+ }
+ assert!(values.len() == 1, "array_agg can only take 1 param!");
+
+ let val = Arc::clone(&values[0]);
+ if val.len() > 0 {
+ self.values.push(val);
+ }
+ Ok(())
+ }
+
+ // Append value like ListArray(Int64Array(1,2,3), Int64Array(4,5,6))
+ fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
+ if states.is_empty() {
+ return Ok(());
+ }
+ assert!(states.len() == 1, "array_agg states must be singleton!");
Review Comment:
Same as above. Can we remove all `assert!` and return `Err`
##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -171,6 +171,7 @@ pub fn max(expr: Expr) -> Expr {
))
}
+// TODO: remove
Review Comment:
Nit: I think we can remove this
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
Review Comment:
Why are we using the smallcase variant as alias ? Shouldn't this be the function name ?
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
Review Comment:
I think this is not clear & can we improve for clarity just the other functions ?
--
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
Re: [PR] `ArrayAgg` UDAF [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1683237730
##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -0,0 +1,249 @@
+// 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.
+
+//! Defines physical expressions that can evaluated at runtime during query execution
+
+use arrow::array::{Array, ArrayRef, AsArray};
+use arrow::datatypes::DataType;
+use arrow_schema::Field;
+
+use datafusion_common::cast::as_list_array;
+use datafusion_common::utils::array_into_list_array_nullable;
+use datafusion_common::Result;
+use datafusion_common::ScalarValue;
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::utils::format_state_name;
+use datafusion_expr::AggregateUDFImpl;
+use datafusion_expr::{Accumulator, Signature, Volatility};
+use std::collections::HashSet;
+use std::sync::Arc;
+
+make_udaf_expr_and_func!(
+ ArrayAgg,
+ array_agg,
+ expression,
+ "input values, including nulls, concatenated into an array",
+ array_agg_udaf
+);
+
+#[derive(Debug)]
+/// ARRAY_AGG aggregate expression
+pub struct ArrayAgg {
+ signature: Signature,
+ alias: Vec<String>,
+}
+
+impl Default for ArrayAgg {
+ fn default() -> Self {
+ Self {
+ signature: Signature::any(1, Volatility::Immutable),
+ alias: vec!["array_agg".to_string()],
Review Comment:
Why are we using the smallcase as alias ? Shouldn't this be the function name itself ?
--
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
Re: [PR] `ArrayAgg` UDAF [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1680467219
##########
datafusion/proto/tests/cases/roundtrip_logical_plan.rs:
##########
@@ -702,6 +702,7 @@ async fn roundtrip_expr_api() -> Result<()> {
string_agg(col("a").cast_to(&DataType::Utf8, &schema)?, lit("|")),
bool_and(lit(true)),
bool_or(lit(true)),
+ array_agg(lit(1)),
Review Comment:
I didn't add `array_agg_distinct` since it is not exist, and we can get distinct one with builder mode.
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1683609423
##########
datafusion/proto/src/physical_plan/to_proto.rs:
##########
@@ -260,14 +259,9 @@ struct AggrFn {
fn aggr_expr_to_aggr_fn(expr: &dyn AggregateExpr) -> Result<AggrFn> {
let aggr_expr = expr.as_any();
- let mut distinct = false;
- let inner = if aggr_expr.downcast_ref::<ArrayAgg>().is_some() {
- protobuf::AggregateFunction::ArrayAgg
- } else if aggr_expr.downcast_ref::<DistinctArrayAgg>().is_some() {
- distinct = true;
- protobuf::AggregateFunction::ArrayAgg
- } else if aggr_expr.downcast_ref::<OrderSensitiveArrayAgg>().is_some() {
+ // TODO: remove
Review Comment:
OrderSensitiveArrayAgg is not yet removed
--
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
Re: [PR] Move array `ArrayAgg` to a `UserDefinedAggregate` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1685011358
##########
datafusion/proto/tests/cases/roundtrip_logical_plan.rs:
##########
@@ -702,6 +702,8 @@ async fn roundtrip_expr_api() -> Result<()> {
string_agg(col("a").cast_to(&DataType::Utf8, &schema)?, lit("|")),
bool_and(lit(true)),
bool_or(lit(true)),
+ array_agg(lit(1)),
+ array_agg(lit(1)).distinct().build().unwrap(),
Review Comment:
👍
--
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
Re: [PR] `ArrayAgg` UDAF [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #11448:
URL: https://github.com/apache/datafusion/pull/11448#discussion_r1680551764
##########
datafusion/physical-expr/src/expressions/mod.rs:
##########
@@ -63,160 +61,3 @@ pub use negative::{negative, NegativeExpr};
pub use no_op::NoOp;
pub use not::{not, NotExpr};
pub use try_cast::{try_cast, TryCastExpr};
-
-#[cfg(test)]
-pub(crate) mod tests {
Review Comment:
no usage
--
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