@@ -446,3 +446,47 @@ impl RecordBatchStream for WindowAggStream {
446446 Arc :: clone ( & self . schema )
447447 }
448448}
449+
450+ #[ cfg( test) ]
451+ mod tests {
452+ use super :: * ;
453+ use crate :: test:: TestMemoryExec ;
454+ use crate :: windows:: create_window_expr;
455+ use arrow:: datatypes:: { DataType , Field , Schema } ;
456+ use datafusion_common:: ScalarValue ;
457+ use datafusion_expr:: {
458+ WindowFrame , WindowFrameBound , WindowFrameUnits , WindowFunctionDefinition ,
459+ } ;
460+ use datafusion_functions_aggregate:: count:: count_udaf;
461+
462+ #[ test]
463+ fn test_window_agg_cardinality_effect ( ) -> Result < ( ) > {
464+ let schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new( "a" , DataType :: Int64 , true ) ] ) ) ;
465+ let input: Arc < dyn ExecutionPlan > =
466+ Arc :: new ( TestMemoryExec :: try_new ( & [ ] , Arc :: clone ( & schema) , None ) ?) ;
467+ let args = vec ! [ crate :: expressions:: col( "a" , & schema) ?] ;
468+ let window_expr = create_window_expr (
469+ & WindowFunctionDefinition :: AggregateUDF ( count_udaf ( ) ) ,
470+ "count(a)" . to_string ( ) ,
471+ & args,
472+ & [ ] ,
473+ & [ ] ,
474+ Arc :: new ( WindowFrame :: new_bounds (
475+ WindowFrameUnits :: Rows ,
476+ WindowFrameBound :: Preceding ( ScalarValue :: UInt64 ( None ) ) ,
477+ WindowFrameBound :: CurrentRow ,
478+ ) ) ,
479+ Arc :: clone ( & schema) ,
480+ false ,
481+ false ,
482+ None ,
483+ ) ?;
484+
485+ let window = WindowAggExec :: try_new ( vec ! [ window_expr] , input, true ) ?;
486+ assert ! ( matches!(
487+ window. cardinality_effect( ) ,
488+ CardinalityEffect :: Equal
489+ ) ) ;
490+ Ok ( ( ) )
491+ }
492+ }
0 commit comments