Skip to content

Commit e3a7cd1

Browse files
committed
Remove GetField usage (see apache#628)
1 parent 850de73 commit e3a7cd1

File tree

11 files changed

+18
-255
lines changed

11 files changed

+18
-255
lines changed

datafusion/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ pub mod physical_plan;
225225
pub mod prelude;
226226
pub mod scalar;
227227
pub mod sql;
228-
mod utils;
229228
pub mod variable;
230229

231230
// re-export dependencies from arrow-rs to minimise version maintenance for crate users

datafusion/src/logical_plan/dfschema.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::sync::Arc;
2525
use crate::error::{DataFusionError, Result};
2626
use crate::logical_plan::Column;
2727

28-
use crate::utils::get_field;
2928
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
3029
use std::fmt::{Display, Formatter};
3130

@@ -161,11 +160,7 @@ impl DFSchema {
161160
// field to lookup is qualified.
162161
// current field is qualified and not shared between relations, compare both
163162
// qualifer and name.
164-
(Some(q), Some(field_q)) => {
165-
(q == field_q && field.name() == name)
166-
|| (q == field.name()
167-
&& get_field(field.field.data_type(), name).is_ok())
168-
}
163+
(Some(q), Some(field_q)) => q == field_q && field.name() == name,
169164
// field to lookup is qualified but current field is unqualified.
170165
(Some(_), None) => false,
171166
// field to lookup is unqualified, no need to compare qualifier

datafusion/src/logical_plan/expr.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::physical_plan::{
2525
aggregates, expressions::binary_operator_data_type, functions, udf::ScalarUDF,
2626
window_functions,
2727
};
28-
use crate::utils::get_field;
2928
use crate::{physical_plan::udaf::AggregateUDF, scalar::ScalarValue};
3029
use aggregates::{AccumulatorFunctionImplementation, StateTypeFunction};
3130
use arrow::{compute::can_cast_types, datatypes::DataType};
@@ -245,13 +244,6 @@ pub enum Expr {
245244
IsNull(Box<Expr>),
246245
/// arithmetic negation of an expression, the operand must be of a signed numeric data type
247246
Negative(Box<Expr>),
248-
/// Returns the field of a [`StructArray`] by name
249-
GetField {
250-
/// the expression to take the field from
251-
expr: Box<Expr>,
252-
/// The name of the field to take
253-
name: String,
254-
},
255247
/// Whether an expression is between a given range.
256248
Between {
257249
/// The value to compare
@@ -440,10 +432,6 @@ impl Expr {
440432
Expr::Wildcard => Err(DataFusionError::Internal(
441433
"Wildcard expressions are not valid in a logical query plan".to_owned(),
442434
)),
443-
Expr::GetField { ref expr, name } => {
444-
let data_type = expr.get_type(schema)?;
445-
get_field(&data_type, name).map(|x| x.data_type().clone())
446-
}
447435
}
448436
}
449437

@@ -499,10 +487,6 @@ impl Expr {
499487
Expr::Wildcard => Err(DataFusionError::Internal(
500488
"Wildcard expressions are not valid in a logical query plan".to_owned(),
501489
)),
502-
Expr::GetField { ref expr, name } => {
503-
let data_type = expr.get_type(input_schema)?;
504-
get_field(&data_type, name).map(|x| x.is_nullable())
505-
}
506490
}
507491
}
508492

@@ -643,14 +627,6 @@ impl Expr {
643627
Expr::IsNotNull(Box::new(self))
644628
}
645629

646-
/// Returns the values of the field `name` from an expression returning a `Struct`
647-
pub fn get_field<I: Into<String>>(self, name: I) -> Expr {
648-
Expr::GetField {
649-
expr: Box::new(self),
650-
name: name.into(),
651-
}
652-
}
653-
654630
/// Create a sort expression from an existing expression.
655631
///
656632
/// ```
@@ -786,7 +762,6 @@ impl Expr {
786762
.try_fold(visitor, |visitor, arg| arg.accept(visitor))
787763
}
788764
Expr::Wildcard => Ok(visitor),
789-
Expr::GetField { ref expr, .. } => expr.accept(visitor),
790765
}?;
791766

792767
visitor.post_visit(self)
@@ -944,10 +919,6 @@ impl Expr {
944919
negated,
945920
},
946921
Expr::Wildcard => Expr::Wildcard,
947-
Expr::GetField { expr, name } => Expr::GetField {
948-
expr: rewrite_boxed(expr, rewriter)?,
949-
name,
950-
},
951922
};
952923

953924
// now rewrite this expression itself
@@ -1709,7 +1680,6 @@ impl fmt::Debug for Expr {
17091680
}
17101681
}
17111682
Expr::Wildcard => write!(f, "*"),
1712-
Expr::GetField { ref expr, name } => write!(f, "({:?}).{}", expr, name),
17131683
}
17141684
}
17151685
}
@@ -1786,10 +1756,6 @@ fn create_name(e: &Expr, input_schema: &DFSchema) -> Result<String> {
17861756
let expr = create_name(expr, input_schema)?;
17871757
Ok(format!("{} IS NOT NULL", expr))
17881758
}
1789-
Expr::GetField { expr, name } => {
1790-
let expr = create_name(expr, input_schema)?;
1791-
Ok(format!("{}.{}", expr, name))
1792-
}
17931759
Expr::ScalarFunction { fun, args, .. } => {
17941760
create_function_name(&fun.to_string(), false, args, input_schema)
17951761
}
@@ -1911,12 +1877,6 @@ mod tests {
19111877
);
19121878
}
19131879

1914-
#[test]
1915-
fn display_get_field() {
1916-
let col_null = col("col1").get_field("name");
1917-
assert_eq!(format!("{:?}", col_null), "(#col1).name");
1918-
}
1919-
19201880
#[derive(Default)]
19211881
struct RecordingRewriter {
19221882
v: Vec<String>,

datafusion/src/optimizer/utils.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ impl ExpressionVisitor for ColumnNameVisitor<'_> {
7979
Expr::AggregateUDF { .. } => {}
8080
Expr::InList { .. } => {}
8181
Expr::Wildcard => {}
82-
Expr::GetField { .. } => {}
8382
}
8483
Ok(Recursion::Continue(self))
8584
}
@@ -288,7 +287,6 @@ pub fn expr_sub_expressions(expr: &Expr) -> Result<Vec<Expr>> {
288287
Expr::Wildcard { .. } => Err(DataFusionError::Internal(
289288
"Wildcard expressions are not valid in a logical query plan".to_owned(),
290289
)),
291-
Expr::GetField { expr, .. } => Ok(vec![expr.as_ref().to_owned()]),
292290
}
293291
}
294292

@@ -304,10 +302,6 @@ pub fn rewrite_expression(expr: &Expr, expressions: &[Expr]) -> Result<Expr> {
304302
}),
305303
Expr::IsNull(_) => Ok(Expr::IsNull(Box::new(expressions[0].clone()))),
306304
Expr::IsNotNull(_) => Ok(Expr::IsNotNull(Box::new(expressions[0].clone()))),
307-
Expr::GetField { expr: _, name } => Ok(Expr::GetField {
308-
expr: Box::new(expressions[0].clone()),
309-
name: name.clone(),
310-
}),
311305
Expr::ScalarFunction { fun, .. } => Ok(Expr::ScalarFunction {
312306
fun: fun.clone(),
313307
args: expressions.to_vec(),

datafusion/src/physical_plan/expressions/get_field.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

datafusion/src/physical_plan/expressions/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ mod cast;
3333
mod coercion;
3434
mod column;
3535
mod count;
36-
mod get_field;
3736
mod in_list;
3837
mod is_not_null;
3938
mod is_null;
@@ -57,7 +56,6 @@ pub use cast::{
5756
};
5857
pub use column::{col, Column};
5958
pub use count::Count;
60-
pub use get_field::{get_field, GetFieldExpr};
6159
pub use in_list::{in_list, InListExpr};
6260
pub use is_not_null::{is_not_null, IsNotNullExpr};
6361
pub use is_null::{is_null, IsNullExpr};

datafusion/src/physical_plan/planner.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ fn physical_name(e: &Expr, input_schema: &DFSchema) -> Result<String> {
129129
let expr = physical_name(expr, input_schema)?;
130130
Ok(format!("{} IS NOT NULL", expr))
131131
}
132-
Expr::GetField { expr, name } => {
133-
let expr = physical_name(expr, input_schema)?;
134-
Ok(format!("{}.{}", expr, name))
135-
}
136132
Expr::ScalarFunction { fun, args, .. } => {
137133
create_function_physical_name(&fun.to_string(), false, args, input_schema)
138134
}
@@ -947,10 +943,6 @@ impl DefaultPhysicalPlanner {
947943
Expr::IsNotNull(expr) => expressions::is_not_null(
948944
self.create_physical_expr(expr, input_dfschema, input_schema, ctx_state)?,
949945
),
950-
Expr::GetField { expr, name } => expressions::get_field(
951-
self.create_physical_expr(expr, input_dfschema, input_schema, ctx_state)?,
952-
name.clone(),
953-
),
954946
Expr::ScalarFunction { fun, args } => {
955947
let physical_args = args
956948
.iter()

datafusion/src/sql/planner.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,6 @@ pub struct SqlToRel<'a, S: ContextProvider> {
8181
schema_provider: &'a S,
8282
}
8383

84-
fn plan_compound(mut identifiers: Vec<String>) -> Expr {
85-
if &identifiers[0][0..1] == "@" {
86-
Expr::ScalarVariable(identifiers)
87-
} else if identifiers.len() == 2 {
88-
// "table.column"
89-
let name = identifiers.pop().unwrap();
90-
let relation = Some(identifiers.pop().unwrap());
91-
Expr::Column(Column { relation, name })
92-
} else {
93-
// "table.column.field..."
94-
let name = identifiers.pop().unwrap();
95-
let expr = Box::new(plan_compound(identifiers));
96-
Expr::GetField { expr, name }
97-
}
98-
}
99-
10084
impl<'a, S: ContextProvider> SqlToRel<'a, S> {
10185
/// Create a new query planner
10286
pub fn new(schema_provider: &'a S) -> Self {
@@ -1110,8 +1094,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
11101094
}
11111095

11121096
SQLExpr::CompoundIdentifier(ids) => {
1113-
let var_names = ids.iter().map(|x| x.value.clone()).collect::<Vec<_>>();
1114-
Ok(plan_compound(var_names))
1097+
let mut var_names = vec![];
1098+
for id in ids {
1099+
var_names.push(id.value.clone());
1100+
}
1101+
if &var_names[0][0..1] == "@" {
1102+
Ok(Expr::ScalarVariable(var_names))
1103+
} else if var_names.len() == 2 {
1104+
// table.column identifier
1105+
let name = var_names.pop().unwrap();
1106+
let relation = Some(var_names.pop().unwrap());
1107+
Ok(Expr::Column(Column { relation, name }))
1108+
} else {
1109+
Err(DataFusionError::NotImplemented(format!(
1110+
"Unsupported compound identifier '{:?}'",
1111+
var_names,
1112+
)))
1113+
}
11151114
}
11161115

11171116
SQLExpr::Wildcard => Ok(Expr::Wildcard),

datafusion/src/sql/utils.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,6 @@ where
368368
Ok(expr.clone())
369369
}
370370
Expr::Wildcard => Ok(Expr::Wildcard),
371-
Expr::GetField { expr, name } => Ok(Expr::GetField {
372-
expr: Box::new(clone_with_replacement(expr.as_ref(), replacement_fn)?),
373-
name: name.clone(),
374-
}),
375371
},
376372
}
377373
}

0 commit comments

Comments
 (0)