Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review: fix clippy error instead of suppressing
  • Loading branch information
2010YOUY01 committed Nov 4, 2025
commit 2736b392ab7e8f1742a4ef882e5e39c8b8cf239a
6 changes: 1 addition & 5 deletions ci/scripts/rust_clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@
# under the License.

set -ex
cargo clippy --all-targets --workspace --features avro,pyarrow,integration-tests,extended_tests -- -D warnings

# Update packages incrementally for stricter Clippy checks
# TODO: add tracking issue for the remaining workspace packages like `datafusion-catalog`
cargo clippy -p datafusion-common --all-targets --features avro,pyarrow,parquet_encryption,sql -- -D warnings -W clippy::needless_pass_by_value
cargo clippy --all-targets --workspace --features avro,pyarrow,integration-tests,extended_tests -- -D warnings
8 changes: 6 additions & 2 deletions datafusion/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ rust-version = { workspace = true }
[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true
[lints] # Overrides / extends workspace.lints
[lints.clippy]
# Avoid unnecessary clones for performance, okay to ignore for tests or intentional
# moves.
# Reference: <https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value>
needless_pass_by_value = "deny"

[lib]
name = "datafusion_common"
Expand Down
19 changes: 9 additions & 10 deletions datafusion/common/src/hash_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ fn hash_array_primitive<T>(
/// If `rehash==true` this combines the previous hash value in the buffer
/// with the new hash using `combine_hashes`
#[cfg(not(feature = "force_hash_collisions"))]
#[allow(clippy::needless_pass_by_value)]
fn hash_array<T>(
array: T,
array: &T,
random_state: &RandomState,
hashes_buffer: &mut [u64],
rehash: bool,
Expand Down Expand Up @@ -401,16 +400,16 @@ pub fn create_hashes<'a>(
downcast_primitive_array! {
array => hash_array_primitive(array, random_state, hashes_buffer, rehash),
DataType::Null => hash_null(random_state, hashes_buffer, rehash),
DataType::Boolean => hash_array(as_boolean_array(array)?, random_state, hashes_buffer, rehash),
DataType::Utf8 => hash_array(as_string_array(array)?, random_state, hashes_buffer, rehash),
DataType::Utf8View => hash_array(as_string_view_array(array)?, random_state, hashes_buffer, rehash),
DataType::LargeUtf8 => hash_array(as_largestring_array(array), random_state, hashes_buffer, rehash),
DataType::Binary => hash_array(as_generic_binary_array::<i32>(array)?, random_state, hashes_buffer, rehash),
DataType::BinaryView => hash_array(as_binary_view_array(array)?, random_state, hashes_buffer, rehash),
DataType::LargeBinary => hash_array(as_generic_binary_array::<i64>(array)?, random_state, hashes_buffer, rehash),
DataType::Boolean => hash_array(&as_boolean_array(array)?, random_state, hashes_buffer, rehash),
DataType::Utf8 => hash_array(&as_string_array(array)?, random_state, hashes_buffer, rehash),
DataType::Utf8View => hash_array(&as_string_view_array(array)?, random_state, hashes_buffer, rehash),
DataType::LargeUtf8 => hash_array(&as_largestring_array(array), random_state, hashes_buffer, rehash),
DataType::Binary => hash_array(&as_generic_binary_array::<i32>(array)?, random_state, hashes_buffer, rehash),
DataType::BinaryView => hash_array(&as_binary_view_array(array)?, random_state, hashes_buffer, rehash),
DataType::LargeBinary => hash_array(&as_generic_binary_array::<i64>(array)?, random_state, hashes_buffer, rehash),
DataType::FixedSizeBinary(_) => {
let array: &FixedSizeBinaryArray = array.as_any().downcast_ref().unwrap();
hash_array(array, random_state, hashes_buffer, rehash)
hash_array(&array, random_state, hashes_buffer, rehash)
}
DataType::Dictionary(_, _) => downcast_dictionary_array! {
array => hash_dictionary(array, random_state, hashes_buffer, rehash)?,
Expand Down
18 changes: 8 additions & 10 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4436,7 +4436,7 @@ impl From<Vec<(&str, ScalarValue)>> for ScalarValue {
value
.into_iter()
.fold(ScalarStructBuilder::new(), |builder, (name, value)| {
builder.with_name_and_scalar(name, value)
builder.with_name_and_scalar(name, &value)
})
.build()
.unwrap()
Expand Down Expand Up @@ -4648,9 +4648,9 @@ impl fmt::Display for ScalarValue {
}
None => write!(f, "NULL")?,
},
ScalarValue::List(arr) => fmt_list(arr.to_owned() as ArrayRef, f)?,
ScalarValue::LargeList(arr) => fmt_list(arr.to_owned() as ArrayRef, f)?,
ScalarValue::FixedSizeList(arr) => fmt_list(arr.to_owned() as ArrayRef, f)?,
ScalarValue::List(arr) => fmt_list(arr.as_ref(), f)?,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ScalarValue::LargeList(arr) => fmt_list(arr.as_ref(), f)?,
ScalarValue::FixedSizeList(arr) => fmt_list(arr.as_ref(), f)?,
ScalarValue::Date32(e) => format_option!(
f,
e.map(|v| {
Expand Down Expand Up @@ -4772,13 +4772,11 @@ impl fmt::Display for ScalarValue {
}
}

#[allow(clippy::needless_pass_by_value)]
fn fmt_list(arr: ArrayRef, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_list(arr: &dyn Array, f: &mut fmt::Formatter) -> fmt::Result {
// ScalarValue List, LargeList, FixedSizeList should always have a single element
assert_eq!(arr.len(), 1);
let options = FormatOptions::default().with_display_error(true);
let formatter =
ArrayFormatter::try_new(arr.as_ref() as &dyn Array, &options).unwrap();
let formatter = ArrayFormatter::try_new(arr, &options).unwrap();
let value_formatter = formatter.value(0);
write!(f, "{value_formatter}")
}
Expand Down Expand Up @@ -8238,8 +8236,8 @@ mod tests {
let field_b = Field::new("b", DataType::Utf8, true);

let s = ScalarStructBuilder::new()
.with_scalar(field_a, ScalarValue::from(1i32))
.with_scalar(field_b, ScalarValue::Utf8(None))
.with_scalar(field_a, &ScalarValue::from(1i32))
.with_scalar(field_b, &ScalarValue::Utf8(None))
.build()
.unwrap();

Expand Down
5 changes: 2 additions & 3 deletions datafusion/common/src/scalar/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ impl ScalarStructBuilder {
}

/// Add the specified field and `ScalarValue` to the struct.
#[allow(clippy::needless_pass_by_value)]
pub fn with_scalar(self, field: impl IntoFieldRef, value: ScalarValue) -> Self {
pub fn with_scalar(self, field: impl IntoFieldRef, value: &ScalarValue) -> Self {
// valid scalar value should not fail
let array = value.to_array().unwrap();
self.with_array(field, array)
}

/// Add a field with the specified name and value to the struct.
/// the field is created with the specified data type and as non nullable
pub fn with_name_and_scalar(self, name: &str, value: ScalarValue) -> Self {
pub fn with_name_and_scalar(self, name: &str, value: &ScalarValue) -> Self {
let field = Field::new(name, value.data_type(), false);
self.with_scalar(field, value)
}
Expand Down
8 changes: 4 additions & 4 deletions datafusion/proto/tests/cases/roundtrip_logical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,22 +1533,22 @@ fn round_trip_scalar_values_and_data_types() {
ScalarStructBuilder::new()
.with_scalar(
Field::new("a", DataType::Int32, true),
ScalarValue::from(23i32),
&ScalarValue::from(23i32),
)
.with_scalar(
Field::new("b", DataType::Boolean, false),
ScalarValue::from(false),
&ScalarValue::from(false),
)
.build()
.unwrap(),
ScalarStructBuilder::new()
.with_scalar(
Field::new("a", DataType::Int32, true),
ScalarValue::from(23i32),
&ScalarValue::from(23i32),
)
.with_scalar(
Field::new("b", DataType::Boolean, false),
ScalarValue::from(false),
&ScalarValue::from(false),
)
.build()
.unwrap(),
Expand Down
10 changes: 7 additions & 3 deletions datafusion/substrait/src/logical_plan/consumer/expr/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,13 @@ pub(crate) fn from_substrait_literal(
&mut entry_name_idx,
)?;
ScalarStructBuilder::new()
.with_scalar(Field::new("key", key_sv.data_type(), false), key_sv)
.with_scalar(
Field::new("key", key_sv.data_type(), false),
&key_sv,
)
.with_scalar(
Field::new("value", value_sv.data_type(), true),
value_sv,
&value_sv,
)
.build()
})
Expand Down Expand Up @@ -367,7 +370,8 @@ pub(crate) fn from_substrait_literal(
let sv = from_substrait_literal(consumer, field, dfs_names, name_idx)?;
// We assume everything to be nullable, since Arrow's strict about things matching
// and it's hard to match otherwise.
builder = builder.with_scalar(Field::new(name, sv.data_type(), true), sv);
builder =
builder.with_scalar(Field::new(name, sv.data_type(), true), &sv);
}
builder.build()?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ mod tests {
let c2 = Field::new("c2", DataType::Utf8, true);
round_trip_literal(
ScalarStructBuilder::new()
.with_scalar(c0.to_owned(), ScalarValue::Boolean(Some(true)))
.with_scalar(c1.to_owned(), ScalarValue::Int32(Some(1)))
.with_scalar(c2.to_owned(), ScalarValue::Utf8(None))
.with_scalar(c0.to_owned(), &ScalarValue::Boolean(Some(true)))
.with_scalar(c1.to_owned(), &ScalarValue::Int32(Some(1)))
.with_scalar(c2.to_owned(), &ScalarValue::Utf8(None))
.build()?,
)?;
round_trip_literal(ScalarStructBuilder::new_null(vec![c0, c1, c2]))?;
Expand Down