Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion ci/scripts/rust_clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
# under the License.

set -ex
cargo clippy --all-targets --workspace --features avro,pyarrow,integration-tests,extended_tests -- -D warnings
cargo clippy --all-targets --workspace --features avro,pyarrow,integration-tests,extended_tests -- -D warnings
11 changes: 9 additions & 2 deletions datafusion/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ 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"
# Make sure fast / cheap clones on Arc are explicit:
# https://github.com/apache/datafusion/issues/11143
clone_on_ref_ptr = "deny"

[lib]
name = "datafusion_common"
Expand Down
18 changes: 9 additions & 9 deletions datafusion/common/src/hash_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn hash_array_primitive<T>(
/// with the new hash using `combine_hashes`
#[cfg(not(feature = "force_hash_collisions"))]
fn hash_array<T>(
array: T,
array: &T,
random_state: &RandomState,
hashes_buffer: &mut [u64],
rehash: bool,
Expand Down Expand Up @@ -400,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
6 changes: 3 additions & 3 deletions datafusion/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg"
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
// Make sure fast / cheap clones on Arc are explicit:
// https://github.com/apache/datafusion/issues/11143
#![deny(clippy::clone_on_ref_ptr)]
// This lint rule is enforced in `../Cargo.toml`, but it's okay to skip them in tests
// See details in https://github.com/apache/datafusion/issues/18503
#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To turn off this lint rule for all tests


mod column;
mod dfschema;
Expand Down
11 changes: 5 additions & 6 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
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
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,12 +4772,11 @@ impl fmt::Display for ScalarValue {
}
}

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
1 change: 1 addition & 0 deletions datafusion/common/src/scalar/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl ScalarStructBuilder {
}

/// Add the specified field and `ScalarValue` to the struct.
#[expect(clippy::needless_pass_by_value)] // Skip for public API's compatibility
pub fn with_scalar(self, field: impl IntoFieldRef, value: ScalarValue) -> Self {
// valid scalar value should not fail
let array = value.to_array().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ impl LogicalPlan {

/// Helper for [Self::with_new_exprs] to use when no expressions are expected.
#[inline]
#[allow(clippy::needless_pass_by_value)] // expr is moved intentionally to ensure it's not used again
#[expect(clippy::needless_pass_by_value)] // expr is moved intentionally to ensure it's not used again
fn assert_no_expressions(&self, expr: Vec<Expr>) -> Result<()> {
if !expr.is_empty() {
return internal_err!("{self:?} should have no exprs, got {:?}", expr);
Expand All @@ -1166,7 +1166,7 @@ impl LogicalPlan {

/// Helper for [Self::with_new_exprs] to use when no inputs are expected.
#[inline]
#[allow(clippy::needless_pass_by_value)] // inputs is moved intentionally to ensure it's not used again
#[expect(clippy::needless_pass_by_value)] // inputs is moved intentionally to ensure it's not used again
fn assert_no_inputs(&self, inputs: Vec<LogicalPlan>) -> Result<()> {
if !inputs.is_empty() {
return internal_err!("{self:?} should have no inputs, got: {:?}", inputs);
Expand Down