@@ -23,7 +23,9 @@ use datafusion_expr::Expr;
2323use regex:: Regex ;
2424use sqlparser:: tokenizer:: Span ;
2525use sqlparser:: {
26- ast:: { self , BinaryOperator , Function , Ident , ObjectName , TimezoneInfo } ,
26+ ast:: {
27+ self , BinaryOperator , Function , Ident , ObjectName , TimezoneInfo , WindowFrameBound ,
28+ } ,
2729 keywords:: ALL_KEYWORDS ,
2830} ;
2931
@@ -153,6 +155,18 @@ pub trait Dialect: Send + Sync {
153155 Ok ( None )
154156 }
155157
158+ /// Allows the dialect to choose to omit window frame in unparsing
159+ /// based on function name and window frame bound
160+ /// Returns false if specific function name / window frame bound indicates no window frame is needed in unparsing
161+ fn window_func_support_window_frame (
162+ & self ,
163+ _func_name : & str ,
164+ _start_bound : & WindowFrameBound ,
165+ _end_bound : & WindowFrameBound ,
166+ ) -> bool {
167+ true
168+ }
169+
156170 /// Extends the dialect's default rules for unparsing scalar functions.
157171 /// This is useful for supporting application-specific UDFs or custom engine extensions.
158172 fn with_custom_scalar_overrides (
@@ -500,6 +514,7 @@ pub struct CustomDialect {
500514 supports_column_alias_in_table_alias : bool ,
501515 requires_derived_table_alias : bool ,
502516 division_operator : BinaryOperator ,
517+ window_func_support_window_frame : bool ,
503518 full_qualified_col : bool ,
504519 unnest_as_table_factor : bool ,
505520}
@@ -527,6 +542,7 @@ impl Default for CustomDialect {
527542 supports_column_alias_in_table_alias : true ,
528543 requires_derived_table_alias : false ,
529544 division_operator : BinaryOperator :: Divide ,
545+ window_func_support_window_frame : true ,
530546 full_qualified_col : false ,
531547 unnest_as_table_factor : false ,
532548 }
@@ -634,6 +650,15 @@ impl Dialect for CustomDialect {
634650 self . division_operator . clone ( )
635651 }
636652
653+ fn window_func_support_window_frame (
654+ & self ,
655+ _func_name : & str ,
656+ _start_bound : & WindowFrameBound ,
657+ _end_bound : & WindowFrameBound ,
658+ ) -> bool {
659+ self . window_func_support_window_frame
660+ }
661+
637662 fn full_qualified_col ( & self ) -> bool {
638663 self . full_qualified_col
639664 }
@@ -675,6 +700,7 @@ pub struct CustomDialectBuilder {
675700 supports_column_alias_in_table_alias : bool ,
676701 requires_derived_table_alias : bool ,
677702 division_operator : BinaryOperator ,
703+ window_func_support_window_frame : bool ,
678704 full_qualified_col : bool ,
679705 unnest_as_table_factor : bool ,
680706}
@@ -708,6 +734,7 @@ impl CustomDialectBuilder {
708734 supports_column_alias_in_table_alias : true ,
709735 requires_derived_table_alias : false ,
710736 division_operator : BinaryOperator :: Divide ,
737+ window_func_support_window_frame : true ,
711738 full_qualified_col : false ,
712739 unnest_as_table_factor : false ,
713740 }
@@ -733,6 +760,7 @@ impl CustomDialectBuilder {
733760 . supports_column_alias_in_table_alias ,
734761 requires_derived_table_alias : self . requires_derived_table_alias ,
735762 division_operator : self . division_operator ,
763+ window_func_support_window_frame : self . window_func_support_window_frame ,
736764 full_qualified_col : self . full_qualified_col ,
737765 unnest_as_table_factor : self . unnest_as_table_factor ,
738766 }
@@ -857,6 +885,14 @@ impl CustomDialectBuilder {
857885 self
858886 }
859887
888+ pub fn with_window_func_support_window_frame (
889+ mut self ,
890+ window_func_support_window_frame : bool ,
891+ ) -> Self {
892+ self . window_func_support_window_frame = window_func_support_window_frame;
893+ self
894+ }
895+
860896 /// Customize the dialect to allow full qualified column names
861897 pub fn with_full_qualified_col ( mut self , full_qualified_col : bool ) -> Self {
862898 self . full_qualified_col = full_qualified_col;
0 commit comments