|
19 | 19 |
|
20 | 20 | use std::cmp::Ordering;
|
21 | 21 | use std::collections::{BTreeMap, HashSet};
|
22 |
| -use std::fmt::{self, Display, Formatter, Write}; |
| 22 | +use std::fmt::{self, Debug, Display, Formatter, Write}; |
23 | 23 | use std::hash::{Hash, Hasher};
|
24 | 24 | use std::mem;
|
25 | 25 | use std::sync::Arc;
|
@@ -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<OuterReference>), |
366 | 366 | /// Unnest expression
|
367 | 367 | Unnest(Unnest),
|
368 | 368 | }
|
@@ -413,6 +413,18 @@ impl<'a> TreeNodeContainer<'a, Self> for Expr {
|
413 | 413 | }
|
414 | 414 | }
|
415 | 415 |
|
| 416 | +#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] |
| 417 | +pub struct OuterReference { |
| 418 | + pub data_type: DataType, |
| 419 | + pub column: Column, |
| 420 | +} |
| 421 | + |
| 422 | +impl Debug for OuterReference { |
| 423 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 424 | + write!(f, "{:?}, {:?}", self.data_type, self.column) |
| 425 | + } |
| 426 | +} |
| 427 | + |
416 | 428 | /// Literal metadata
|
417 | 429 | ///
|
418 | 430 | /// Stores metadata associated with a literal expressions
|
@@ -1443,7 +1455,7 @@ impl Expr {
|
1443 | 1455 | Expr::Case { .. } => "Case",
|
1444 | 1456 | Expr::Cast { .. } => "Cast",
|
1445 | 1457 | Expr::Column(..) => "Column",
|
1446 |
| - Expr::OuterReferenceColumn(_, _) => "Outer", |
| 1458 | + Expr::OuterReferenceColumn(_) => "Outer", |
1447 | 1459 | Expr::Exists { .. } => "Exists",
|
1448 | 1460 | Expr::GroupingSet(..) => "GroupingSet",
|
1449 | 1461 | Expr::InList { .. } => "InList",
|
@@ -2018,7 +2030,7 @@ impl Expr {
|
2018 | 2030 | | Expr::SimilarTo(..)
|
2019 | 2031 | | Expr::Not(..)
|
2020 | 2032 | | Expr::Negative(..)
|
2021 |
| - | Expr::OuterReferenceColumn(_, _) |
| 2033 | + | Expr::OuterReferenceColumn(_) |
2022 | 2034 | | Expr::TryCast(..)
|
2023 | 2035 | | Expr::Unnest(..)
|
2024 | 2036 | | Expr::Wildcard { .. }
|
@@ -2601,9 +2613,9 @@ impl HashNode for Expr {
|
2601 | 2613 | Expr::Placeholder(place_holder) => {
|
2602 | 2614 | place_holder.hash(state);
|
2603 | 2615 | }
|
2604 |
| - Expr::OuterReferenceColumn(data_type, column) => { |
2605 |
| - data_type.hash(state); |
2606 |
| - column.hash(state); |
| 2616 | + Expr::OuterReferenceColumn(boxed_orc) => { |
| 2617 | + boxed_orc.data_type.hash(state); |
| 2618 | + boxed_orc.column.hash(state); |
2607 | 2619 | }
|
2608 | 2620 | Expr::Unnest(Unnest { expr: _expr }) => {}
|
2609 | 2621 | };
|
@@ -2908,7 +2920,7 @@ struct SqlDisplay<'a>(&'a Expr);
|
2908 | 2920 | impl Display for SqlDisplay<'_> {
|
2909 | 2921 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
2910 | 2922 | match self.0 {
|
2911 |
| - Expr::Literal(scalar, _) => scalar.fmt(f), |
| 2923 | + Expr::Literal(scalar, _) => Display::fmt(&scalar, f), |
2912 | 2924 | Expr::Alias(Alias { name, .. }) => write!(f, "{name}"),
|
2913 | 2925 | Expr::Between(Between {
|
2914 | 2926 | expr,
|
@@ -3171,7 +3183,8 @@ impl Display for Expr {
|
3171 | 3183 | match self {
|
3172 | 3184 | Expr::Alias(Alias { expr, name, .. }) => write!(f, "{expr} AS {name}"),
|
3173 | 3185 | Expr::Column(c) => write!(f, "{c}"),
|
3174 |
| - Expr::OuterReferenceColumn(_, c) => { |
| 3186 | + Expr::OuterReferenceColumn(boxed_orc) => { |
| 3187 | + let c = &boxed_orc.column; |
3175 | 3188 | write!(f, "{OUTER_REFERENCE_COLUMN_PREFIX}({c})")
|
3176 | 3189 | }
|
3177 | 3190 | Expr::ScalarVariable(_, var_names) => write!(f, "{}", var_names.join(".")),
|
@@ -3818,7 +3831,7 @@ mod test {
|
3818 | 3831 | // If this test fails when you change `Expr`, please try
|
3819 | 3832 | // `Box`ing the fields to make `Expr` smaller
|
3820 | 3833 | // See https://github.com/apache/datafusion/issues/16199 for details
|
3821 |
| - assert_eq!(size_of::<Expr>(), 128); |
| 3834 | + assert_eq!(size_of::<Expr>(), 112); |
3822 | 3835 | assert_eq!(size_of::<ScalarValue>(), 64);
|
3823 | 3836 | assert_eq!(size_of::<DataType>(), 24); // 3 ptrs
|
3824 | 3837 | assert_eq!(size_of::<Vec<Expr>>(), 24);
|
|
0 commit comments