Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ async fn test_aggregate_with_pk2() -> Result<()> {
assert_snapshot!(
physical_plan_to_string(&df).await,
@r"
AggregateExec: mode=Single, gby=[id@0 as id, name@1 as name], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Single, gby=[id@0 as id, name@1 as name], aggr=[], group_clustering_mode=Full
FilterExec: id@0 = 1 AND name@1 = a
DataSourceExec: partitions=1, partition_sizes=[1]
"
Expand Down Expand Up @@ -941,7 +941,7 @@ async fn test_aggregate_with_pk3() -> Result<()> {
assert_snapshot!(
physical_plan_to_string(&df).await,
@r"
AggregateExec: mode=Single, gby=[id@0 as id, name@1 as name], aggr=[], ordering_mode=PartiallySorted([0])
AggregateExec: mode=Single, gby=[id@0 as id, name@1 as name], aggr=[], group_clustering_mode=Partial([0])
FilterExec: id@0 = 1
DataSourceExec: partitions=1, partition_sizes=[1]
"
Expand Down Expand Up @@ -991,7 +991,7 @@ async fn test_aggregate_with_pk4() -> Result<()> {
assert_snapshot!(
physical_plan_to_string(&df).await,
@r"
AggregateExec: mode=Single, gby=[id@0 as id], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Single, gby=[id@0 as id], aggr=[], group_clustering_mode=Full
FilterExec: id@0 = 1
DataSourceExec: partitions=1, partition_sizes=[1]
"
Expand Down Expand Up @@ -3273,9 +3273,9 @@ async fn union_with_mix_of_presorted_and_explicitly_resorted_inputs_with_reparti
assert_snapshot!(
union_with_mix_of_presorted_and_explicitly_resorted_inputs_impl(false).await?,
@r"
AggregateExec: mode=Final, gby=[id@0 as id], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Final, gby=[id@0 as id], aggr=[], group_clustering_mode=Full
SortPreservingMergeExec: [id@0 ASC NULLS LAST]
AggregateExec: mode=Partial, gby=[id@0 as id], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Partial, gby=[id@0 as id], aggr=[], group_clustering_mode=Full
UnionExec
DataSourceExec: file_groups={1 group: [[{testdata}/alltypes_tiny_pages.parquet]]}, projection=[id], output_ordering=[id@0 ASC NULLS LAST], file_type=parquet
SortExec: expr=[id@0 ASC NULLS LAST], preserve_partitioning=[false]
Expand All @@ -3291,9 +3291,9 @@ async fn union_with_mix_of_presorted_and_explicitly_resorted_inputs_with_reparti
assert_snapshot!(
union_with_mix_of_presorted_and_explicitly_resorted_inputs_impl(true).await?,
@r"
AggregateExec: mode=Final, gby=[id@0 as id], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Final, gby=[id@0 as id], aggr=[], group_clustering_mode=Full
SortPreservingMergeExec: [id@0 ASC NULLS LAST]
AggregateExec: mode=Partial, gby=[id@0 as id], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Partial, gby=[id@0 as id], aggr=[], group_clustering_mode=Full
UnionExec
DataSourceExec: file_groups={1 group: [[{testdata}/alltypes_tiny_pages.parquet]]}, projection=[id], output_ordering=[id@0 ASC NULLS LAST], file_type=parquet
SortExec: expr=[id@0 ASC NULLS LAST], preserve_partitioning=[false]
Expand Down
12 changes: 6 additions & 6 deletions datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use datafusion_common_runtime::JoinSet;
use datafusion_functions_aggregate::sum::sum_udaf;
use datafusion_physical_expr::PhysicalSortExpr;
use datafusion_physical_expr::expressions::{Column, col, lit};
use datafusion_physical_plan::InputOrderMode;
use datafusion_physical_plan::aggregates::GroupClusteringMode;
use test_utils::{StringBatchGenerator, add_empty_batches};

use datafusion_execution::TaskContext;
Expand Down Expand Up @@ -352,8 +352,8 @@ async fn run_aggregate_test(input1: Vec<RecordBatch>, group_by_columns: Vec<&str
.unwrap(),
);
assert_ne!(
aggregate_exec_running.input_order_mode(),
&InputOrderMode::Linear,
aggregate_exec_running.group_clustering_mode(),
&GroupClusteringMode::None,
"running aggregate should observe ordered input for group_by: {group_by:?}"
);

Expand Down Expand Up @@ -555,11 +555,11 @@ async fn verify_ordered_aggregate(frame: &DataFrame, expected_sort: bool) {
if let Some(exec) = node.downcast_ref::<AggregateExec>() {
if self.expected_sort {
assert!(matches!(
exec.input_order_mode(),
InputOrderMode::PartiallySorted(_) | InputOrderMode::Sorted
exec.group_clustering_mode(),
GroupClusteringMode::Partial(_) | GroupClusteringMode::Full
));
} else {
assert_eq!(*exec.input_order_mode(), InputOrderMode::Linear);
assert_eq!(*exec.group_clustering_mode(), GroupClusteringMode::None);
}
}
Ok(TreeNodeRecursion::Continue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ pub struct QueryBuilder {
/// ...
/// ```
///
/// More details can see [`GroupOrdering`].
/// More details can see [`GroupClustering`].
///
/// [`GroupOrdering`]: datafusion_physical_plan::aggregates::order::GroupOrdering
/// [`GroupClustering`]: datafusion_physical_plan::aggregates::order::GroupClustering
dataset_sort_keys: Vec<Vec<String>>,

/// If we will also test the no grouping case like:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3954,9 +3954,9 @@ fn preserve_ordering_for_streaming_sorted_aggregate() -> Result<()> {

let plan_distrib = test_config.to_plan(physical_plan.clone(), &DISTRIB_DISTRIB_SORT);
assert_plan!(plan_distrib, @r"
AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[COUNT(b)], ordering_mode=Sorted
AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[COUNT(b)], group_clustering_mode=Full
RepartitionExec: partitioning=Hash([a@0], 2), input_partitions=2, preserve_order=true, sort_exprs=a@0 ASC
AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[COUNT(b)], ordering_mode=Sorted
AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[COUNT(b)], group_clustering_mode=Full
DataSourceExec: file_groups={2 groups: [[x], [y]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], file_type=parquet
");

Expand Down Expand Up @@ -3988,9 +3988,9 @@ fn preserve_ordering_for_streaming_partially_sorted_aggregate() -> Result<()> {

let plan_distrib = test_config.to_plan(physical_plan.clone(), &DISTRIB_DISTRIB_SORT);
assert_plan!(plan_distrib, @r"
AggregateExec: mode=FinalPartitioned, gby=[a@0 as a, b@1 as b], aggr=[COUNT(c)], ordering_mode=PartiallySorted([0])
AggregateExec: mode=FinalPartitioned, gby=[a@0 as a, b@1 as b], aggr=[COUNT(c)], group_clustering_mode=Partial([0])
RepartitionExec: partitioning=Hash([a@0, b@1], 2), input_partitions=2, preserve_order=true, sort_exprs=a@0 ASC
AggregateExec: mode=Partial, gby=[a@0 as a, b@1 as b], aggr=[COUNT(c)], ordering_mode=PartiallySorted([0])
AggregateExec: mode=Partial, gby=[a@0 as a, b@1 as b], aggr=[COUNT(c)], group_clustering_mode=Partial([0])
DataSourceExec: file_groups={2 groups: [[x], [y]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], file_type=parquet
");

Expand Down
14 changes: 7 additions & 7 deletions datafusion/core/tests/physical_optimizer/filter_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,12 @@ fn test_pushdown_through_aggregates_on_grouping_columns() {
OptimizationTest:
input:
- FilterExec: b@1 = bar
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], ordering_mode=PartiallySorted([0])
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], group_clustering_mode=Partial([0])
- FilterExec: a@0 = foo
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
output:
Ok:
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], ordering_mode=Sorted
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], group_clustering_mode=Full
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=a@0 = foo AND b@1 = bar
"
);
Expand Down Expand Up @@ -801,7 +801,7 @@ fn test_pushdown_through_aggregates_preserves_parent_filter_order() {
output:
Ok:
- FilterExec: cnt@2 = 1
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], ordering_mode=PartiallySorted([1])
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], group_clustering_mode=Partial([1])
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=b@1 = bar
"
);
Expand Down Expand Up @@ -2493,7 +2493,7 @@ fn test_pushdown_filter_on_non_first_grouping_column() {
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
output:
Ok:
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], ordering_mode=PartiallySorted([1])
- AggregateExec: mode=Final, gby=[a@0 as a, b@1 as b], aggr=[cnt], group_clustering_mode=Partial([1])
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=b@1 = bar
"
);
Expand Down Expand Up @@ -2632,7 +2632,7 @@ fn test_pushdown_grouping_sets_filter_on_common_column() {
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
output:
Ok:
- AggregateExec: mode=Final, gby=[(a@0 as a, b@1 as b), (NULL as a, b@1 as b)], aggr=[cnt], ordering_mode=PartiallySorted([1])
- AggregateExec: mode=Final, gby=[(a@0 as a, b@1 as b), (NULL as a, b@1 as b)], aggr=[cnt], group_clustering_mode=Partial([1])
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=b@1 = bar
"
);
Expand Down Expand Up @@ -2829,7 +2829,7 @@ fn test_pushdown_through_aggregate_with_reordered_input_columns() {
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
output:
Ok:
- AggregateExec: mode=Final, gby=[a@1 as a, b@2 as b], aggr=[cnt], ordering_mode=PartiallySorted([1])
- AggregateExec: mode=Final, gby=[a@1 as a, b@2 as b], aggr=[cnt], group_clustering_mode=Partial([1])
- ProjectionExec: expr=[c@2 as c, a@0 as a, b@1 as b]
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=b@1 = bar
"
Expand Down Expand Up @@ -2918,7 +2918,7 @@ fn test_pushdown_through_aggregate_grouping_sets_with_reordered_input() {
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
output:
Ok:
- AggregateExec: mode=Final, gby=[(a@1 as a, b@2 as b), (NULL as a, b@2 as b)], aggr=[cnt], ordering_mode=PartiallySorted([1])
- AggregateExec: mode=Final, gby=[(a@1 as a, b@2 as b), (NULL as a, b@2 as b)], aggr=[cnt], group_clustering_mode=Partial([1])
- ProjectionExec: expr=[c@2 as c, a@0 as a, b@1 as b]
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=b@1 = bar
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ fn test_has_order_by() -> Result<()> {
actual,
@r"
LocalLimitExec: fetch=10
AggregateExec: mode=Single, gby=[a@0 as a], aggr=[], ordering_mode=Sorted
AggregateExec: mode=Single, gby=[a@0 as a], aggr=[], group_clustering_mode=Full
DataSourceExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], file_type=parquet
"
);
Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/tests/physical_optimizer/pushdown_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,13 @@ fn test_pushdown_through_blocking_node() {
OptimizationTest:
input:
- SortExec: expr=[a@0 ASC], preserve_partitioning=[false]
- AggregateExec: mode=Final, gby=[a@0 as a], aggr=[COUNT(b)], ordering_mode=Sorted
- AggregateExec: mode=Final, gby=[a@0 as a], aggr=[COUNT(b)], group_clustering_mode=Full
- SortExec: expr=[a@0 DESC NULLS LAST], preserve_partitioning=[false]
- DataSourceExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], file_type=parquet
output:
Ok:
- SortExec: expr=[a@0 ASC], preserve_partitioning=[false]
- AggregateExec: mode=Final, gby=[a@0 as a], aggr=[COUNT(b)], ordering_mode=Sorted
- AggregateExec: mode=Final, gby=[a@0 as a], aggr=[COUNT(b)], group_clustering_mode=Full
- SortExec: expr=[a@0 DESC NULLS LAST], preserve_partitioning=[false]
- DataSourceExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], file_type=parquet, sort_order_for_reorder=[a@0 DESC NULLS LAST], reverse_row_groups=true
"
Expand Down
6 changes: 3 additions & 3 deletions datafusion/physical-plan/benches/dictionary_group_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use criterion::{
};
use datafusion_expr::EmitTo;
use datafusion_physical_plan::aggregates::group_values::new_group_values;
use datafusion_physical_plan::aggregates::order::GroupOrdering;
use datafusion_physical_plan::aggregates::order::GroupClustering;
use rand::rngs::StdRng;
use rand::seq::SliceRandom;
use rand::{Rng, SeedableRng};
Expand Down Expand Up @@ -106,7 +106,7 @@ fn bench_intern_emit(c: &mut Criterion) {
b.iter_batched_ref(
|| {
(
new_group_values(schema.clone(), &GroupOrdering::None)
new_group_values(schema.clone(), &GroupClustering::None)
.unwrap(),
Vec::<usize>::with_capacity(size),
)
Expand Down Expand Up @@ -151,7 +151,7 @@ fn bench_repeated_intern_emit(c: &mut Criterion) {
b.iter_batched_ref(
|| {
(
new_group_values(schema.clone(), &GroupOrdering::None)
new_group_values(schema.clone(), &GroupClustering::None)
.unwrap(),
Vec::<usize>::with_capacity(size),
)
Expand Down
16 changes: 8 additions & 8 deletions datafusion/physical-plan/benches/partial_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::sync::Arc;

use arrow::array::{ArrayRef, Int32Array};
use datafusion_physical_plan::aggregates::order::GroupOrderingPartial;
use datafusion_physical_plan::aggregates::order::GroupClusteringPartial;

use criterion::{Criterion, criterion_group, criterion_main};

Expand All @@ -34,20 +34,20 @@ fn create_test_arrays(num_columns: usize) -> Vec<ArrayRef> {
.collect()
}
fn bench_new_groups(c: &mut Criterion) {
let mut group = c.benchmark_group("group_ordering_partial");
let mut group = c.benchmark_group("group_clustering_partial");

// Test with 1, 2, 4, and 8 order indices
// Test with 1, 2, 4, and 8 grouping indices
for num_columns in [1, 2, 4, 8] {
let order_indices: Vec<usize> = (0..num_columns).collect();
let grouping_indices: Vec<usize> = (0..num_columns).collect();

group.bench_function(format!("order_indices_{num_columns}"), |b| {
group.bench_function(format!("grouping_indices_{num_columns}"), |b| {
let batch_group_values = create_test_arrays(num_columns);
let group_indices: Vec<usize> = (0..BATCH_SIZE).collect();

b.iter(|| {
let mut ordering =
GroupOrderingPartial::try_new(order_indices.clone()).unwrap();
ordering
let mut clustering =
GroupClusteringPartial::try_new(grouping_indices.clone()).unwrap();
clustering
.new_groups(&batch_group_values, &group_indices, BATCH_SIZE)
.unwrap();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

//! Aggregate table for final aggregation when partial-state input is ordered.
//!
//! See comments in [`super::ordered_partial_table`] for details.
//! See comments in [`super::clustered_partial_table`] for details.

use std::sync::Arc;

use arrow::datatypes::SchemaRef;
use arrow::record_batch::RecordBatch;
use datafusion_common::Result;

use crate::InputOrderMode;
use crate::aggregates::GroupClusteringMode;
use crate::aggregates::aggregate_hash_table::FinalMarker;
use crate::aggregates::group_values::GroupByMetrics;
use crate::aggregates::{AggregateExec, AggregateMode};

use super::common_ordered::OrderedAggregateTable;
use super::common_clustered::ClusteredAggregateTable;

/// Implementation specific to final aggregation, where the table stores partial
/// aggregate states and the input rows are also partial states.
Expand All @@ -40,14 +40,14 @@ use super::common_ordered::OrderedAggregateTable;
/// - Aggregate table stores: `k, sum(x), count(x)`
/// - Input rows: `k, sum(x), count(x)`
///
/// See comments at [`OrderedAggregateTable`] for details.
impl OrderedAggregateTable<FinalMarker> {
/// See comments at [`ClusteredAggregateTable`] for details.
impl ClusteredAggregateTable<FinalMarker> {
pub(in crate::aggregates) fn new_with_input_order(
agg: &AggregateExec,
input_schema: &SchemaRef,
output_schema: SchemaRef,
batch_size: usize,
input_order_mode: &InputOrderMode,
group_clustering_mode: &GroupClusteringMode,
group_by_metrics: GroupByMetrics,
) -> Result<Self> {
Self::new_for_mode(
Expand All @@ -56,7 +56,7 @@ impl OrderedAggregateTable<FinalMarker> {
output_schema,
Arc::clone(input_schema),
batch_size,
input_order_mode,
group_clustering_mode,
&AggregateMode::Final,
vec![None; agg.aggr_expr.len()],
group_by_metrics,
Expand All @@ -76,7 +76,7 @@ impl OrderedAggregateTable<FinalMarker> {
self.aggregate_evaluated_batch(&evaluated_batch, true)
}

/// See comments in `ordered_partial_stream::next_output_batch`
/// See comments in `clustered_partial_stream::next_output_batch`
pub(in crate::aggregates) fn next_output_batch(
&mut self,
) -> Result<Option<RecordBatch>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Aggregate table for partial aggregation when input is ordered by group keys.
//!
//! See the [`super::common_ordered`] comments for the high-level ideas.
//! See the [`super::common_clustered`] comments for the high-level ideas.
//!
//! This operator handles input that is ordered by group keys:
//! - Fully ordered: `GROUP BY a, b`, input is `ORDER BY a, b`
Expand All @@ -40,7 +40,7 @@ use crate::aggregates::{
group_values::GroupByMetrics,
};

use super::common_ordered::OrderedAggregateTable;
use super::common_clustered::ClusteredAggregateTable;

/// Implementation specific to partial aggregation, where the table stores
/// partial aggregate states and the input rows are raw rows.
Expand All @@ -50,8 +50,8 @@ use super::common_ordered::OrderedAggregateTable;
/// - Aggregate table stores: `k, sum(x), count(x)`
/// - Input rows: `k, x`
///
/// See comments at [`OrderedAggregateTable`] for details.
impl OrderedAggregateTable<PartialMarker> {
/// See comments at [`ClusteredAggregateTable`] for details.
impl ClusteredAggregateTable<PartialMarker> {
pub(in crate::aggregates) fn new(
agg: &AggregateExec,
partition: usize,
Expand All @@ -67,7 +67,7 @@ impl OrderedAggregateTable<PartialMarker> {
output_schema,
state_schema,
batch_size,
&agg.input_order_mode,
&agg.group_clustering_mode,
&AggregateMode::Partial,
agg.filter_expr.iter().cloned().collect(),
group_by_metrics,
Expand All @@ -92,8 +92,8 @@ impl OrderedAggregateTable<PartialMarker> {
/// are complete and safe to emit.
///
/// Key steps:
/// 1. Ask `group_ordering` to decide how many groups can be emitted eagerly.
/// 2. Remove the emitted groups from `group_ordering`, `GroupValues`, and
/// 1. Ask `group_clustering` to decide how many groups can be emitted eagerly.
/// 2. Remove the emitted groups from `group_clustering`, `GroupValues`, and
/// all `GroupsAccumulator`s.
///
/// This may output small batches. Avoiding tiny batches is left to future
Expand Down
Loading
Loading