Skip to content

Apache DataFusion SQL Query Engine

Avoid redundant pass-by-value in optimizer (#12262)

Piotr Findeisen447cb02a3a0a
diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rs
index 88a90e1e1d..90f175b593 100644
--- a/datafusion/core/src/execution/session_state.rs
+++ b/datafusion/core/src/execution/session_state.rs
@@ -1740,8 +1740,8 @@ impl OptimizerConfig for SessionState {
self.execution_props.query_execution_start_time
}
- fn alias_generator(&self) -> Arc<AliasGenerator> {
- self.execution_props.alias_generator.clone()
+ fn alias_generator(&self) -> &Arc<AliasGenerator> {
+ &self.execution_props.alias_generator
}
fn options(&self) -> &ConfigOptions {
diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rs
index 9b64bca812..1d8eb9445e 100644
--- a/datafusion/expr/src/utils.rs
+++ b/datafusion/expr/src/utils.rs
@@ -1305,7 +1305,7 @@ pub fn only_or_err<T>(slice: &[T]) -> Result<&T> {
}
/// merge inputs schema into a single schema.
-pub fn merge_schema(inputs: Vec<&LogicalPlan>) -> DFSchema {
+pub fn merge_schema(inputs: &[&LogicalPlan]) -> DFSchema {
if inputs.len() == 1 {
inputs[0].schema().as_ref().clone()
} else {
diff --git a/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs b/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
index dd422f7aab..b2de541a34 100644
--- a/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
+++ b/datafusion/optimizer/src/analyzer/expand_wildcard_rule.rs
@@ -84,7 +84,7 @@ fn expand_exprlist(input: &LogicalPlan, expr: Vec<Expr>) -> Result<Vec<Expr>> {
// If there is a REPLACE statement, replace that column with the given
// replace expression. Column name remains the same.
let replaced = if let Some(replace) = options.replace {
- replace_columns(expanded, replace)?
+ replace_columns(expanded, &replace)?
} else {
expanded
};
@@ -95,7 +95,7 @@ fn expand_exprlist(input: &LogicalPlan, expr: Vec<Expr>) -> Result<Vec<Expr>> {
// If there is a REPLACE statement, replace that column with the given
// replace expression. Column name remains the same.
let replaced = if let Some(replace) = options.replace {
- replace_columns(expanded, replace)?
+ replace_columns(expanded, &replace)?
} else {
expanded
};
@@ -139,7 +139,7 @@ fn expand_exprlist(input: &LogicalPlan, expr: Vec<Expr>) -> Result<Vec<Expr>> {
/// Multiple REPLACEs are also possible with comma separations.
fn replace_columns(
mut exprs: Vec<Expr>,
- replace: PlannedReplaceSelectItem,
+ replace: &PlannedReplaceSelectItem,
) -> Result<Vec<Expr>> {
for expr in exprs.iter_mut() {
if let Expr::Column(Column { name, .. }) = expr {
diff --git a/datafusion/optimizer/src/analyzer/function_rewrite.rs b/datafusion/optimizer/src/analyzer/function_rewrite.rs
index 098c934bf7..94f5657b89 100644
--- a/datafusion/optimizer/src/analyzer/function_rewrite.rs
+++ b/datafusion/optimizer/src/analyzer/function_rewrite.rs
@@ -48,7 +48,7 @@ impl ApplyFunctionRewrites {
) -> Result<Transformed<LogicalPlan>> {
// get schema representing all available input fields. This is used for data type
// resolution only, so order does not matter here
- let mut schema = merge_schema(plan.inputs());
+ let mut schema = merge_schema(&plan.inputs());
if let LogicalPlan::TableScan(ts) = &plan {
let source_schema = DFSchema::try_from_qualified_schema(
diff --git a/datafusion/optimizer/src/analyzer/subquery.rs b/datafusion/optimizer/src/analyzer/subquery.rs
index 78be48a189..996dc23885 100644
--- a/datafusion/optimizer/src/analyzer/subquery.rs
+++ b/datafusion/optimizer/src/analyzer/subquery.rs
@@ -16,7 +16,6 @@
// under the License.
use std::ops::Deref;
-use std::sync::Arc;
use crate::analyzer::check_plan;
use crate::utils::collect_subquery_cols;
@@ -246,7 +245,7 @@ fn check_aggregation_in_scalar_subquery(
if !agg.group_expr.is_empty() {
let correlated_exprs = get_correlated_expressions(inner_plan)?;
let inner_subquery_cols =
- collect_subquery_cols(&correlated_exprs, Arc::clone(agg.input.schema()))?;
+ collect_subquery_cols(&correlated_exprs, agg.input.schema())?;
let mut group_columns = agg
.group_expr
.iter()
diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rs
index 61ff4b4fd5..284650c3d6 100644
--- a/datafusion/optimizer/src/analyzer/type_coercion.rs
+++ b/datafusion/optimizer/src/analyzer/type_coercion.rs
@@ -91,7 +91,7 @@ fn analyze_internal(
) -> Result<Transformed<LogicalPlan>> {
// get schema representing all available input fields. This is used for data type
// resolution only, so order does not matter here
- let mut schema = merge_schema(plan.inputs());
+ let mut schema = merge_schema(&plan.inputs());
if let LogicalPlan::TableScan(ts) = &plan {
let source_schema = DFSchema::try_from_qualified_schema(
@@ -544,12 +544,12 @@ fn coerce_scalar(target_type: &DataType, value: &ScalarValue) -> Result<ScalarVa
/// Downstream code uses this signal to treat these values as *unbounded*.
fn coerce_scalar_range_aware(
target_type: &DataType,
- value: ScalarValue,
+ value: &ScalarValue,
) -> Result<ScalarValue> {
- coerce_scalar(target_type, &value).or_else(|err| {
+ coerce_scalar(target_type, value).or_else(|err| {
// If type coercion fails, check if the largest type in family works:
if let Some(largest_type) = get_widest_type_in_family(target_type) {
- coerce_scalar(largest_type, &value).map_or_else(
+ coerce_scalar(largest_type, value).map_or_else(
|_| exec_err!("Cannot cast {value:?} to {target_type:?}"),
|_| ScalarValue::try_from(target_type),
)
@@ -578,11 +578,11 @@ fn coerce_frame_bound(
) -> Result<WindowFrameBound> {
match bound {
WindowFrameBound::Preceding(v) => {
- coerce_scalar_range_aware(target_type, v).map(WindowFrameBound::Preceding)
+ coerce_scalar_range_aware(target_type, &v).map(WindowFrameBound::Preceding)
}
WindowFrameBound::CurrentRow => Ok(WindowFrameBound::CurrentRow),
WindowFrameBound::Following(v) => {
- coerce_scalar_range_aware(target_type, v).map(WindowFrameBound::Following)
+ coerce_scalar_range_aware(target_type, &v).map(WindowFrameBound::Following)
}
}
}
@@ -1459,26 +1459,26 @@ mod test {
fn cast_helper(
case: Case,
- case_when_type: DataType,
- then_else_type: DataType,
+ case_when_type: &DataType,
+ then_else_type: &DataType,
schema: &DFSchemaRef,
) -> Case {
let expr = case
.expr
- .map(|e| cast_if_not_same_type(e, &case_when_type, schema));
+ .map(|e| cast_if_not_same_type(e, case_when_type, schema));
let when_then_expr = case
.when_then_expr
.into_iter()
.map(|(when, then)| {
(
- cast_if_not_same_type(when, &case_when_type, schema),
- cast_if_not_same_type(then, &then_else_type, schema),
+ cast_if_not_same_type(when, case_when_type, schema),
+ cast_if_not_same_type(then, then_else_type, schema),
)
})
.collect::<Vec<_>>();
let else_expr = case
.else_expr
- .map(|e| cast_if_not_same_type(e, &then_else_type, schema));
+ .map(|e| cast_if_not_same_type(e, then_else_type, schema));
Case {
expr,
@@ -1526,8 +1526,8 @@ mod test {
let then_else_common_type = DataType::Utf8;
let expected = cast_helper(
case.clone(),
- case_when_common_type,
- then_else_common_type,
+ &case_when_common_type,
+ &then_else_common_type,
&schema,
);
let actual = coerce_case_expression(case, &schema)?;
@@ -1546,8 +1546,8 @@ mod test {
let then_else_common_type = DataType::Utf8;
let expected = cast_helper(
case.clone(),
- case_when_common_type,
- then_else_common_type,
+ &case_when_common_type,
+ &then_else_common_type,
&schema,
);
let actual = coerce_case_expression(case, &schema)?;
diff --git a/datafusion/optimizer/src/common_subexpr_eliminate.rs b/datafusion/optimizer/src/common_subexpr_eliminate.rs
index 22e9d220d3..583c6cf50d 100644
--- a/datafusion/optimizer/src/common_subexpr_eliminate.rs
+++ b/datafusion/optimizer/src/common_subexpr_eliminate.rs
@@ -229,7 +229,7 @@ impl CommonSubexprEliminate {
fn rewrite_exprs_list<'n>(
&self,
exprs_list: Vec<Vec<Expr>>,
- arrays_list: Vec<Vec<IdArray<'n>>>,
+ arrays_list: &[Vec<IdArray<'n>>],
expr_stats: &ExprStats<'n>,
common_exprs: &mut CommonExprs<'n>,
alias_generator: &AliasGenerator,
@@ -284,10 +284,10 @@ impl CommonSubexprEliminate {
// Must clone as Identifiers use references to original expressions so we have
// to keep the original expressions intact.
exprs_list.clone(),
- id_arrays_list,
+ &id_arrays_list,
&expr_stats,
&mut common_exprs,
- &config.alias_generator(),
+ config.alias_generator().as_ref(),
)?;
assert!(!common_exprs.is_empty());
diff --git a/datafusion/optimizer/src/decorrelate.rs b/datafusion/optimizer/src/decorrelate.rs
index 4d0770ccbb..7f918c03e3 100644
--- a/datafusion/optimizer/src/decorrelate.rs
+++ b/datafusion/optimizer/src/decorrelate.rs
@@ -148,7 +148,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
}
fn f_up(&mut self, plan: LogicalPlan) -> Result<Transformed<LogicalPlan>> {
- let subquery_schema = Arc::clone(plan.schema());
+ let subquery_schema = plan.schema();
match &plan {
LogicalPlan::Filter(plan_filter) => {
let subquery_filter_exprs = split_conjunction(&plan_filter.predicate);
@@ -231,7 +231,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
{
proj_exprs_evaluation_result_on_empty_batch(
&projection.expr,
- Arc::clone(projection.input.schema()),
+ projection.input.schema(),
expr_result_map,
&mut expr_result_map_for_count_bug,
)?;
@@ -277,7 +277,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
{
agg_exprs_evaluation_result_on_empty_batch(
&aggregate.aggr_expr,
- Arc::clone(aggregate.input.schema()),
+ aggregate.input.schema(),
&mut expr_result_map_for_count_bug,
)?;
if !expr_result_map_for_count_bug.is_empty() {
@@ -423,7 +423,7 @@ fn remove_duplicated_filter(filters: Vec<Expr>, in_predicate: &Expr) -> Vec<Expr
fn agg_exprs_evaluation_result_on_empty_batch(
agg_expr: &[Expr],
- schema: DFSchemaRef,
+ schema: &DFSchemaRef,
expr_result_map_for_count_bug: &mut ExprResultMap,
) -> Result<()> {
for e in agg_expr.iter() {
@@ -446,7 +446,7 @@ fn agg_exprs_evaluation_result_on_empty_batch(
let result_expr = result_expr.unalias();
let props = ExecutionProps::new();
- let info = SimplifyContext::new(&props).with_schema(Arc::clone(&schema));
+ let info = SimplifyContext::new(&props).with_schema(Arc::clone(schema));
let simplifier = ExprSimplifier::new(info);
let result_expr = simplifier.simplify(result_expr)?;
if matches!(result_expr, Expr::Literal(ScalarValue::Int64(_))) {
@@ -459,7 +459,7 @@ fn agg_exprs_evaluation_result_on_empty_batch(
fn proj_exprs_evaluation_result_on_empty_batch(
proj_expr: &[Expr],
- schema: DFSchemaRef,
+ schema: &DFSchemaRef,
input_expr_result_map_for_count_bug: &ExprResultMap,
expr_result_map_for_count_bug: &mut ExprResultMap,
) -> Result<()> {
@@ -483,7 +483,7 @@ fn proj_exprs_evaluation_result_on_empty_batch(
if result_expr.ne(expr) {
let props = ExecutionProps::new();
- let info = SimplifyContext::new(&props).with_schema(Arc::clone(&schema));
+ let info = SimplifyContext::new(&props).with_schema(Arc::clone(schema));
let simplifier = ExprSimplifier::new(info);
let result_expr = simplifier.simplify(result_expr)?;
let expr_name = match expr {
diff --git a/datafusion/optimizer/src/decorrelate_predicate_subquery.rs b/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
index f1cae1099a..9b1ada382b 100644
--- a/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
+++ b/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
@@ -249,7 +249,7 @@ impl OptimizerRule for DecorrelatePredicateSubquery {
fn build_join(
query_info: &SubqueryInfo,
left: &LogicalPlan,
- alias: Arc<AliasGenerator>,
+ alias: &Arc<AliasGenerator>,
) -> Result<Option<LogicalPlan>> {
let where_in_expr_opt = &query_info.where_in_expr;
let in_predicate_opt = where_in_expr_opt
diff --git a/datafusion/optimizer/src/eliminate_cross_join.rs b/datafusion/optimizer/src/eliminate_cross_join.rs
index 20e6641e4d..93df0dcfd5 100644
--- a/datafusion/optimizer/src/eliminate_cross_join.rs
+++ b/datafusion/optimizer/src/eliminate_cross_join.rs
@@ -378,7 +378,7 @@ fn extract_possible_join_keys(expr: &Expr, join_keys: &mut JoinKeySet) {
extract_possible_join_keys(left, &mut left_join_keys);
extract_possible_join_keys(right, &mut right_join_keys);
- join_keys.insert_intersection(left_join_keys, right_join_keys)
+ join_keys.insert_intersection(&left_join_keys, &right_join_keys)
}
_ => (),
};
diff --git a/datafusion/optimizer/src/join_key_set.rs b/datafusion/optimizer/src/join_key_set.rs
index cd8ed382f0..c0eec78b18 100644
--- a/datafusion/optimizer/src/join_key_set.rs
+++ b/datafusion/optimizer/src/join_key_set.rs
@@ -107,7 +107,7 @@ impl JoinKeySet {
}
/// Inserts any join keys that are common to both `s1` and `s2` into self
- pub fn insert_intersection(&mut self, s1: JoinKeySet, s2: JoinKeySet) {
+ pub fn insert_intersection(&mut self, s1: &JoinKeySet, s2: &JoinKeySet) {
// note can't use inner.intersection as we need to consider both (l, r)
// and (r, l) in equality
for (left, right) in s1.inner.iter() {
@@ -234,7 +234,7 @@ mod test {
let mut set = JoinKeySet::new();
// put something in there already
set.insert(&col("x"), &col("y"));
- set.insert_intersection(set1, set2);
+ set.insert_intersection(&set1, &set2);
assert_contents(
&set,
diff --git a/datafusion/optimizer/src/optimize_projections/mod.rs b/datafusion/optimizer/src/optimize_projections/mod.rs
index 35b0d07751..96772d3f28 100644
--- a/datafusion/optimizer/src/optimize_projections/mod.rs
+++ b/datafusion/optimizer/src/optimize_projections/mod.rs
@@ -120,7 +120,7 @@ fn optimize_projections(
match plan {
LogicalPlan::Projection(proj) => {
return merge_consecutive_projections(proj)?.transform_data(|proj| {
- rewrite_projection_given_requirements(proj, config, indices)
+ rewrite_projection_given_requirements(proj, config, &indices)
})
}
LogicalPlan::Aggregate(aggregate) => {
@@ -754,7 +754,7 @@ fn add_projection_on_top_if_helpful(
fn rewrite_projection_given_requirements(
proj: Projection,
config: &dyn OptimizerConfig,
- indices: RequiredIndicies,
+ indices: &RequiredIndicies,
) -> Result<Transformed<LogicalPlan>> {
let Projection { expr, input, .. } = proj;
diff --git a/datafusion/optimizer/src/optimizer.rs b/datafusion/optimizer/src/optimizer.rs
index 93923a4e1e..2fc560ccee 100644
--- a/datafusion/optimizer/src/optimizer.rs
+++ b/datafusion/optimizer/src/optimizer.rs
@@ -126,7 +126,7 @@ pub trait OptimizerConfig {
fn query_execution_start_time(&self) -> DateTime<Utc>;
/// Return alias generator used to generate unique aliases for subqueries
- fn alias_generator(&self) -> Arc<AliasGenerator>;
+ fn alias_generator(&self) -> &Arc<AliasGenerator>;
fn options(&self) -> &ConfigOptions;
@@ -204,8 +204,8 @@ impl OptimizerConfig for OptimizerContext {
self.query_execution_start_time
}
- fn alias_generator(&self) -> Arc<AliasGenerator> {
- Arc::clone(&self.alias_generator)
+ fn alias_generator(&self) -> &Arc<AliasGenerator> {
+ &self.alias_generator
}
fn options(&self) -> &ConfigOptions {
diff --git a/datafusion/optimizer/src/scalar_subquery_to_join.rs b/datafusion/optimizer/src/scalar_subquery_to_join.rs
index c79180b792..e5c8757405 100644
--- a/datafusion/optimizer/src/scalar_subquery_to_join.rs
+++ b/datafusion/optimizer/src/scalar_subquery_to_join.rs
@@ -54,7 +54,7 @@ impl ScalarSubqueryToJoin {
fn extract_subquery_exprs(
&self,
predicate: &Expr,
- alias_gen: Arc<AliasGenerator>,
+ alias_gen: &Arc<AliasGenerator>,
) -> Result<(Vec<(Subquery, String)>, Expr)> {
let mut extract = ExtractScalarSubQuery {
sub_query_info: vec![],
@@ -223,12 +223,12 @@ fn contains_scalar_subquery(expr: &Expr) -> bool {
.expect("Inner is always Ok")
}
-struct ExtractScalarSubQuery {
+struct ExtractScalarSubQuery<'a> {
sub_query_info: Vec<(Subquery, String)>,
- alias_gen: Arc<AliasGenerator>,
+ alias_gen: &'a Arc<AliasGenerator>,
}
-impl TreeNodeRewriter for ExtractScalarSubQuery {
+impl TreeNodeRewriter for ExtractScalarSubQuery<'_> {
type Node = Expr;
fn f_down(&mut self, expr: Expr) -> Result<Transformed<Expr>> {
diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
index f299d4542c..fc3921d296 100644
--- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
+++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
@@ -730,7 +730,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
op: Eq,
right,
}) if is_bool_lit(&left) && info.is_boolean_type(&right)? => {
- Transformed::yes(match as_bool_lit(*left)? {
+ Transformed::yes(match as_bool_lit(&left)? {
Some(true) => *right,
Some(false) => Expr::Not(right),
None => lit_bool_null(),
@@ -744,7 +744,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
op: Eq,
right,
}) if is_bool_lit(&right) && info.is_boolean_type(&left)? => {
- Transformed::yes(match as_bool_lit(*right)? {
+ Transformed::yes(match as_bool_lit(&right)? {
Some(true) => *left,
Some(false) => Expr::Not(left),
None => lit_bool_null(),
@@ -761,7 +761,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
op: NotEq,
right,
}) if is_bool_lit(&left) && info.is_boolean_type(&right)? => {
- Transformed::yes(match as_bool_lit(*left)? {
+ Transformed::yes(match as_bool_lit(&left)? {
Some(true) => Expr::Not(right),
Some(false) => *right,
None => lit_bool_null(),
@@ -775,7 +775,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
op: NotEq,
right,
}) if is_bool_lit(&right) && info.is_boolean_type(&left)? => {
- Transformed::yes(match as_bool_lit(*right)? {
+ Transformed::yes(match as_bool_lit(&right)? {
Some(true) => Expr::Not(left),
Some(false) => *left,
None => lit_bool_null(),
@@ -1569,7 +1569,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
{
match (*left, *right) {
(Expr::InList(l1), Expr::InList(l2)) => {
- return inlist_intersection(l1, l2, false).map(Transformed::yes);
+ return inlist_intersection(l1, &l2, false).map(Transformed::yes);
}
// Matched previously once
_ => unreachable!(),
@@ -1609,7 +1609,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
{
match (*left, *right) {
(Expr::InList(l1), Expr::InList(l2)) => {
- return inlist_except(l1, l2).map(Transformed::yes);
+ return inlist_except(l1, &l2).map(Transformed::yes);
}
// Matched previously once
_ => unreachable!(),
@@ -1629,7 +1629,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
{
match (*left, *right) {
(Expr::InList(l1), Expr::InList(l2)) => {
- return inlist_except(l2, l1).map(Transformed::yes);
+ return inlist_except(l2, &l1).map(Transformed::yes);
}
// Matched previously once
_ => unreachable!(),
@@ -1649,7 +1649,7 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
{
match (*left, *right) {
(Expr::InList(l1), Expr::InList(l2)) => {
- return inlist_intersection(l1, l2, true).map(Transformed::yes);
+ return inlist_intersection(l1, &l2, true).map(Transformed::yes);
}
// Matched previously once
_ => unreachable!(),
@@ -1759,7 +1759,7 @@ fn inlist_union(mut l1: InList, l2: InList, negated: bool) -> Result<Expr> {
/// Return the intersection of two inlist expressions
/// maintaining the order of the elements in the two lists
-fn inlist_intersection(mut l1: InList, l2: InList, negated: bool) -> Result<Expr> {
+fn inlist_intersection(mut l1: InList, l2: &InList, negated: bool) -> Result<Expr> {
let l2_items = l2.list.iter().collect::<HashSet<_>>();
// remove all items from l1 that are not in l2
@@ -1775,7 +1775,7 @@ fn inlist_intersection(mut l1: InList, l2: InList, negated: bool) -> Result<Expr
/// Return the all items in l1 that are not in l2
/// maintaining the order of the elements in the two lists
-fn inlist_except(mut l1: InList, l2: InList) -> Result<Expr> {
+fn inlist_except(mut l1: InList, l2: &InList) -> Result<Expr> {
let l2_items = l2.list.iter().collect::<HashSet<_>>();
// keep only items from l1 that are not in l2
diff --git a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs
index 1c39313ea1..877989c02d 100644
--- a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs
+++ b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs
@@ -80,7 +80,7 @@ impl SimplifyExpressions {
execution_props: &ExecutionProps,
) -> Result<Transformed<LogicalPlan>> {
let schema = if !plan.inputs().is_empty() {
- DFSchemaRef::new(merge_schema(plan.inputs()))
+ DFSchemaRef::new(merge_schema(&plan.inputs()))
} else if let LogicalPlan::TableScan(scan) = &plan {
// When predicates are pushed into a table scan, there is no input
// schema to resolve predicates against, so it must be handled specially
diff --git a/datafusion/optimizer/src/simplify_expressions/utils.rs b/datafusion/optimizer/src/simplify_expressions/utils.rs
index 5da727cb59..38bfc1a934 100644
--- a/datafusion/optimizer/src/simplify_expressions/utils.rs
+++ b/datafusion/optimizer/src/simplify_expressions/utils.rs
@@ -221,9 +221,9 @@ pub fn is_negative_of(not_expr: &Expr, expr: &Expr) -> bool {
/// returns the contained boolean value in `expr` as
/// `Expr::Literal(ScalarValue::Boolean(v))`.
-pub fn as_bool_lit(expr: Expr) -> Result<Option<bool>> {
+pub fn as_bool_lit(expr: &Expr) -> Result<Option<bool>> {
match expr {
- Expr::Literal(ScalarValue::Boolean(v)) => Ok(v),
+ Expr::Literal(ScalarValue::Boolean(v)) => Ok(*v),
_ => internal_err!("Expected boolean literal, got {expr:?}"),
}
}
diff --git a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
index b17d69437c..6043f0d7c8 100644
--- a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
+++ b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
@@ -99,7 +99,7 @@ impl OptimizerRule for UnwrapCastInComparison {
plan: LogicalPlan,
_config: &dyn OptimizerConfig,
) -> Result<Transformed<LogicalPlan>> {
- let mut schema = merge_schema(plan.inputs());
+ let mut schema = merge_schema(&plan.inputs());
if let LogicalPlan::TableScan(ts) = &plan {
let source_schema = DFSchema::try_from_qualified_schema(
@@ -414,32 +414,32 @@ fn try_cast_numeric_literal(
DataType::UInt64 => ScalarValue::UInt64(Some(value as u64)),
DataType::Timestamp(TimeUnit::Second, tz) => {
let value = cast_between_timestamp(
- lit_data_type,
- DataType::Timestamp(TimeUnit::Second, tz.clone()),
+ &lit_data_type,
+ &DataType::Timestamp(TimeUnit::Second, tz.clone()),
value,
);
ScalarValue::TimestampSecond(value, tz.clone())
}
DataType::Timestamp(TimeUnit::Millisecond, tz) => {
let value = cast_between_timestamp(
- lit_data_type,
- DataType::Timestamp(TimeUnit::Millisecond, tz.clone()),
+ &lit_data_type,
+ &DataType::Timestamp(TimeUnit::Millisecond, tz.clone()),
value,
);
ScalarValue::TimestampMillisecond(value, tz.clone())
}
DataType::Timestamp(TimeUnit::Microsecond, tz) => {
let value = cast_between_timestamp(
- lit_data_type,
- DataType::Timestamp(TimeUnit::Microsecond, tz.clone()),
+ &lit_data_type,
+ &DataType::Timestamp(TimeUnit::Microsecond, tz.clone()),
value,
);
ScalarValue::TimestampMicrosecond(value, tz.clone())
}
DataType::Timestamp(TimeUnit::Nanosecond, tz) => {
let value = cast_between_timestamp(
- lit_data_type,
- DataType::Timestamp(TimeUnit::Nanosecond, tz.clone()),
+ &lit_data_type,
+ &DataType::Timestamp(TimeUnit::Nanosecond, tz.clone()),
value,
);
ScalarValue::TimestampNanosecond(value, tz.clone())
@@ -505,7 +505,7 @@ fn try_cast_dictionary(
}
/// Cast a timestamp value from one unit to another
-fn cast_between_timestamp(from: DataType, to: DataType, value: i128) -> Option<i64> {
+fn cast_between_timestamp(from: &DataType, to: &DataType, value: i128) -> Option<i64> {
let value = value as i64;
let from_scale = match from {
DataType::Timestamp(TimeUnit::Second, _) => 1,
diff --git a/datafusion/optimizer/src/utils.rs b/datafusion/optimizer/src/utils.rs
index 45cef55bf2..9e602ad497 100644
--- a/datafusion/optimizer/src/utils.rs
+++ b/datafusion/optimizer/src/utils.rs
@@ -21,7 +21,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use crate::{OptimizerConfig, OptimizerRule};
-use datafusion_common::{Column, DFSchema, DFSchemaRef, Result};
+use datafusion_common::{Column, DFSchema, Result};
use datafusion_expr::expr_rewriter::replace_col;
use datafusion_expr::utils as expr_utils;
use datafusion_expr::{logical_plan::LogicalPlan, Expr, Operator};
@@ -83,7 +83,7 @@ pub(crate) fn has_all_column_refs(expr: &Expr, schema_cols: &HashSet<Column>) ->
pub(crate) fn collect_subquery_cols(
exprs: &[Expr],
- subquery_schema: DFSchemaRef,
+ subquery_schema: &DFSchema,
) -> Result<BTreeSet<Column>> {
exprs.iter().try_fold(BTreeSet::new(), |mut cols, expr| {
let mut using_cols: Vec<Column> = vec![];
@@ -296,5 +296,5 @@ pub fn only_or_err<T>(slice: &[T]) -> Result<&T> {
note = "use `datafusion_expr::utils::merge_schema` instead"
)]
pub fn merge_schema(inputs: Vec<&LogicalPlan>) -> DFSchema {
- expr_utils::merge_schema(inputs)
+ expr_utils::merge_schema(&inputs)
}