@@ -1131,6 +1131,8 @@ pub struct WindowFunctionParams {
11311131 pub window_frame : WindowFrame ,
11321132 /// Specifies how NULL value is treated: ignore or respect
11331133 pub null_treatment : Option < NullTreatment > ,
1134+ /// Distinct flag
1135+ pub distinct : bool ,
11341136}
11351137
11361138impl WindowFunction {
@@ -1145,6 +1147,7 @@ impl WindowFunction {
11451147 order_by : Vec :: default ( ) ,
11461148 window_frame : WindowFrame :: new ( None ) ,
11471149 null_treatment : None ,
1150+ distinct : false ,
11481151 } ,
11491152 }
11501153 }
@@ -2291,6 +2294,7 @@ impl NormalizeEq for Expr {
22912294 partition_by : self_partition_by,
22922295 order_by : self_order_by,
22932296 null_treatment : self_null_treatment,
2297+ distinct : self_distinct,
22942298 } ,
22952299 } = left. as_ref ( ) ;
22962300 let WindowFunction {
@@ -2302,6 +2306,7 @@ impl NormalizeEq for Expr {
23022306 partition_by : other_partition_by,
23032307 order_by : other_order_by,
23042308 null_treatment : other_null_treatment,
2309+ distinct : other_distinct,
23052310 } ,
23062311 } = other. as_ref ( ) ;
23072312
@@ -2325,6 +2330,7 @@ impl NormalizeEq for Expr {
23252330 && a. nulls_first == b. nulls_first
23262331 && a. expr . normalize_eq ( & b. expr )
23272332 } )
2333+ && self_distinct == other_distinct
23282334 }
23292335 (
23302336 Expr :: Exists ( Exists {
@@ -2558,11 +2564,13 @@ impl HashNode for Expr {
25582564 order_by : _,
25592565 window_frame,
25602566 null_treatment,
2567+ distinct,
25612568 } ,
25622569 } = window_fun. as_ref ( ) ;
25632570 fun. hash ( state) ;
25642571 window_frame. hash ( state) ;
25652572 null_treatment. hash ( state) ;
2573+ distinct. hash ( state) ;
25662574 }
25672575 Expr :: InList ( InList {
25682576 expr : _expr,
@@ -2865,15 +2873,27 @@ impl Display for SchemaDisplay<'_> {
28652873 order_by,
28662874 window_frame,
28672875 null_treatment,
2876+ distinct,
28682877 } = params;
28692878
2879+ // Write function name and open parenthesis
2880+ write ! ( f, "{fun}(" ) ?;
2881+
2882+ // If DISTINCT, emit the keyword
2883+ if * distinct {
2884+ write ! ( f, "DISTINCT " ) ?;
2885+ }
2886+
2887+ // Write the comma‑separated argument list
28702888 write ! (
28712889 f,
2872- "{}({})" ,
2873- fun,
2890+ "{}" ,
28742891 schema_name_from_exprs_comma_separated_without_space( args) ?
28752892 ) ?;
28762893
2894+ // **Close the argument parenthesis**
2895+ write ! ( f, ")" ) ?;
2896+
28772897 if let Some ( null_treatment) = null_treatment {
28782898 write ! ( f, " {null_treatment}" ) ?;
28792899 }
@@ -3260,9 +3280,10 @@ impl Display for Expr {
32603280 order_by,
32613281 window_frame,
32623282 null_treatment,
3283+ distinct,
32633284 } = params;
32643285
3265- fmt_function ( f, & fun. to_string ( ) , false , args, true ) ?;
3286+ fmt_function ( f, & fun. to_string ( ) , * distinct , args, true ) ?;
32663287
32673288 if let Some ( nt) = null_treatment {
32683289 write ! ( f, "{nt}" ) ?;
0 commit comments