Skip to content

Commit c216f48

Browse files
committed
refactor: rename to approx_percentile_cont
1 parent 03a5eff commit c216f48

File tree

14 files changed

+129
-122
lines changed

14 files changed

+129
-122
lines changed

ballista/rust/core/proto/ballista.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ enum AggregateFunction {
176176
STDDEV=11;
177177
STDDEV_POP=12;
178178
CORRELATION=13;
179-
APPROX_QUANTILE = 14;
179+
APPROX_PERCENTILE_CONT = 14;
180180
}
181181

182182
message AggregateExprNode {

ballista/rust/core/src/serde/logical_plan/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,9 @@ mod roundtrip_tests {
10011001
}
10021002

10031003
#[test]
1004-
fn roundtrip_approx_quantile() -> Result<()> {
1004+
fn roundtrip_approx_percentile_cont() -> Result<()> {
10051005
let test_expr = Expr::AggregateFunction {
1006-
fun: aggregates::AggregateFunction::ApproxQuantile,
1006+
fun: aggregates::AggregateFunction::ApproxPercentileCont,
10071007
args: vec![col("bananas"), lit(0.42)],
10081008
distinct: false,
10091009
};

ballista/rust/core/src/serde/logical_plan/to_proto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,8 @@ impl TryInto<protobuf::LogicalExprNode> for &Expr {
10741074
AggregateFunction::ApproxDistinct => {
10751075
protobuf::AggregateFunction::ApproxDistinct
10761076
}
1077-
AggregateFunction::ApproxQuantile => {
1078-
protobuf::AggregateFunction::ApproxQuantile
1077+
AggregateFunction::ApproxPercentileCont => {
1078+
protobuf::AggregateFunction::ApproxPercentileCont
10791079
}
10801080
AggregateFunction::ArrayAgg => protobuf::AggregateFunction::ArrayAgg,
10811081
AggregateFunction::Min => protobuf::AggregateFunction::Min,
@@ -1339,7 +1339,7 @@ impl From<&AggregateFunction> for protobuf::AggregateFunction {
13391339
AggregateFunction::Stddev => Self::Stddev,
13401340
AggregateFunction::StddevPop => Self::StddevPop,
13411341
AggregateFunction::Correlation => Self::Correlation,
1342-
AggregateFunction::ApproxQuantile => Self::ApproxQuantile,
1342+
AggregateFunction::ApproxPercentileCont => Self::ApproxPercentileCont,
13431343
}
13441344
}
13451345
}

ballista/rust/core/src/serde/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ impl From<protobuf::AggregateFunction> for AggregateFunction {
129129
protobuf::AggregateFunction::Stddev => AggregateFunction::Stddev,
130130
protobuf::AggregateFunction::StddevPop => AggregateFunction::StddevPop,
131131
protobuf::AggregateFunction::Correlation => AggregateFunction::Correlation,
132-
protobuf::AggregateFunction::ApproxQuantile => {
133-
AggregateFunction::ApproxQuantile
132+
protobuf::AggregateFunction::ApproxPercentileCont => {
133+
AggregateFunction::ApproxPercentileCont
134134
}
135135
}
136136
}

datafusion/src/logical_plan/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,12 +1647,12 @@ pub fn approx_distinct(expr: Expr) -> Expr {
16471647
}
16481648
}
16491649

1650-
/// Calculate an approximation of the specified `quantile` for `expr`.
1651-
pub fn approx_quantile(expr: Expr, quantile: Expr) -> Expr {
1650+
/// Calculate an approximation of the specified `percentile` for `expr`.
1651+
pub fn approx_percentile_cont(expr: Expr, percentile: Expr) -> Expr {
16521652
Expr::AggregateFunction {
1653-
fun: aggregates::AggregateFunction::ApproxQuantile,
1653+
fun: aggregates::AggregateFunction::ApproxPercentileCont,
16541654
distinct: false,
1655-
args: vec![expr, quantile],
1655+
args: vec![expr, percentile],
16561656
}
16571657
}
16581658

datafusion/src/logical_plan/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub use builder::{
3636
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ToDFSchema};
3737
pub use display::display_schema;
3838
pub use expr::{
39-
abs, acos, and, approx_distinct, approx_quantile, array, ascii, asin, atan, avg,
40-
binary_expr, bit_length, btrim, case, ceil, character_length, chr, col,
39+
abs, acos, and, approx_distinct, approx_percentile_cont, array, ascii, asin, atan,
40+
avg, binary_expr, bit_length, btrim, case, ceil, character_length, chr, col,
4141
columnize_expr, combine_filters, concat, concat_ws, cos, count, count_distinct,
4242
create_udaf, create_udf, date_part, date_trunc, digest, exp, exprlist_to_fields,
4343
floor, in_list, initcap, left, length, lit, lit_timestamp_nano, ln, log10, log2,

datafusion/src/physical_plan/aggregates.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ pub enum AggregateFunction {
8080
CovariancePop,
8181
/// Correlation
8282
Correlation,
83-
/// Approximate quantile function
84-
ApproxQuantile,
83+
/// Approximate continuous percentile function
84+
ApproxPercentileCont,
8585
}
8686

8787
impl fmt::Display for AggregateFunction {
@@ -112,7 +112,7 @@ impl FromStr for AggregateFunction {
112112
"covar_samp" => AggregateFunction::Covariance,
113113
"covar_pop" => AggregateFunction::CovariancePop,
114114
"corr" => AggregateFunction::Correlation,
115-
"approx_quantile" => AggregateFunction::ApproxQuantile,
115+
"approx_percentile_cont" => AggregateFunction::ApproxPercentileCont,
116116
_ => {
117117
return Err(DataFusionError::Plan(format!(
118118
"There is no built-in function named {}",
@@ -160,7 +160,7 @@ pub fn return_type(
160160
coerced_data_types[0].clone(),
161161
true,
162162
)))),
163-
AggregateFunction::ApproxQuantile => Ok(coerced_data_types[0].clone()),
163+
AggregateFunction::ApproxPercentileCont => Ok(coerced_data_types[0].clone()),
164164
}
165165
}
166166

@@ -335,17 +335,18 @@ pub fn create_aggregate_expr(
335335
"CORR(DISTINCT) aggregations are not available".to_string(),
336336
));
337337
}
338-
(AggregateFunction::ApproxQuantile, false) => {
339-
Arc::new(expressions::ApproxQuantile::new(
340-
// Pass in the desired quantile expr
338+
(AggregateFunction::ApproxPercentileCont, false) => {
339+
Arc::new(expressions::ApproxPercentileCont::new(
340+
// Pass in the desired percentile expr
341341
coerced_phy_exprs,
342342
name,
343343
return_type,
344344
)?)
345345
}
346-
(AggregateFunction::ApproxQuantile, true) => {
346+
(AggregateFunction::ApproxPercentileCont, true) => {
347347
return Err(DataFusionError::NotImplemented(
348-
"approx_quantile(DISTINCT) aggregations are not available".to_string(),
348+
"approx_percentile_cont(DISTINCT) aggregations are not available"
349+
.to_string(),
349350
));
350351
}
351352
})
@@ -406,8 +407,8 @@ pub fn signature(fun: &AggregateFunction) -> Signature {
406407
AggregateFunction::Correlation => {
407408
Signature::uniform(2, NUMERICS.to_vec(), Volatility::Immutable)
408409
}
409-
AggregateFunction::ApproxQuantile => Signature::one_of(
410-
// Accept any numeric value paired with a float64 quantile
410+
AggregateFunction::ApproxPercentileCont => Signature::one_of(
411+
// Accept any numeric value paired with a float64 percentile
411412
NUMERICS
412413
.iter()
413414
.map(|t| TypeSignature::Exact(vec![t.clone(), DataType::Float64]))
@@ -421,8 +422,8 @@ pub fn signature(fun: &AggregateFunction) -> Signature {
421422
mod tests {
422423
use super::*;
423424
use crate::physical_plan::expressions::{
424-
ApproxDistinct, ApproxQuantile, ArrayAgg, Avg, Correlation, Count, Covariance,
425-
DistinctArrayAgg, DistinctCount, Max, Min, Stddev, Sum, Variance,
425+
ApproxDistinct, ApproxPercentileCont, ArrayAgg, Avg, Correlation, Count,
426+
Covariance, DistinctArrayAgg, DistinctCount, Max, Min, Stddev, Sum, Variance,
426427
};
427428
use crate::{error::Result, scalar::ScalarValue};
428429

@@ -539,7 +540,7 @@ mod tests {
539540
}
540541

541542
#[test]
542-
fn test_agg_approx_quantile_phy_expr() {
543+
fn test_agg_approx_percentile_phy_expr() {
543544
for data_type in NUMERICS {
544545
let input_schema =
545546
Schema::new(vec![Field::new("c1", data_type.clone(), true)]);
@@ -550,15 +551,15 @@ mod tests {
550551
Arc::new(expressions::Literal::new(ScalarValue::Float64(Some(0.2)))),
551552
];
552553
let result_agg_phy_exprs = create_aggregate_expr(
553-
&AggregateFunction::ApproxQuantile,
554+
&AggregateFunction::ApproxPercentileCont,
554555
false,
555556
&input_phy_exprs[..],
556557
&input_schema,
557558
"c1",
558559
)
559560
.expect("failed to create aggregate expr");
560561

561-
assert!(result_agg_phy_exprs.as_any().is::<ApproxQuantile>());
562+
assert!(result_agg_phy_exprs.as_any().is::<ApproxPercentileCont>());
562563
assert_eq!("c1", result_agg_phy_exprs.name());
563564
assert_eq!(
564565
Field::new("c1", data_type.clone(), false),
@@ -568,7 +569,7 @@ mod tests {
568569
}
569570

570571
#[test]
571-
fn test_agg_approx_quantile_invalid_phy_expr() {
572+
fn test_agg_approx_percentile_invalid_phy_expr() {
572573
for data_type in NUMERICS {
573574
let input_schema =
574575
Schema::new(vec![Field::new("c1", data_type.clone(), true)]);
@@ -579,13 +580,13 @@ mod tests {
579580
Arc::new(expressions::Literal::new(ScalarValue::Float64(Some(4.2)))),
580581
];
581582
let err = create_aggregate_expr(
582-
&AggregateFunction::ApproxQuantile,
583+
&AggregateFunction::ApproxPercentileCont,
583584
false,
584585
&input_phy_exprs[..],
585586
&input_schema,
586587
"c1",
587588
)
588-
.expect_err("should fail due to invalid quantile");
589+
.expect_err("should fail due to invalid percentile");
589590

590591
assert!(matches!(err, DataFusionError::Plan(_)));
591592
}

datafusion/src/physical_plan/coercion_rule/aggregate_rule.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::physical_plan::functions::{Signature, TypeSignature};
2828
use crate::physical_plan::PhysicalExpr;
2929
use crate::{
3030
arrow::datatypes::Schema,
31-
physical_plan::expressions::is_approx_quantile_supported_arg_type,
31+
physical_plan::expressions::is_approx_percentile_cont_supported_arg_type,
3232
};
3333
use arrow::datatypes::DataType;
3434
use std::ops::Deref;
@@ -139,16 +139,16 @@ pub(crate) fn coerce_types(
139139
}
140140
Ok(input_types.to_vec())
141141
}
142-
AggregateFunction::ApproxQuantile => {
143-
if !is_approx_quantile_supported_arg_type(&input_types[0]) {
142+
AggregateFunction::ApproxPercentileCont => {
143+
if !is_approx_percentile_cont_supported_arg_type(&input_types[0]) {
144144
return Err(DataFusionError::Plan(format!(
145145
"The function {:?} does not support inputs of type {:?}.",
146146
agg_fun, input_types[0]
147147
)));
148148
}
149149
if !matches!(input_types[1], DataType::Float64) {
150150
return Err(DataFusionError::Plan(format!(
151-
"The quantile argument for {:?} must be Float64, not {:?}.",
151+
"The percentile argument for {:?} must be Float64, not {:?}.",
152152
agg_fun, input_types[1]
153153
)));
154154
}
@@ -324,7 +324,7 @@ mod tests {
324324
}
325325
}
326326

327-
// ApproxQuantile input types
327+
// ApproxPercentileCont input types
328328
let input_types = vec![
329329
vec![DataType::Int8, DataType::Float64],
330330
vec![DataType::Int16, DataType::Float64],
@@ -338,9 +338,13 @@ mod tests {
338338
vec![DataType::Float64, DataType::Float64],
339339
];
340340
for input_type in &input_types {
341-
let signature = aggregates::signature(&AggregateFunction::ApproxQuantile);
342-
let result =
343-
coerce_types(&AggregateFunction::ApproxQuantile, input_type, &signature);
341+
let signature =
342+
aggregates::signature(&AggregateFunction::ApproxPercentileCont);
343+
let result = coerce_types(
344+
&AggregateFunction::ApproxPercentileCont,
345+
input_type,
346+
&signature,
347+
);
344348
assert_eq!(*input_type, result.unwrap());
345349
}
346350
}

0 commit comments

Comments
 (0)