@@ -170,7 +170,7 @@ use crate::statistics::{ChildStats, StatisticsArgs};
170170use crate :: { ChildrenPropertiesMode , ReplaceChildrenOptions , validate_child_count} ;
171171use crate :: {
172172 DisplayFormatType , Distribution , ExecutionPlan , InputDistributionRequirements ,
173- InputOrderMode , SendableRecordBatchStream , Statistics ,
173+ InputOrderMode , Partitioning , SendableRecordBatchStream , Statistics ,
174174} ;
175175use datafusion_common:: config:: ConfigOptions ;
176176use parking_lot:: Mutex ;
@@ -1015,7 +1015,7 @@ impl AggregateExec {
10151015 . filter ( |idx| group_by. groups . iter ( ) . all ( |group| !group[ * idx] ) )
10161016 . collect ( ) ;
10171017
1018- let input_order_mode = if indices. len ( ) == groupby_exprs. len ( )
1018+ let mut input_order_mode = if indices. len ( ) == groupby_exprs. len ( )
10191019 && !indices. is_empty ( )
10201020 && group_by. groups . len ( ) == 1
10211021 {
@@ -1026,19 +1026,29 @@ impl AggregateExec {
10261026 InputOrderMode :: Linear
10271027 } ;
10281028
1029+ // To keep the ordering optimization simple, grouping sets are not supported.
1030+ // See [`OrderedPartialAggregateStream`] for more details about this optimization.
1031+ if group_by. has_grouping_set ( ) {
1032+ input_order_mode = InputOrderMode :: Linear ;
1033+ }
1034+
10291035 // construct a map from the input expression to the output expression of the Aggregation group by
10301036 let group_expr_mapping =
10311037 ProjectionMapping :: try_new ( group_by. expr . clone ( ) , & input. schema ( ) ) ?;
10321038
1033- let cache = Self :: compute_properties (
1034- & input,
1035- Arc :: clone ( & schema) ,
1036- & group_expr_mapping,
1037- group_by. is_true_no_grouping ( ) ,
1038- & mode,
1039- & input_order_mode,
1040- aggr_expr. as_ref ( ) ,
1041- ) ?;
1039+ let cache = if group_by. has_grouping_set ( ) {
1040+ Self :: compute_grouping_set_properties ( & input, Arc :: clone ( & schema) )
1041+ } else {
1042+ Self :: compute_properties (
1043+ & input,
1044+ Arc :: clone ( & schema) ,
1045+ & group_expr_mapping,
1046+ group_by. is_true_no_grouping ( ) ,
1047+ & mode,
1048+ & input_order_mode,
1049+ aggr_expr. as_ref ( ) ,
1050+ ) ?
1051+ } ;
10421052
10431053 let mut exec = AggregateExec {
10441054 mode,
@@ -1438,6 +1448,22 @@ impl AggregateExec {
14381448 ) )
14391449 }
14401450
1451+ fn compute_grouping_set_properties (
1452+ input : & Arc < dyn ExecutionPlan > ,
1453+ schema : SchemaRef ,
1454+ ) -> PlanProperties {
1455+ // Grouping-set expansion can replace group keys with nulls and adds a
1456+ // grouping ID, so input properties do not project through unchanged.
1457+ PlanProperties :: new (
1458+ EquivalenceProperties :: new ( schema) ,
1459+ Partitioning :: UnknownPartitioning (
1460+ input. output_partitioning ( ) . partition_count ( ) ,
1461+ ) ,
1462+ EmissionType :: Final ,
1463+ input. boundedness ( ) ,
1464+ )
1465+ }
1466+
14411467 pub fn input_order_mode ( & self ) -> & InputOrderMode {
14421468 & self . input_order_mode
14431469 }
0 commit comments