@@ -279,7 +279,7 @@ use sqlparser::ast::{
279
279
#[ derive( Clone , PartialEq , PartialOrd , Eq , Debug , Hash ) ]
280
280
pub enum Expr {
281
281
/// An expression with a specific name.
282
- Alias ( Alias ) ,
282
+ Alias ( Box < Alias > ) ,
283
283
/// A named reference to a qualified field in a schema.
284
284
Column ( Column ) ,
285
285
/// A named reference to a variable in a registry.
@@ -362,7 +362,7 @@ pub enum Expr {
362
362
Placeholder ( Placeholder ) ,
363
363
/// A placeholder which holds a reference to a qualified field
364
364
/// in the outer query, used for correlated sub queries.
365
- OuterReferenceColumn ( DataType , Column ) ,
365
+ OuterReferenceColumn ( Box < ( DataType , Column ) > ) ,
366
366
/// Unnest expression
367
367
Unnest ( Unnest ) ,
368
368
}
@@ -1421,7 +1421,9 @@ impl Expr {
1421
1421
name,
1422
1422
spans : _,
1423
1423
} ) => ( relation. clone ( ) , name. clone ( ) ) ,
1424
- Expr :: Alias ( Alias { relation, name, .. } ) => ( relation. clone ( ) , name. clone ( ) ) ,
1424
+ Expr :: Alias ( boxed_alias) => {
1425
+ ( boxed_alias. relation . clone ( ) , boxed_alias. name . clone ( ) )
1426
+ }
1425
1427
_ => ( None , self . schema_name ( ) . to_string ( ) ) ,
1426
1428
}
1427
1429
}
@@ -1443,7 +1445,7 @@ impl Expr {
1443
1445
Expr :: Case { .. } => "Case" ,
1444
1446
Expr :: Cast { .. } => "Cast" ,
1445
1447
Expr :: Column ( ..) => "Column" ,
1446
- Expr :: OuterReferenceColumn ( _, _ ) => "Outer" ,
1448
+ Expr :: OuterReferenceColumn ( _) => "Outer" ,
1447
1449
Expr :: Exists { .. } => "Exists" ,
1448
1450
Expr :: GroupingSet ( ..) => "GroupingSet" ,
1449
1451
Expr :: InList { .. } => "InList" ,
@@ -1569,7 +1571,7 @@ impl Expr {
1569
1571
1570
1572
/// Return `self AS name` alias expression
1571
1573
pub fn alias ( self , name : impl Into < String > ) -> Expr {
1572
- Expr :: Alias ( Alias :: new ( self , None :: < & str > , name. into ( ) ) )
1574
+ Expr :: Alias ( Box :: new ( Alias :: new ( self , None :: < & str > , name. into ( ) ) ) )
1573
1575
}
1574
1576
1575
1577
/// Return `self AS name` alias expression with metadata
@@ -1592,7 +1594,9 @@ impl Expr {
1592
1594
name : impl Into < String > ,
1593
1595
metadata : Option < FieldMetadata > ,
1594
1596
) -> Expr {
1595
- Expr :: Alias ( Alias :: new ( self , None :: < & str > , name. into ( ) ) . with_metadata ( metadata) )
1597
+ Expr :: Alias ( Box :: new (
1598
+ Alias :: new ( self , None :: < & str > , name. into ( ) ) . with_metadata ( metadata) ,
1599
+ ) )
1596
1600
}
1597
1601
1598
1602
/// Return `self AS name` alias expression with a specific qualifier
@@ -1601,7 +1605,7 @@ impl Expr {
1601
1605
relation : Option < impl Into < TableReference > > ,
1602
1606
name : impl Into < String > ,
1603
1607
) -> Expr {
1604
- Expr :: Alias ( Alias :: new ( self , relation, name. into ( ) ) )
1608
+ Expr :: Alias ( Box :: new ( Alias :: new ( self , relation, name. into ( ) ) ) )
1605
1609
}
1606
1610
1607
1611
/// Return `self AS name` alias expression with a specific qualifier and metadata
@@ -1625,7 +1629,9 @@ impl Expr {
1625
1629
name : impl Into < String > ,
1626
1630
metadata : Option < FieldMetadata > ,
1627
1631
) -> Expr {
1628
- Expr :: Alias ( Alias :: new ( self , relation, name. into ( ) ) . with_metadata ( metadata) )
1632
+ Expr :: Alias ( Box :: new (
1633
+ Alias :: new ( self , relation, name. into ( ) ) . with_metadata ( metadata) ,
1634
+ ) )
1629
1635
}
1630
1636
1631
1637
/// Remove an alias from an expression if one exists.
@@ -2018,7 +2024,7 @@ impl Expr {
2018
2024
| Expr :: SimilarTo ( ..)
2019
2025
| Expr :: Not ( ..)
2020
2026
| Expr :: Negative ( ..)
2021
- | Expr :: OuterReferenceColumn ( _, _ )
2027
+ | Expr :: OuterReferenceColumn ( _)
2022
2028
| Expr :: TryCast ( ..)
2023
2029
| Expr :: Unnest ( ..)
2024
2030
| Expr :: Wildcard { .. }
@@ -2106,23 +2112,10 @@ impl NormalizeEq for Expr {
2106
2112
&& self_right. normalize_eq ( other_right)
2107
2113
}
2108
2114
}
2109
- (
2110
- Expr :: Alias ( Alias {
2111
- expr : self_expr,
2112
- relation : self_relation,
2113
- name : self_name,
2114
- ..
2115
- } ) ,
2116
- Expr :: Alias ( Alias {
2117
- expr : other_expr,
2118
- relation : other_relation,
2119
- name : other_name,
2120
- ..
2121
- } ) ,
2122
- ) => {
2123
- self_name == other_name
2124
- && self_relation == other_relation
2125
- && self_expr. normalize_eq ( other_expr)
2115
+ ( Expr :: Alias ( boxed_alias) , Expr :: Alias ( boxed_other_alias) ) => {
2116
+ boxed_alias. name == boxed_other_alias. name
2117
+ && boxed_alias. relation == boxed_other_alias. relation
2118
+ && boxed_alias. expr . normalize_eq ( & * boxed_other_alias. expr )
2126
2119
}
2127
2120
(
2128
2121
Expr :: Like ( Like {
@@ -2453,14 +2446,9 @@ impl HashNode for Expr {
2453
2446
fn hash_node < H : Hasher > ( & self , state : & mut H ) {
2454
2447
mem:: discriminant ( self ) . hash ( state) ;
2455
2448
match self {
2456
- Expr :: Alias ( Alias {
2457
- expr : _expr,
2458
- relation,
2459
- name,
2460
- ..
2461
- } ) => {
2462
- relation. hash ( state) ;
2463
- name. hash ( state) ;
2449
+ Expr :: Alias ( boxed_alias) => {
2450
+ boxed_alias. relation . hash ( state) ;
2451
+ boxed_alias. name . hash ( state) ;
2464
2452
}
2465
2453
Expr :: Column ( column) => {
2466
2454
column. hash ( state) ;
@@ -2601,7 +2589,8 @@ impl HashNode for Expr {
2601
2589
Expr :: Placeholder ( place_holder) => {
2602
2590
place_holder. hash ( state) ;
2603
2591
}
2604
- Expr :: OuterReferenceColumn ( data_type, column) => {
2592
+ Expr :: OuterReferenceColumn ( boxed_orc) => {
2593
+ let ( data_type, column) = boxed_orc. as_ref ( ) ;
2605
2594
data_type. hash ( state) ;
2606
2595
column. hash ( state) ;
2607
2596
}
@@ -2665,12 +2654,14 @@ impl Display for SchemaDisplay<'_> {
2665
2654
}
2666
2655
}
2667
2656
// Expr is not shown since it is aliased
2668
- Expr :: Alias ( Alias {
2669
- name,
2670
- relation : Some ( relation) ,
2671
- ..
2672
- } ) => write ! ( f, "{relation}.{name}" ) ,
2673
- Expr :: Alias ( Alias { name, .. } ) => write ! ( f, "{name}" ) ,
2657
+ Expr :: Alias ( boxed_alias) => {
2658
+ let alias = boxed_alias. as_ref ( ) ;
2659
+ if let Some ( relation) = & alias. relation {
2660
+ write ! ( f, "{relation}.{}" , alias. name)
2661
+ } else {
2662
+ write ! ( f, "{}" , alias. name)
2663
+ }
2664
+ }
2674
2665
Expr :: Between ( Between {
2675
2666
expr,
2676
2667
negated,
@@ -2909,7 +2900,10 @@ impl Display for SqlDisplay<'_> {
2909
2900
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
2910
2901
match self . 0 {
2911
2902
Expr :: Literal ( scalar, _) => scalar. fmt ( f) ,
2912
- Expr :: Alias ( Alias { name, .. } ) => write ! ( f, "{name}" ) ,
2903
+ Expr :: Alias ( boxed_alias) => {
2904
+ let name = & boxed_alias. as_ref ( ) . name ;
2905
+ write ! ( f, "{name}" )
2906
+ }
2913
2907
Expr :: Between ( Between {
2914
2908
expr,
2915
2909
negated,
@@ -3169,9 +3163,13 @@ pub const UNNEST_COLUMN_PREFIX: &str = "UNNEST";
3169
3163
impl Display for Expr {
3170
3164
fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
3171
3165
match self {
3172
- Expr :: Alias ( Alias { expr, name, .. } ) => write ! ( f, "{expr} AS {name}" ) ,
3166
+ Expr :: Alias ( boxed_alias) => {
3167
+ let Alias { expr, name, .. } = boxed_alias. as_ref ( ) ;
3168
+ write ! ( f, "{expr} AS {name}" )
3169
+ }
3173
3170
Expr :: Column ( c) => write ! ( f, "{c}" ) ,
3174
- Expr :: OuterReferenceColumn ( _, c) => {
3171
+ Expr :: OuterReferenceColumn ( boxed_orc) => {
3172
+ let ( _, c) = boxed_orc. as_ref ( ) ;
3175
3173
write ! ( f, "{OUTER_REFERENCE_COLUMN_PREFIX}({c})" )
3176
3174
}
3177
3175
Expr :: ScalarVariable ( _, var_names) => write ! ( f, "{}" , var_names. join( "." ) ) ,
@@ -3818,7 +3816,7 @@ mod test {
3818
3816
// If this test fails when you change `Expr`, please try
3819
3817
// `Box`ing the fields to make `Expr` smaller
3820
3818
// See https://github.com/apache/datafusion/issues/16199 for details
3821
- assert_eq ! ( size_of:: <Expr >( ) , 128 ) ;
3819
+ assert_eq ! ( size_of:: <Expr >( ) , 112 ) ;
3822
3820
assert_eq ! ( size_of:: <ScalarValue >( ) , 64 ) ;
3823
3821
assert_eq ! ( size_of:: <DataType >( ) , 24 ) ; // 3 ptrs
3824
3822
assert_eq ! ( size_of:: <Vec <Expr >>( ) , 24 ) ;
0 commit comments