Skip to content

Commit

Permalink
Use a short name for set monotonicity
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankabak committed Jan 30, 2025
1 parent 5e9b2db commit 54d62d6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions datafusion/expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub use partition_evaluator::PartitionEvaluator;
pub use sqlparser;
pub use table_source::{TableProviderFilterPushDown, TableSource, TableType};
pub use udaf::{
aggregate_doc_sections, AggregateExprSetMonotonicity, AggregateUDF, AggregateUDFImpl,
ReversedUDAF, StatisticsArgs,
aggregate_doc_sections, AggregateUDF, AggregateUDFImpl, ReversedUDAF,
SetMonotonicity, StatisticsArgs,
};
pub use udf::{
scalar_doc_sections, ReturnInfo, ReturnTypeArgs, ScalarFunctionArgs, ScalarUDF,
Expand Down
8 changes: 4 additions & 4 deletions datafusion/expr/src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
}

/// Indicates whether the aggregation function is monotonic as a set
/// function. See [`AggregateExprSetMonotonicity`] for details.
fn set_monotonicity(&self, _data_type: &DataType) -> AggregateExprSetMonotonicity {
AggregateExprSetMonotonicity::NotMonotonic
/// function. See [`SetMonotonicity`] for details.
fn set_monotonicity(&self, _data_type: &DataType) -> SetMonotonicity {
SetMonotonicity::NotMonotonic
}
}

Expand Down Expand Up @@ -835,7 +835,7 @@ pub mod aggregate_doc_sections {
/// the other hand, `MIN` is monotonically decreasing as its value always
/// decreases or stays the same as new values are seen.
#[derive(Debug, Clone, PartialEq)]
pub enum AggregateExprSetMonotonicity {
pub enum SetMonotonicity {
/// Aggregate value increases or stays the same as the input set grows.
Increasing,
/// Aggregate value decreases or stays the same as the input set grows.
Expand Down
9 changes: 4 additions & 5 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ use datafusion_common::{
};
use datafusion_expr::function::StateFieldsArgs;
use datafusion_expr::{
function::AccumulatorArgs, utils::format_state_name, Accumulator,
AggregateExprSetMonotonicity, AggregateUDFImpl, Documentation, EmitTo,
GroupsAccumulator, Signature, Volatility,
function::AccumulatorArgs, utils::format_state_name, Accumulator, AggregateUDFImpl,
Documentation, EmitTo, GroupsAccumulator, SetMonotonicity, Signature, Volatility,
};
use datafusion_expr::{Expr, ReversedUDAF, StatisticsArgs, TypeSignature};
use datafusion_functions_aggregate_common::aggregate::count_distinct::{
Expand Down Expand Up @@ -353,10 +352,10 @@ impl AggregateUDFImpl for Count {
self.doc()
}

fn set_monotonicity(&self, _data_type: &DataType) -> AggregateExprSetMonotonicity {
fn set_monotonicity(&self, _data_type: &DataType) -> SetMonotonicity {
// `COUNT` is monotonically increasing as it always increases or stays
// the same as new values are seen.
AggregateExprSetMonotonicity::Increasing
SetMonotonicity::Increasing
}
}

Expand Down
12 changes: 6 additions & 6 deletions datafusion/functions-aggregate/src/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use arrow::datatypes::{
use crate::min_max::min_max_bytes::MinMaxBytesAccumulator;
use datafusion_common::ScalarValue;
use datafusion_expr::{
function::AccumulatorArgs, Accumulator, AggregateExprSetMonotonicity,
AggregateUDFImpl, Documentation, Signature, Volatility,
function::AccumulatorArgs, Accumulator, AggregateUDFImpl, Documentation,
SetMonotonicity, Signature, Volatility,
};
use datafusion_expr::{GroupsAccumulator, StatisticsArgs};
use datafusion_macros::user_doc;
Expand Down Expand Up @@ -362,10 +362,10 @@ impl AggregateUDFImpl for Max {
self.doc()
}

fn set_monotonicity(&self, _data_type: &DataType) -> AggregateExprSetMonotonicity {
fn set_monotonicity(&self, _data_type: &DataType) -> SetMonotonicity {
// `MAX` is monotonically increasing as it always increases or stays
// the same as new values are seen.
AggregateExprSetMonotonicity::Increasing
SetMonotonicity::Increasing
}
}

Expand Down Expand Up @@ -1190,10 +1190,10 @@ impl AggregateUDFImpl for Min {
self.doc()
}

fn set_monotonicity(&self, _data_type: &DataType) -> AggregateExprSetMonotonicity {
fn set_monotonicity(&self, _data_type: &DataType) -> SetMonotonicity {
// `MIN` is monotonically decreasing as it always decreases or stays
// the same as new values are seen.
AggregateExprSetMonotonicity::Decreasing
SetMonotonicity::Decreasing
}
}

Expand Down
16 changes: 8 additions & 8 deletions datafusion/functions-aggregate/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use datafusion_expr::function::AccumulatorArgs;
use datafusion_expr::function::StateFieldsArgs;
use datafusion_expr::utils::format_state_name;
use datafusion_expr::{
Accumulator, AggregateExprSetMonotonicity, AggregateUDFImpl, Documentation,
GroupsAccumulator, ReversedUDAF, Signature, Volatility,
Accumulator, AggregateUDFImpl, Documentation, GroupsAccumulator, ReversedUDAF,
SetMonotonicity, Signature, Volatility,
};
use datafusion_functions_aggregate_common::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator;
use datafusion_functions_aggregate_common::utils::Hashable;
Expand Down Expand Up @@ -255,15 +255,15 @@ impl AggregateUDFImpl for Sum {
self.doc()
}

fn set_monotonicity(&self, data_type: &DataType) -> AggregateExprSetMonotonicity {
fn set_monotonicity(&self, data_type: &DataType) -> SetMonotonicity {
// `SUM` is only monotonically increasing when its input is unsigned.
// TODO: Expand these utilizing statistics.
match data_type {
DataType::UInt8 => AggregateExprSetMonotonicity::Increasing,
DataType::UInt16 => AggregateExprSetMonotonicity::Increasing,
DataType::UInt32 => AggregateExprSetMonotonicity::Increasing,
DataType::UInt64 => AggregateExprSetMonotonicity::Increasing,
_ => AggregateExprSetMonotonicity::NotMonotonic,
DataType::UInt8 => SetMonotonicity::Increasing,
DataType::UInt16 => SetMonotonicity::Increasing,
DataType::UInt32 => SetMonotonicity::Increasing,
DataType::UInt64 => SetMonotonicity::Increasing,
_ => SetMonotonicity::NotMonotonic,
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions datafusion/physical-expr/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::expressions::Column;
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
use arrow_schema::SortOptions;
use datafusion_common::{internal_err, not_impl_err, Result, ScalarValue};
use datafusion_expr::{AggregateExprSetMonotonicity, AggregateUDF, ReversedUDAF};
use datafusion_expr::{AggregateUDF, ReversedUDAF, SetMonotonicity};
use datafusion_expr_common::accumulator::Accumulator;
use datafusion_expr_common::groups_accumulator::GroupsAccumulator;
use datafusion_expr_common::type_coercion::aggregates::check_arg_count;
Expand Down Expand Up @@ -537,8 +537,8 @@ impl AggregateFunctionExpr {
}

/// Indicates whether the aggregation function is monotonic as a set
/// function. See [`AggregateExprSetMonotonicity`] for details.
pub fn set_monotonicity(&self) -> AggregateExprSetMonotonicity {
/// function. See [`SetMonotonicity`] for details.
pub fn set_monotonicity(&self) -> SetMonotonicity {
let field = self.field();
let data_type = field.data_type();
self.fun.inner().set_monotonicity(data_type)
Expand All @@ -549,14 +549,12 @@ impl AggregateFunctionExpr {
// If the aggregate expressions are set-monotonic, the output data is
// naturally ordered with it per group or partition.
let monotonicity = self.set_monotonicity();
if monotonicity == AggregateExprSetMonotonicity::NotMonotonic {
if monotonicity == SetMonotonicity::NotMonotonic {
return None;
}
let expr = Arc::new(Column::new(self.name(), aggr_func_idx));
let options = SortOptions::new(
monotonicity == AggregateExprSetMonotonicity::Decreasing,
false,
);
let options =
SortOptions::new(monotonicity == SetMonotonicity::Decreasing, false);
Some(PhysicalSortExpr { expr, options })
}
}
Expand Down

0 comments on commit 54d62d6

Please sign in to comment.