Skip to content

Commit 4c1bfe2

Browse files
committed
add new changes
1 parent aab44fd commit 4c1bfe2

File tree

15 files changed

+52
-46
lines changed

15 files changed

+52
-46
lines changed

datafusion/common/src/column.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::str::FromStr;
3030
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
3131
pub struct Column {
3232
/// relation/table reference.
33-
pub relation: Option<TableReference>,
33+
pub relation: Box<Option<TableReference>>,
3434
/// field/column name.
3535
pub name: String,
3636
/// Original source code location, if known
@@ -58,7 +58,7 @@ impl Column {
5858
name: impl Into<String>,
5959
) -> Self {
6060
Self {
61-
relation: relation.map(|r| r.into()),
61+
relation: Box::new(relation.map(|r| r.into())),
6262
name: name.into(),
6363
spans: Spans::new(),
6464
}
@@ -67,7 +67,7 @@ impl Column {
6767
/// Convenience method for when there is no qualifier
6868
pub fn new_unqualified(name: impl Into<String>) -> Self {
6969
Self {
70-
relation: None,
70+
relation: Box::new(None),
7171
name: name.into(),
7272
spans: Spans::new(),
7373
}
@@ -78,7 +78,7 @@ impl Column {
7878
/// Alias for `Column::new_unqualified`
7979
pub fn from_name(name: impl Into<String>) -> Self {
8080
Self {
81-
relation: None,
81+
relation: Box::new(None),
8282
name: name.into(),
8383
spans: Spans::new(),
8484
}
@@ -116,6 +116,8 @@ impl Column {
116116
// identifiers will be treated as an unqualified column name
117117
_ => return None,
118118
};
119+
120+
let relation = Box::new(relation);
119121
Some(Self {
120122
relation,
121123
name,
@@ -132,7 +134,7 @@ impl Column {
132134
let flat_name = flat_name.into();
133135
Self::from_idents(parse_identifiers_normalized(&flat_name, false)).unwrap_or_else(
134136
|| Self {
135-
relation: None,
137+
relation: Box::new(None),
136138
name: flat_name,
137139
spans: Spans::new(),
138140
},
@@ -144,7 +146,7 @@ impl Column {
144146
let flat_name = flat_name.into();
145147
Self::from_idents(parse_identifiers_normalized(&flat_name, true)).unwrap_or_else(
146148
|| Self {
147-
relation: None,
149+
relation: Box::new(None),
148150
name: flat_name,
149151
spans: Spans::new(),
150152
},
@@ -160,15 +162,15 @@ impl Column {
160162

161163
/// Serialize column into a flat name string
162164
pub fn flat_name(&self) -> String {
163-
match &self.relation {
165+
match &*self.relation {
164166
Some(r) => format!("{}.{}", r, self.name),
165167
None => self.name.clone(),
166168
}
167169
}
168170

169171
/// Serialize column into a quoted flat name string
170172
pub fn quoted_flat_name(&self) -> String {
171-
match &self.relation {
173+
match &*self.relation {
172174
Some(r) => {
173175
format!(
174176
"{}.{}",
@@ -316,7 +318,7 @@ impl Column {
316318
/// Qualifies the column with the given table reference.
317319
pub fn with_relation(&self, relation: TableReference) -> Self {
318320
Self {
319-
relation: Some(relation),
321+
relation: Box::new(Some(relation)),
320322
..self.clone()
321323
}
322324
}

datafusion/common/src/dfschema.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl DFSchema {
379379
/// See [Self::index_of_column] for a version that returns an error if the
380380
/// column is not found
381381
pub fn maybe_index_of_column(&self, col: &Column) -> Option<usize> {
382-
self.index_of_column_by_name(col.relation.as_ref(), &col.name)
382+
self.index_of_column_by_name(col.relation.as_ref().as_ref(), &col.name)
383383
}
384384

385385
/// Find the index of the column with the given qualifier and name,
@@ -388,13 +388,14 @@ impl DFSchema {
388388
/// See [Self::maybe_index_of_column] for a version that returns `None` if
389389
/// the column is not found
390390
pub fn index_of_column(&self, col: &Column) -> Result<usize> {
391-
self.maybe_index_of_column(col)
392-
.ok_or_else(|| field_not_found(col.relation.clone(), &col.name, self))
391+
self.maybe_index_of_column(col).ok_or_else(|| {
392+
field_not_found(col.relation.as_ref().clone(), &col.name, self)
393+
})
393394
}
394395

395396
/// Check if the column is in the current schema
396397
pub fn is_column_from_schema(&self, col: &Column) -> bool {
397-
self.index_of_column_by_name(col.relation.as_ref(), &col.name)
398+
self.index_of_column_by_name(col.relation.as_ref().as_ref(), &col.name)
398399
.is_some()
399400
}
400401

@@ -539,7 +540,7 @@ impl DFSchema {
539540
&self,
540541
column: &Column,
541542
) -> Result<(Option<&TableReference>, &Field)> {
542-
self.qualified_field_with_name(column.relation.as_ref(), &column.name)
543+
self.qualified_field_with_name(column.relation.as_ref().as_ref(), &column.name)
543544
}
544545

545546
/// Find if the field exists with the given name
@@ -559,7 +560,7 @@ impl DFSchema {
559560

560561
/// Find if the field exists with the given qualified column
561562
pub fn has_column(&self, column: &Column) -> bool {
562-
match &column.relation {
563+
match &*column.relation {
563564
Some(r) => self.has_column_with_qualified_name(r, &column.name),
564565
None => self.has_column_with_unqualified_name(&column.name),
565566
}
@@ -1029,7 +1030,7 @@ impl<P: AsRef<DFSchema> + std::fmt::Debug> ExprSchema for P {
10291030

10301031
impl ExprSchema for DFSchema {
10311032
fn field_from_column(&self, col: &Column) -> Result<&Field> {
1032-
match &col.relation {
1033+
match &*col.relation {
10331034
Some(r) => self.field_with_qualified_name(r, &col.name),
10341035
None => self.field_with_unqualified_name(&col.name),
10351036
}

datafusion/core/src/dataframe/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ impl DataFrame {
22962296
func: coalesce(),
22972297
args: vec![col(field.name()), lit(fill_value)],
22982298
})),
2299-
relation: None,
2299+
relation: Box::new(None),
23002300
name: field.name().to_string(),
23012301
metadata: None,
23022302
}),

datafusion/core/tests/dataframe/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5668,7 +5668,7 @@ async fn test_alias() -> Result<()> {
56685668
.alias("table_alias")?;
56695669
// All ouput column qualifiers are changed to "table_alias"
56705670
df.schema().columns().iter().for_each(|c| {
5671-
assert_eq!(c.relation, Some("table_alias".into()));
5671+
assert_eq!(*c.relation, Some("table_alias".into()));
56725672
});
56735673

56745674
let plan = df

datafusion/core/tests/execution/logical_plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn count_only_nulls() -> Result<()> {
5353
],
5454
}));
5555
let input_col_ref = Expr::Column(Column {
56-
relation: None,
56+
relation: Box::new(None),
5757
name: "col".to_string(),
5858
spans: Spans::new(),
5959
});

datafusion/expr/src/expr.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl Unnest {
623623
#[derive(Clone, PartialEq, Eq, Debug)]
624624
pub struct Alias {
625625
pub expr: Box<Expr>,
626-
pub relation: Option<TableReference>,
626+
pub relation: Box<Option<TableReference>>,
627627
pub name: String,
628628
pub metadata: Option<FieldMetadata>,
629629
}
@@ -659,7 +659,7 @@ impl Alias {
659659
) -> Self {
660660
Self {
661661
expr: Box::new(expr),
662-
relation: relation.map(|r| r.into()),
662+
relation: Box::new(relation.map(|r| r.into())),
663663
name: name.into(),
664664
metadata: None,
665665
}
@@ -1423,8 +1423,10 @@ impl Expr {
14231423
relation,
14241424
name,
14251425
spans: _,
1426-
}) => (relation.clone(), name.clone()),
1427-
Expr::Alias(Alias { relation, name, .. }) => (relation.clone(), name.clone()),
1426+
}) => (relation.as_ref().clone(), name.clone()),
1427+
Expr::Alias(Alias { relation, name, .. }) => {
1428+
(*relation.clone(), name.clone())
1429+
}
14281430
_ => (None, self.schema_name().to_string()),
14291431
}
14301432
}
@@ -2673,12 +2675,10 @@ impl Display for SchemaDisplay<'_> {
26732675
}
26742676
}
26752677
// Expr is not shown since it is aliased
2676-
Expr::Alias(Alias {
2677-
name,
2678-
relation: Some(relation),
2679-
..
2680-
}) => write!(f, "{relation}.{name}"),
2681-
Expr::Alias(Alias { name, .. }) => write!(f, "{name}"),
2678+
Expr::Alias(Alias { name, relation, .. }) => match relation.as_ref() {
2679+
Some(rel) => write!(f, "{rel}.{name}"),
2680+
None => write!(f, "{name}"),
2681+
},
26822682
Expr::Between(Between {
26832683
expr,
26842684
negated,
@@ -3839,7 +3839,7 @@ mod test {
38393839
// If this test fails when you change `Expr`, please try
38403840
// `Box`ing the fields to make `Expr` smaller
38413841
// See https://github.com/apache/datafusion/issues/16199 for details
3842-
assert_eq!(size_of::<Expr>(), 128);
3842+
assert_eq!(size_of::<Expr>(), 96);
38433843
assert_eq!(size_of::<ScalarValue>(), 64);
38443844
assert_eq!(size_of::<DataType>(), 24); // 3 ptrs
38453845
assert_eq!(size_of::<Vec<Expr>>(), 24);

datafusion/expr/src/logical_plan/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ impl LogicalPlanBuilder {
10211021
let l = l.into();
10221022
let r = r.into();
10231023

1024-
match (&l.relation, &r.relation) {
1024+
match (&*l.relation, &*r.relation) {
10251025
(Some(lr), Some(rr)) => {
10261026
let l_is_left =
10271027
self.plan.schema().field_with_qualified_name(lr, &l.name);
@@ -2388,7 +2388,7 @@ mod tests {
23882388
name,
23892389
spans: _,
23902390
} = *field;
2391-
let Some(TableReference::Bare { table }) = relation else {
2391+
let Some(TableReference::Bare { table }) = *relation else {
23922392
return plan_err!(
23932393
"wrong relation: {relation:?}, expected table name"
23942394
);

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,7 @@ impl Unnest {
41634163
Ok(transformed_columns
41644164
.iter()
41654165
.map(|(col, field)| {
4166-
(col.relation.to_owned(), field.to_owned())
4166+
(col.relation.as_ref().to_owned(), field.to_owned())
41674167
})
41684168
.collect())
41694169
}

datafusion/expr/src/tree_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl TreeNode for Expr {
136136
name,
137137
metadata,
138138
}) => f(*expr)?.update_data(|e| {
139-
e.alias_qualified_with_metadata(relation, name, metadata)
139+
e.alias_qualified_with_metadata(*relation, name, metadata)
140140
}),
141141
Expr::InSubquery(InSubquery {
142142
expr,

datafusion/optimizer/src/analyzer/resolve_grouping_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn replace_grouping_exprs(
105105
)?;
106106
projection_exprs.push(Expr::Alias(Alias::new(
107107
grouping_expr,
108-
column.relation,
108+
*column.relation,
109109
column.name,
110110
)));
111111
}

0 commit comments

Comments
 (0)