@@ -948,6 +948,8 @@ pub struct WindowFunctionParams {
948948 pub window_frame : WindowFrame ,
949949 /// Specifies how NULL value is treated: ignore or respect
950950 pub null_treatment : Option < NullTreatment > ,
951+ /// Distinct flag
952+ pub distinct : bool ,
951953}
952954
953955impl WindowFunction {
@@ -962,6 +964,7 @@ impl WindowFunction {
962964 order_by : Vec :: default ( ) ,
963965 window_frame : WindowFrame :: new ( None ) ,
964966 null_treatment : None ,
967+ distinct : false ,
965968 } ,
966969 }
967970 }
@@ -2130,6 +2133,7 @@ impl NormalizeEq for Expr {
21302133 partition_by : self_partition_by,
21312134 order_by : self_order_by,
21322135 null_treatment : self_null_treatment,
2136+ distinct : self_distinct,
21332137 } ,
21342138 } = left. as_ref ( ) ;
21352139 let WindowFunction {
@@ -2141,6 +2145,7 @@ impl NormalizeEq for Expr {
21412145 partition_by : other_partition_by,
21422146 order_by : other_order_by,
21432147 null_treatment : other_null_treatment,
2148+ distinct : other_distinct,
21442149 } ,
21452150 } = other. as_ref ( ) ;
21462151
@@ -2164,6 +2169,7 @@ impl NormalizeEq for Expr {
21642169 && a. nulls_first == b. nulls_first
21652170 && a. expr . normalize_eq ( & b. expr )
21662171 } )
2172+ && self_distinct == other_distinct
21672173 }
21682174 (
21692175 Expr :: Exists ( Exists {
@@ -2397,11 +2403,13 @@ impl HashNode for Expr {
23972403 order_by : _,
23982404 window_frame,
23992405 null_treatment,
2406+ distinct,
24002407 } ,
24012408 } = window_fun. as_ref ( ) ;
24022409 fun. hash ( state) ;
24032410 window_frame. hash ( state) ;
24042411 null_treatment. hash ( state) ;
2412+ distinct. hash ( state) ;
24052413 }
24062414 Expr :: InList ( InList {
24072415 expr : _expr,
@@ -2704,15 +2712,27 @@ impl Display for SchemaDisplay<'_> {
27042712 order_by,
27052713 window_frame,
27062714 null_treatment,
2715+ distinct,
27072716 } = params;
27082717
2718+ // Write function name and open parenthesis
2719+ write ! ( f, "{fun}(" ) ?;
2720+
2721+ // If DISTINCT, emit the keyword
2722+ if * distinct {
2723+ write ! ( f, "DISTINCT " ) ?;
2724+ }
2725+
2726+ // Write the comma‑separated argument list
27092727 write ! (
27102728 f,
2711- "{}({})" ,
2712- fun,
2729+ "{}" ,
27132730 schema_name_from_exprs_comma_separated_without_space( args) ?
27142731 ) ?;
27152732
2733+ // **Close the argument parenthesis**
2734+ write ! ( f, ")" ) ?;
2735+
27162736 if let Some ( null_treatment) = null_treatment {
27172737 write ! ( f, " {null_treatment}" ) ?;
27182738 }
@@ -3099,9 +3119,10 @@ impl Display for Expr {
30993119 order_by,
31003120 window_frame,
31013121 null_treatment,
3122+ distinct,
31023123 } = params;
31033124
3104- fmt_function ( f, & fun. to_string ( ) , false , args, true ) ?;
3125+ fmt_function ( f, & fun. to_string ( ) , * distinct , args, true ) ?;
31053126
31063127 if let Some ( nt) = null_treatment {
31073128 write ! ( f, "{nt}" ) ?;
0 commit comments