Skip to content

Commit c603d35

Browse files
committed
address review: import InputDistributionRequirements, add unbounded-frame negative slt test
1 parent f588f75 commit c603d35

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ use crate::windows::{
3636
};
3737
use crate::{
3838
ColumnStatistics, DisplayAs, DisplayFormatType, Distribution, ExecutionPlan,
39-
ExecutionPlanProperties, InputOrderMode, PlanProperties, RecordBatchStream,
40-
SendableRecordBatchStream, Statistics, WindowExpr, check_if_same_properties,
39+
ExecutionPlanProperties, InputDistributionRequirements, InputOrderMode,
40+
PlanProperties, RecordBatchStream, SendableRecordBatchStream, Statistics, WindowExpr,
41+
check_if_same_properties,
4142
};
4243

4344
use arrow::compute::take_record_batch;
@@ -324,12 +325,12 @@ impl ExecutionPlan for BoundedWindowAggExec {
324325
self.input_distribution_requirements().into_per_child()
325326
}
326327

327-
fn input_distribution_requirements(&self) -> crate::InputDistributionRequirements {
328+
fn input_distribution_requirements(&self) -> InputDistributionRequirements {
328329
if self.partition_keys().is_empty() {
329330
debug!("No partition defined for BoundedWindowAggExec!!!");
330-
crate::InputDistributionRequirements::new(vec![Distribution::SinglePartition])
331+
InputDistributionRequirements::new(vec![Distribution::SinglePartition])
331332
} else {
332-
crate::InputDistributionRequirements::new(vec![Distribution::KeyPartitioned(
333+
InputDistributionRequirements::new(vec![Distribution::KeyPartitioned(
333334
self.partition_keys(),
334335
)])
335336
.allow_range_satisfaction_for_key_partitioning()

datafusion/physical-plan/src/windows/window_agg_exec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use crate::windows::{
3232
};
3333
use crate::{
3434
ColumnStatistics, DisplayAs, DisplayFormatType, Distribution, ExecutionPlan,
35-
ExecutionPlanProperties, PhysicalExpr, PlanProperties, RecordBatchStream,
36-
SendableRecordBatchStream, Statistics, WindowExpr, check_if_same_properties,
35+
ExecutionPlanProperties, InputDistributionRequirements, PhysicalExpr, PlanProperties,
36+
RecordBatchStream, SendableRecordBatchStream, Statistics, WindowExpr,
37+
check_if_same_properties,
3738
};
3839

3940
use arrow::array::ArrayRef;
@@ -233,11 +234,11 @@ impl ExecutionPlan for WindowAggExec {
233234
self.input_distribution_requirements().into_per_child()
234235
}
235236

236-
fn input_distribution_requirements(&self) -> crate::InputDistributionRequirements {
237+
fn input_distribution_requirements(&self) -> InputDistributionRequirements {
237238
if self.partition_keys().is_empty() {
238-
crate::InputDistributionRequirements::new(vec![Distribution::SinglePartition])
239+
InputDistributionRequirements::new(vec![Distribution::SinglePartition])
239240
} else {
240-
crate::InputDistributionRequirements::new(vec![Distribution::KeyPartitioned(
241+
InputDistributionRequirements::new(vec![Distribution::KeyPartitioned(
241242
self.partition_keys(),
242243
)])
243244
.allow_range_satisfaction_for_key_partitioning()

datafusion/sqllogictest/test_files/range_partitioning.slt

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,37 @@ SELECT non_range_key, value, SUM(value) OVER (PARTITION BY non_range_key ORDER B
779779

780780

781781
##########
782-
# TEST 22: Window Subset Satisfaction on Range Partition Column
782+
# TEST 22: Unbounded-Frame Window on Non-Range Column Rehashes
783+
# The unbounded frame makes DataFusion use WindowAggExec; Range([range_key])
784+
# does not colocate non_range_key values, so PARTITION BY non_range_key
785+
# still requires a hash repartition.
786+
##########
787+
788+
query TT
789+
EXPLAIN SELECT non_range_key, SUM(value) OVER (PARTITION BY non_range_key ORDER BY value ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM range_partitioned;
790+
----
791+
physical_plan
792+
01)ProjectionExec: expr=[non_range_key@0 as non_range_key, sum(range_partitioned.value) PARTITION BY [range_partitioned.non_range_key] ORDER BY [range_partitioned.value ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING@2 as sum(range_partitioned.value) PARTITION BY [range_partitioned.non_range_key] ORDER BY [range_partitioned.value ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]
793+
02)--WindowAggExec: wdw=[sum(range_partitioned.value) PARTITION BY [range_partitioned.non_range_key] ORDER BY [range_partitioned.value ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING: Ok(Field { name: "sum(range_partitioned.value) PARTITION BY [range_partitioned.non_range_key] ORDER BY [range_partitioned.value ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING", data_type: Int64, nullable: true }), frame: WindowFrame { units: Rows, start_bound: Preceding(UInt64(NULL)), end_bound: Following(UInt64(NULL)), is_causal: false }]
794+
03)----SortExec: expr=[non_range_key@0 ASC NULLS LAST, value@1 ASC NULLS LAST], preserve_partitioning=[true]
795+
04)------RepartitionExec: partitioning=Hash([non_range_key@0], 4), input_partitions=4
796+
05)--------DataSourceExec: file_groups=<slt:ignore>, projection=[non_range_key, value], output_partitioning=UnknownPartitioning(4), file_type=csv, has_header=false
797+
798+
query III
799+
SELECT non_range_key, value, SUM(value) OVER (PARTITION BY non_range_key ORDER BY value ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM range_partitioned ORDER BY non_range_key, value;
800+
----
801+
1 10 610
802+
1 100 610
803+
1 200 610
804+
1 300 610
805+
2 50 800
806+
2 150 800
807+
2 250 800
808+
2 350 800
809+
810+
811+
##########
812+
# TEST 23: Window Subset Satisfaction on Range Partition Column
783813
# With the subset threshold met, Range([range_key]) satisfies
784814
# PARTITION BY (range_key, non_range_key): equal composite keys share the
785815
# same range_key, so they are already colocated.
@@ -811,7 +841,7 @@ SELECT range_key, SUM(value) OVER (PARTITION BY range_key, non_range_key ORDER B
811841

812842

813843
##########
814-
# TEST 23: Exact Range Window Below Subset Threshold
844+
# TEST 24: Exact Range Window Below Subset Threshold
815845
# Even when subset satisfaction is disabled, exact Range([range_key])
816846
# satisfies PARTITION BY range_key when repartitioning would not increase
817847
# partition count.
@@ -837,7 +867,7 @@ physical_plan
837867

838868

839869
##########
840-
# TEST 24: Window Subset Rehashes Below Subset Threshold
870+
# TEST 25: Window Subset Rehashes Below Subset Threshold
841871
# Range([range_key]) is only a subset of PARTITION BY
842872
# (range_key, non_range_key), so it should not satisfy the window key when
843873
# subset satisfaction is disabled.
@@ -873,7 +903,7 @@ reset datafusion.optimizer.subset_repartition_threshold;
873903

874904

875905
##########
876-
# TEST 25: Window Preserves Range When Preserve File Threshold Met
906+
# TEST 26: Window Preserves Range When Preserve File Threshold Met
877907
# With the subset threshold not met, preserve-file threshold 1 still
878908
# preserves Range even though target_partitions is 5.
879909
##########
@@ -916,7 +946,7 @@ reset datafusion.optimizer.preserve_file_partitions;
916946

917947

918948
##########
919-
# TEST 26: Window Keeps Range When Preserve File Threshold Not Met
949+
# TEST 27: Window Keeps Range When Preserve File Threshold Not Met
920950
# With the subset threshold met, the window reuses Range even though the
921951
# preserve-file threshold is not met and target_partitions is 5.
922952
##########
@@ -959,7 +989,7 @@ reset datafusion.optimizer.preserve_file_partitions;
959989

960990

961991
##########
962-
# TEST 27: Window Rehashes Below Subset Threshold
992+
# TEST 28: Window Rehashes Below Subset Threshold
963993
# With subset threshold 5 and only 4 input partitions, planning repartitions
964994
# to increase parallelism instead of reusing Range partitioning.
965995
##########
@@ -994,7 +1024,7 @@ reset datafusion.optimizer.preserve_file_partitions;
9941024

9951025

9961026
##########
997-
# TEST 28: Window Without Partition Keys Uses a Single Partition
1027+
# TEST 29: Window Without Partition Keys Uses a Single Partition
9981028
# A window with no PARTITION BY requires a single partition; range
9991029
# partitioning is not applicable.
10001030
##########

0 commit comments

Comments
 (0)