@@ -297,7 +297,7 @@ pub enum Expr {
297297 /// [`ExprFunctionExt`]: crate::expr_fn::ExprFunctionExt
298298 AggregateFunction ( AggregateFunction ) ,
299299 /// Represents the call of a window function with arguments.
300- WindowFunction ( WindowFunction ) ,
300+ WindowFunction ( Box < WindowFunction > ) , // Boxed as it is large (272 bytes)
301301 /// Returns whether the list contains the expr value.
302302 InList ( InList ) ,
303303 /// EXISTS subquery
@@ -341,6 +341,13 @@ impl From<Column> for Expr {
341341 }
342342}
343343
344+ /// Create an [`Expr`] from a [`WindowFunction`]
345+ impl From < WindowFunction > for Expr {
346+ fn from ( value : WindowFunction ) -> Self {
347+ Expr :: WindowFunction ( Box :: new ( value) )
348+ }
349+ }
350+
344351/// Create an [`Expr`] from an optional qualifier and a [`FieldRef`]. This is
345352/// useful for creating [`Expr`] from a [`DFSchema`].
346353///
@@ -1893,24 +1900,24 @@ impl NormalizeEq for Expr {
18931900 _ => false ,
18941901 }
18951902 }
1896- (
1897- Expr :: WindowFunction ( WindowFunction {
1903+ ( Expr :: WindowFunction ( left ) , Expr :: WindowFunction ( right ) ) => {
1904+ let WindowFunction {
18981905 fun : self_fun,
18991906 args : self_args,
19001907 partition_by : self_partition_by,
19011908 order_by : self_order_by,
19021909 window_frame : self_window_frame,
19031910 null_treatment : self_null_treatment,
1904- } ) ,
1905- Expr :: WindowFunction ( WindowFunction {
1911+ } = left . as_ref ( ) ;
1912+ let WindowFunction {
19061913 fun : other_fun,
19071914 args : other_args,
19081915 partition_by : other_partition_by,
19091916 order_by : other_order_by,
19101917 window_frame : other_window_frame,
19111918 null_treatment : other_null_treatment,
1912- } ) ,
1913- ) => {
1919+ } = right . as_ref ( ) ;
1920+
19141921 self_fun. name ( ) == other_fun. name ( )
19151922 && self_window_frame == other_window_frame
19161923 && self_null_treatment == other_null_treatment
@@ -2150,14 +2157,15 @@ impl HashNode for Expr {
21502157 distinct. hash ( state) ;
21512158 null_treatment. hash ( state) ;
21522159 }
2153- Expr :: WindowFunction ( WindowFunction {
2154- fun,
2155- args : _args,
2156- partition_by : _partition_by,
2157- order_by : _order_by,
2158- window_frame,
2159- null_treatment,
2160- } ) => {
2160+ Expr :: WindowFunction ( window_func) => {
2161+ let WindowFunction {
2162+ fun,
2163+ args : _args,
2164+ partition_by : _partition_by,
2165+ order_by : _order_by,
2166+ window_frame,
2167+ null_treatment,
2168+ } = window_func. as_ref ( ) ;
21612169 fun. hash ( state) ;
21622170 window_frame. hash ( state) ;
21632171 null_treatment. hash ( state) ;
@@ -2458,14 +2466,15 @@ impl Display for SchemaDisplay<'_> {
24582466
24592467 Ok ( ( ) )
24602468 }
2461- Expr :: WindowFunction ( WindowFunction {
2462- fun,
2463- args,
2464- partition_by,
2465- order_by,
2466- window_frame,
2467- null_treatment,
2468- } ) => {
2469+ Expr :: WindowFunction ( window_func) => {
2470+ let WindowFunction {
2471+ fun,
2472+ args,
2473+ partition_by,
2474+ order_by,
2475+ window_frame,
2476+ null_treatment,
2477+ } = window_func. as_ref ( ) ;
24692478 write ! (
24702479 f,
24712480 "{}({})" ,
@@ -2612,14 +2621,16 @@ impl Display for Expr {
26122621 // Expr::ScalarFunction(ScalarFunction { func, args }) => {
26132622 // write!(f, "{}", func.display_name(args).unwrap())
26142623 // }
2615- Expr :: WindowFunction ( WindowFunction {
2616- fun,
2617- args,
2618- partition_by,
2619- order_by,
2620- window_frame,
2621- null_treatment,
2622- } ) => {
2624+ Expr :: WindowFunction ( window_func) => {
2625+ let WindowFunction {
2626+ fun,
2627+ args,
2628+ partition_by,
2629+ order_by,
2630+ window_frame,
2631+ null_treatment,
2632+ } = window_func. as_ref ( ) ;
2633+
26232634 fmt_function ( f, & fun. to_string ( ) , false , args, true ) ?;
26242635
26252636 if let Some ( nt) = null_treatment {
@@ -3076,6 +3087,10 @@ mod test {
30763087 // If this test fails when you change `Expr`, please try
30773088 // `Box`ing the fields to make `Expr` smaller
30783089 // See https://github.com/apache/datafusion/issues/14256 for details
3079- assert_eq ! ( size_of:: <Expr >( ) , 272 ) ;
3090+ assert_eq ! ( size_of:: <Expr >( ) , 112 ) ;
3091+ assert_eq ! ( size_of:: <ScalarValue >( ) , 64 ) ;
3092+ assert_eq ! ( size_of:: <DataType >( ) , 24 ) ; // 3 ptrs
3093+ assert_eq ! ( size_of:: <Vec <Expr >>( ) , 24 ) ;
3094+ assert_eq ! ( size_of:: <Arc <Expr >>( ) , 8 ) ;
30803095 }
30813096}
0 commit comments