Skip to content

Commit a216d4a

Browse files
chore: Enforce lint rule clippy::needless_pass_by_value to datafusion-physical-expr (apache#18557)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#18544. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> See apache#18503 for details. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> I enabled the clippy lint rule and then fixed nearly all instances. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> As part of the normal test suite, yes. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> The following `pub (crate)` APIs were changed: - `regex_match_dyn` in `datafusion/physical-expr/src/expressions/binary/kernels.rs` - `regex_match_dyn_scalar` in `datafusion/physical-expr/src/expressions/binary/kernels.rs` But no fully `pub` functions were changed.
1 parent f10fcbe commit a216d4a

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

datafusion/physical-expr/src/analysis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn analyze(
218218
.update_ranges(&mut target_indices_and_boundaries, Interval::CERTAINLY_TRUE)?
219219
{
220220
PropagationResult::Success => {
221-
shrink_boundaries(graph, target_boundaries, target_expr_and_indices)
221+
shrink_boundaries(&graph, target_boundaries, &target_expr_and_indices)
222222
}
223223
PropagationResult::Infeasible => {
224224
// If the propagation result is infeasible, set intervals to None
@@ -239,9 +239,9 @@ pub fn analyze(
239239
/// Following this, it constructs and returns a new `AnalysisContext` with the
240240
/// updated parameters.
241241
fn shrink_boundaries(
242-
graph: ExprIntervalGraph,
242+
graph: &ExprIntervalGraph,
243243
mut target_boundaries: Vec<ExprBoundaries>,
244-
target_expr_and_indices: Vec<(Arc<dyn PhysicalExpr>, usize)>,
244+
target_expr_and_indices: &[(Arc<dyn PhysicalExpr>, usize)],
245245
) -> Result<AnalysisContext> {
246246
let initial_boundaries = target_boundaries.clone();
247247
target_expr_and_indices.iter().for_each(|(expr, i)| {

datafusion/physical-expr/src/equivalence/properties/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl EquivalenceProperties {
380380
right: Arc<dyn PhysicalExpr>,
381381
) -> Result<()> {
382382
// Add equal expressions to the state:
383-
if self.eq_group.add_equal_conditions(Arc::clone(&left), right) {
383+
if self.eq_group.add_equal_conditions(left, right) {
384384
self.update_oeq_cache()?;
385385
}
386386
self.update_oeq_cache()?;

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ impl BinaryExpr {
573573
) -> Result<Option<Result<ArrayRef>>> {
574574
use Operator::*;
575575
let scalar_result = match &self.op {
576-
RegexMatch => regex_match_dyn_scalar(array, scalar, false, false),
577-
RegexIMatch => regex_match_dyn_scalar(array, scalar, false, true),
578-
RegexNotMatch => regex_match_dyn_scalar(array, scalar, true, false),
579-
RegexNotIMatch => regex_match_dyn_scalar(array, scalar, true, true),
576+
RegexMatch => regex_match_dyn_scalar(array, &scalar, false, false),
577+
RegexIMatch => regex_match_dyn_scalar(array, &scalar, false, true),
578+
RegexNotMatch => regex_match_dyn_scalar(array, &scalar, true, false),
579+
RegexNotIMatch => regex_match_dyn_scalar(array, &scalar, true, true),
580580
BitwiseAnd => bitwise_and_dyn_scalar(array, scalar),
581581
BitwiseOr => bitwise_or_dyn_scalar(array, scalar),
582582
BitwiseXor => bitwise_xor_dyn_scalar(array, scalar),
@@ -625,16 +625,16 @@ impl BinaryExpr {
625625
)
626626
}
627627
}
628-
RegexMatch => regex_match_dyn(left, right, false, false),
629-
RegexIMatch => regex_match_dyn(left, right, false, true),
630-
RegexNotMatch => regex_match_dyn(left, right, true, false),
631-
RegexNotIMatch => regex_match_dyn(left, right, true, true),
628+
RegexMatch => regex_match_dyn(&left, &right, false, false),
629+
RegexIMatch => regex_match_dyn(&left, &right, false, true),
630+
RegexNotMatch => regex_match_dyn(&left, &right, true, false),
631+
RegexNotIMatch => regex_match_dyn(&left, &right, true, true),
632632
BitwiseAnd => bitwise_and_dyn(left, right),
633633
BitwiseOr => bitwise_or_dyn(left, right),
634634
BitwiseXor => bitwise_xor_dyn(left, right),
635635
BitwiseShiftRight => bitwise_shift_right_dyn(left, right),
636636
BitwiseShiftLeft => bitwise_shift_left_dyn(left, right),
637-
StringConcat => concat_elements(left, right),
637+
StringConcat => concat_elements(&left, &right),
638638
AtArrow | ArrowAt | Arrow | LongArrow | HashArrow | HashLongArrow | AtAt
639639
| HashMinus | AtQuestion | Question | QuestionAnd | QuestionPipe
640640
| IntegerDivide => {
@@ -854,7 +854,7 @@ fn pre_selection_scatter(
854854
Ok(ColumnarValue::Array(Arc::new(boolean_result)))
855855
}
856856

857-
fn concat_elements(left: Arc<dyn Array>, right: Arc<dyn Array>) -> Result<ArrayRef> {
857+
fn concat_elements(left: &ArrayRef, right: &ArrayRef) -> Result<ArrayRef> {
858858
Ok(match left.data_type() {
859859
DataType::Utf8 => Arc::new(concat_elements_utf8(
860860
left.as_string::<i32>(),

datafusion/physical-expr/src/expressions/binary/kernels.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ macro_rules! regexp_is_match_flag {
207207
}
208208

209209
pub(crate) fn regex_match_dyn(
210-
left: ArrayRef,
211-
right: ArrayRef,
210+
left: &ArrayRef,
211+
right: &ArrayRef,
212212
not_match: bool,
213213
flag: bool,
214214
) -> Result<ArrayRef> {
@@ -259,7 +259,7 @@ macro_rules! regexp_is_match_flag_scalar {
259259

260260
pub(crate) fn regex_match_dyn_scalar(
261261
left: &dyn Array,
262-
right: ScalarValue,
262+
right: &ScalarValue,
263263
not_match: bool,
264264
flag: bool,
265265
) -> Option<Result<ArrayRef>> {

datafusion/physical-expr/src/expressions/in_list.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ where
149149
///
150150
/// Note: This is split into a separate function as higher-rank trait bounds currently
151151
/// cause type inference to misbehave
152-
fn make_hash_set<T>(array: T) -> ArrayHashSet
152+
fn make_hash_set<T>(array: &T) -> ArrayHashSet
153153
where
154154
T: ArrayAccessor,
155155
T::Item: IsEqual,
@@ -183,26 +183,26 @@ where
183183
/// Creates a `Box<dyn Set>` for the given list of `IN` expressions and `batch`
184184
fn make_set(array: &dyn Array) -> Result<Arc<dyn Set>> {
185185
Ok(downcast_primitive_array! {
186-
array => Arc::new(ArraySet::new(array, make_hash_set(array))),
186+
array => Arc::new(ArraySet::new(array, make_hash_set(&array))),
187187
DataType::Boolean => {
188188
let array = as_boolean_array(array)?;
189-
Arc::new(ArraySet::new(array, make_hash_set(array)))
189+
Arc::new(ArraySet::new(array, make_hash_set(&array)))
190190
},
191191
DataType::Utf8 => {
192192
let array = as_string_array(array)?;
193-
Arc::new(ArraySet::new(array, make_hash_set(array)))
193+
Arc::new(ArraySet::new(array, make_hash_set(&array)))
194194
}
195195
DataType::LargeUtf8 => {
196196
let array = as_largestring_array(array);
197-
Arc::new(ArraySet::new(array, make_hash_set(array)))
197+
Arc::new(ArraySet::new(array, make_hash_set(&array)))
198198
}
199199
DataType::Binary => {
200200
let array = as_generic_binary_array::<i32>(array)?;
201-
Arc::new(ArraySet::new(array, make_hash_set(array)))
201+
Arc::new(ArraySet::new(array, make_hash_set(&array)))
202202
}
203203
DataType::LargeBinary => {
204204
let array = as_generic_binary_array::<i64>(array)?;
205-
Arc::new(ArraySet::new(array, make_hash_set(array)))
205+
Arc::new(ArraySet::new(array, make_hash_set(&array)))
206206
}
207207
DataType::Dictionary(_, _) => unreachable!("dictionary should have been flattened"),
208208
d => return not_impl_err!("DataType::{d} not supported in InList")

datafusion/physical-expr/src/expressions/literal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl PhysicalExpr for Literal {
137137
}
138138

139139
/// Create a literal expression
140+
#[allow(clippy::needless_pass_by_value)]
140141
pub fn lit<T: datafusion_expr::Literal>(value: T) -> Arc<dyn PhysicalExpr> {
141142
match value.lit() {
142143
Expr::Literal(v, _) => Arc::new(Literal::new(v)),

datafusion/physical-expr/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
// Make sure fast / cheap clones on Arc are explicit:
2424
// https://github.com/apache/datafusion/issues/11143
2525
#![deny(clippy::clone_on_ref_ptr)]
26+
// https://github.com/apache/datafusion/issues/18503
27+
#![deny(clippy::needless_pass_by_value)]
28+
#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
2629

2730
// Backward compatibility
2831
pub mod aggregate;

datafusion/physical-expr/src/utils/guarantee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl LiteralGuarantee {
124124
// for an `AND` conjunction to be true, all terms individually must be true
125125
.fold(GuaranteeBuilder::new(), |builder, expr| {
126126
if let Some(cel) = ColOpLit::try_new(expr) {
127-
builder.aggregate_conjunct(cel)
127+
builder.aggregate_conjunct(&cel)
128128
} else if let Some(inlist) = expr
129129
.as_any()
130130
.downcast_ref::<crate::expressions::InListExpr>()
@@ -292,7 +292,7 @@ impl<'a> GuaranteeBuilder<'a> {
292292
/// # Examples
293293
/// * `AND (a = 1)`: `a` is guaranteed to be 1
294294
/// * `AND (a != 1)`: a is guaranteed to not be 1
295-
fn aggregate_conjunct(self, col_op_lit: ColOpLit<'a>) -> Self {
295+
fn aggregate_conjunct(self, col_op_lit: &ColOpLit<'a>) -> Self {
296296
self.aggregate_multi_conjunct(
297297
col_op_lit.col,
298298
col_op_lit.guarantee,

0 commit comments

Comments
 (0)