goldmedal commented on code in PR #10917:
URL: https://github.com/apache/datafusion/pull/10917#discussion_r1641808587
##########
datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs:
##########
@@ -15,91 +15,139 @@
// specific language governing permissions and limitations
// under the License.
-use crate::expressions::ApproxPercentileCont;
-use crate::{AggregateExpr, PhysicalExpr};
+use std::any::Any;
+use std::fmt::{Debug, Formatter};
+
use arrow::{
array::ArrayRef,
datatypes::{DataType, Field},
};
-use
datafusion_functions_aggregate::approx_percentile_cont::ApproxPercentileAccumulator;
+
+use datafusion_common::ScalarValue;
+use datafusion_common::{not_impl_err, plan_err, Result};
+use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
+use datafusion_expr::type_coercion::aggregates::NUMERICS;
+use datafusion_expr::{
+ Accumulator, AggregateUDFImpl, Signature, TypeSignature, Volatility,
+};
use datafusion_physical_expr_common::aggregate::tdigest::{
Centroid, TDigest, DEFAULT_MAX_SIZE,
};
+use datafusion_physical_expr_common::physical_expr::down_cast_any_ref;
-use datafusion_common::Result;
-use datafusion_common::ScalarValue;
-use datafusion_expr::Accumulator;
+use crate::approx_percentile_cont::{ApproxPercentileAccumulator,
ApproxPercentileCont};
-use crate::aggregate::utils::down_cast_any_ref;
-use std::{any::Any, sync::Arc};
+make_udaf_expr_and_func!(
+ ApproxPercentileContWithWeight,
+ approx_percentile_cont_with_weight,
+ expression weight percentile,
+ "Computes the approximate percentile continuous with weight of a set of
numbers",
+ approx_percentile_cont_with_weight_udaf
+);
/// APPROX_PERCENTILE_CONT_WITH_WEIGTH aggregate expression
-#[derive(Debug)]
pub struct ApproxPercentileContWithWeight {
+ signature: Signature,
approx_percentile_cont: ApproxPercentileCont,
- column_expr: Arc<dyn PhysicalExpr>,
- weight_expr: Arc<dyn PhysicalExpr>,
- percentile_expr: Arc<dyn PhysicalExpr>,
+}
+
+impl Debug for ApproxPercentileContWithWeight {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("ApproxPercentileContWithWeight")
+ .field("signature", &self.signature)
+ .finish()
+ }
+}
+
+impl Default for ApproxPercentileContWithWeight {
+ fn default() -> Self {
+ Self::new()
+ }
}
impl ApproxPercentileContWithWeight {
/// Create a new [`ApproxPercentileContWithWeight`] aggregate function.
- pub fn new(
- expr: Vec<Arc<dyn PhysicalExpr>>,
- name: impl Into<String>,
- return_type: DataType,
- ) -> Result<Self> {
- // Arguments should be [ColumnExpr, WeightExpr,
DesiredPercentileLiteral]
- debug_assert_eq!(expr.len(), 3);
-
- let sub_expr = vec![expr[0].clone(), expr[2].clone()];
- let approx_percentile_cont =
- ApproxPercentileCont::new(sub_expr, name, return_type)?;
-
- Ok(Self {
- approx_percentile_cont,
- column_expr: expr[0].clone(),
- weight_expr: expr[1].clone(),
- percentile_expr: expr[2].clone(),
- })
+ pub fn new() -> Self {
+ Self {
+ signature: Signature::one_of(
Review Comment:
Same as
https://github.com/apache/datafusion/pull/10917#discussion_r1641808518
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]