Skip to content

Apache DataFusion SQL Query Engine

Enable more clippy lints (#24322)

Emil Ernerfeldt303ff78ac894
diff --git a/Cargo.toml b/Cargo.toml
index 65670d895e..cff099732b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -217,59 +217,114 @@ zstd = { version = "0.13", default-features = false }
allow_attributes = "warn"
as_ptr_cast_mut = "warn"
assigning_clones = "warn"
+bool_to_int_with_if = "warn"
+branches_sharing_code = "warn"
+checked_conversions = "warn"
clear_with_drain = "warn"
coerce_container_to_any = "warn"
debug_assert_with_mut_call = "warn"
decimal_bitwise_operands = "warn"
default_union_representation = "warn"
doc_include_without_cfg = "warn"
+duration_suboptimal_units = "warn"
+elidable_lifetime_names = "warn"
empty_enum_variants_with_brackets = "warn"
+empty_enums = "warn"
+equatable_if_let = "warn"
exit = "warn"
+expl_impl_clone_on_copy = "warn"
+explicit_deref_methods = "warn"
+filter_map_next = "warn"
flat_map_option = "warn"
+fn_params_excessive_bools = "warn"
fn_to_numeric_cast_any = "warn"
+ignore_without_reason = "warn"
imprecise_flops = "warn"
+inconsistent_struct_constructor = "warn"
index_refutable_slice = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
+into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
ip_constant = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
+iter_not_returning_iterator = "warn"
iter_on_empty_collections = "warn"
+iter_on_single_items = "warn"
+iter_without_into_iter = "warn"
# Detects large stack-allocated futures that may cause stack overflow crashes (see threshold in clippy.toml)
large_futures = "warn"
large_include_file = "warn"
+# Like `large_futures`, these guard against stack overflows
+large_stack_arrays = "warn"
+large_stack_frames = "warn"
+large_types_passed_by_value = "warn"
+linkedlist = "warn"
+# Catches `"{foo}"` where the string is never actually formatted
+literal_string_with_formatting_args = "warn"
macro_use_imports = "warn"
+manual_assert = "warn"
manual_ilog2 = "warn"
manual_instant_elapsed = "warn"
manual_is_power_of_two = "warn"
+manual_is_variant_and = "warn"
+# `(a + b) / 2` can overflow; `a.midpoint(b)` cannot
+manual_midpoint = "warn"
match_wild_err_arm = "warn"
mem_forget = "warn"
mismatching_type_param_order = "warn"
mut_mut = "warn"
# https://github.com/apache/datafusion/issues/18503
needless_pass_by_value = "warn"
+needless_type_cast = "warn"
negative_feature_names = "warn"
+# Prefer `std::sync::LazyLock` over the `lazy_static`/`once_cell` crates
+non_std_lazy_statics = "warn"
non_zero_suggestions = "warn"
nonstandard_macro_braces = "warn"
+option_as_ref_cloned = "warn"
+option_option = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
pathbuf_init_then_push = "warn"
precedence_bits = "warn"
+ptr_cast_constness = "warn"
pub_underscore_fields = "warn"
+pub_without_shorthand = "warn"
rc_mutex = "warn"
+ref_as_ptr = "warn"
ref_option_ref = "warn"
+rest_pat_in_fully_bound_structs = "warn"
+# Catches copy-paste bugs in `if`/`else if` chains
+same_functions_in_if_condition = "warn"
same_length_and_capacity = "warn"
+# Catches a `&self` argument that is only threaded through recursive calls
+self_only_used_in_recursion = "warn"
+# Avoids hashing the key twice
+set_contains_or_insert = "warn"
+single_option_map = "warn"
str_split_at_newline = "warn"
string_add_assign = "warn"
+string_lit_as_bytes = "warn"
+string_lit_chars_any = "warn"
suspicious_xor_used_as_pow = "warn"
trailing_empty_array = "warn"
+trait_duplication_in_bounds = "warn"
transmute_ptr_to_ptr = "warn"
+# Subtracting `Instant`s panics on overflow; use `saturating_duration_since`
+unchecked_time_subtraction = "warn"
uninhabited_references = "warn"
uninlined_format_args = "warn"
+unnecessary_box_returns = "warn"
+# `{:?}` on a `Path` quotes and escapes it; `{}` on `.display()` does not
+unnecessary_debug_formatting = "warn"
unnecessary_lazy_evaluations = "warn"
+unnecessary_safety_doc = "warn"
unnecessary_self_imports = "warn"
+unnecessary_struct_initialization = "warn"
unused_async = "warn"
+unused_peekable = "warn"
unused_rounding = "warn"
used_underscore_binding = "warn"
verbose_file_reads = "warn"
diff --git a/benchmarks/src/bin/benchmark_runner.rs b/benchmarks/src/bin/benchmark_runner.rs
index c1700c42ba..fc980a63bf 100644
--- a/benchmarks/src/bin/benchmark_runner.rs
+++ b/benchmarks/src/bin/benchmark_runner.rs
@@ -1970,6 +1970,10 @@ description = "Run query one against CSV data."
}
#[tokio::test]
+ #[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `${VAR:-default}` braces are shell-style placeholders, not format args"
+ )]
async fn cli_subgroup_filter_is_used_for_benchmark_replacements() {
let temp = tempfile::tempdir().unwrap();
@@ -1992,6 +1996,10 @@ description = "Run query one against CSV data."
}
#[tokio::test]
+ #[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `${VAR:-default}` braces are shell-style placeholders, not format args"
+ )]
async fn benchmark_replacements_use_explicit_data_dir() {
let temp = tempfile::tempdir().unwrap();
diff --git a/benchmarks/src/bin/mem_profile.rs b/benchmarks/src/bin/mem_profile.rs
index 41a0baecbb..36e22570f5 100644
--- a/benchmarks/src/bin/mem_profile.rs
+++ b/benchmarks/src/bin/mem_profile.rs
@@ -145,11 +145,10 @@ fn run_benchmark_as_child_process(
env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string());
let command = format!("{target_dir}/{profile}/dfbench");
// Check whether benchmark binary exists
- if !Path::new(&command).exists() {
- panic!(
- "Benchmark binary not found: `{command}`\nRun this command from the top-level `datafusion/` directory so `target/{profile}/dfbench` can be found.",
- );
- }
+ assert!(
+ Path::new(&command).exists(),
+ "Benchmark binary not found: `{command}`\nRun this command from the top-level `datafusion/` directory so `target/{profile}/dfbench` can be found.",
+ );
args.insert(0, command);
let mut results = vec![];
@@ -339,11 +338,10 @@ mod tests {
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
- if !output.status.success() {
- panic!(
- "mem_profile failed\nstdout:\n{stdout}\nstderr:\n{stderr}---------------------",
- );
- }
+ assert!(
+ output.status.success(),
+ "mem_profile failed\nstdout:\n{stdout}\nstderr:\n{stderr}---------------------",
+ );
assert!(
stdout.contains("Peak RSS")
diff --git a/benchmarks/src/nlj.rs b/benchmarks/src/nlj.rs
index 485ee069d1..87bfbaf4dd 100644
--- a/benchmarks/src/nlj.rs
+++ b/benchmarks/src/nlj.rs
@@ -226,7 +226,7 @@ impl RunOpt {
}
Err(e) => {
return Err(DataFusionError::Context(
- "NLJ benchmark Q{query_id} failed with error:".to_string(),
+ format!("NLJ benchmark Q{query_id} failed with error:"),
Box::new(e),
));
}
diff --git a/benchmarks/src/sql_benchmark.rs b/benchmarks/src/sql_benchmark.rs
index f69012402a..24db7e0a0f 100644
--- a/benchmarks/src/sql_benchmark.rs
+++ b/benchmarks/src/sql_benchmark.rs
@@ -1761,6 +1761,10 @@ mod tests {
}
#[test]
+ #[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `${VAR:-default}` braces are shell-style placeholders, not format args"
+ )]
fn process_replacements_uses_default_for_missing_variable() {
let replacements = HashMap::new();
@@ -2300,6 +2304,10 @@ NULL|(empty)
}
#[tokio::test]
+ #[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `${VAR:-default}` braces are shell-style placeholders, not format args"
+ )]
async fn parser_applies_data_dir_replacement_in_load_query_file() {
let temp_dir = tempdir().expect("failed to create benchmark test directory");
let data_dir = temp_dir.path().join("non_default_data");
diff --git a/datafusion-cli/src/functions.rs b/datafusion-cli/src/functions.rs
index 409eedee75..657be4268d 100644
--- a/datafusion-cli/src/functions.rs
+++ b/datafusion-cli/src/functions.rs
@@ -283,16 +283,16 @@ fn convert_parquet_statistics(
val.max_opt().map(|v| v.to_string()),
),
(Statistics::ByteArray(val), ConvertedType::UTF8) => (
- byte_array_to_string(val.min_opt()),
- byte_array_to_string(val.max_opt()),
+ val.min_opt().map(byte_array_to_string),
+ val.max_opt().map(byte_array_to_string),
),
(Statistics::ByteArray(val), _) => (
val.min_opt().map(|v| v.to_string()),
val.max_opt().map(|v| v.to_string()),
),
(Statistics::FixedLenByteArray(val), ConvertedType::UTF8) => (
- fixed_len_byte_array_to_string(val.min_opt()),
- fixed_len_byte_array_to_string(val.max_opt()),
+ val.min_opt().map(fixed_len_byte_array_to_string),
+ val.max_opt().map(fixed_len_byte_array_to_string),
),
(Statistics::FixedLenByteArray(val), _) => (
val.min_opt().map(|v| v.to_string()),
@@ -302,21 +302,17 @@ fn convert_parquet_statistics(
}
/// Convert to a string if it has utf8 encoding, otherwise print bytes directly
-fn byte_array_to_string(val: Option<&ByteArray>) -> Option<String> {
- val.map(|v| {
- v.as_utf8()
- .map(|s| s.to_string())
- .unwrap_or_else(|_e| v.to_string())
- })
+fn byte_array_to_string(val: &ByteArray) -> String {
+ val.as_utf8()
+ .map(|s| s.to_string())
+ .unwrap_or_else(|_e| val.to_string())
}
/// Convert to a string if it has utf8 encoding, otherwise print bytes directly
-fn fixed_len_byte_array_to_string(val: Option<&FixedLenByteArray>) -> Option<String> {
- val.map(|v| {
- v.as_utf8()
- .map(|s| s.to_string())
- .unwrap_or_else(|_e| v.to_string())
- })
+fn fixed_len_byte_array_to_string(val: &FixedLenByteArray) -> String {
+ val.as_utf8()
+ .map(|s| s.to_string())
+ .unwrap_or_else(|_e| val.to_string())
}
#[derive(Debug)]
diff --git a/datafusion-cli/src/helper.rs b/datafusion-cli/src/helper.rs
index 67e203cf79..db3e80efad 100644
--- a/datafusion-cli/src/helper.rs
+++ b/datafusion-cli/src/helper.rs
@@ -308,16 +308,14 @@ mod tests {
let mut validator = CliHelper::default();
// should be invalid in generic dialect
- let result =
- readline_direct(Cursor::new(r"select 1 # 2;".as_bytes()), &validator)?;
+ let result = readline_direct(Cursor::new(br"select 1 # 2;"), &validator)?;
assert!(
matches!(result, ValidationResult::Invalid(Some(e)) if e.contains("Invalid statement"))
);
// valid in postgresql dialect
validator.set_dialect(&Dialect::PostgreSQL);
- let result =
- readline_direct(Cursor::new(r"select 1 # 2;".as_bytes()), &validator)?;
+ let result = readline_direct(Cursor::new(br"select 1 # 2;"), &validator)?;
assert!(matches!(result, ValidationResult::Valid(None)));
Ok(())
diff --git a/datafusion-examples/examples/data_io/parquet_advanced_index.rs b/datafusion-examples/examples/data_io/parquet_advanced_index.rs
index 47c57a4804..43174bd76c 100644
--- a/datafusion-examples/examples/data_io/parquet_advanced_index.rs
+++ b/datafusion-examples/examples/data_io/parquet_advanced_index.rs
@@ -406,7 +406,8 @@ impl IndexedFile {
let file_size = path.metadata()?.len();
let file = File::open(path).map_err(|e| {
- DataFusionError::from(e).context(format!("Error opening file {path:?}"))
+ DataFusionError::from(e)
+ .context(format!("Error opening file {}", path.display()))
})?;
let options = ArrowReaderOptions::new()
@@ -583,7 +584,7 @@ impl ParquetFileReaderFactory for CachedParquetFileReaderFactory {
let metadata = self
.metadata
.get(&filename)
- .expect("metadata for file not found: {filename}");
+ .unwrap_or_else(|| panic!("metadata for file not found: {filename}"));
Ok(Box::new(ParquetReaderWithCache {
filename,
metadata: Arc::clone(metadata),
diff --git a/datafusion-examples/examples/data_io/parquet_index.rs b/datafusion-examples/examples/data_io/parquet_index.rs
index c8ae7e14c4..b2b9fe877a 100644
--- a/datafusion-examples/examples/data_io/parquet_index.rs
+++ b/datafusion-examples/examples/data_io/parquet_index.rs
@@ -501,7 +501,8 @@ impl ParquetMetadataIndexBuilder {
let file_size = file.metadata()?.len();
let file = File::open(file).map_err(|e| {
- DataFusionError::from(e).context(format!("Error opening file {file:?}"))
+ DataFusionError::from(e)
+ .context(format!("Error opening file {}", file.display()))
})?;
let reader = ParquetRecordBatchReaderBuilder::try_new(file)?;
@@ -621,12 +622,15 @@ fn read_dir(dir: &Path) -> Result<Vec<DirEntry>> {
let mut files = dir
.read_dir()
.map_err(|e| {
- DataFusionError::from(e).context(format!("Error reading directory {dir:?}"))
+ DataFusionError::from(e)
+ .context(format!("Error reading directory {}", dir.display()))
})?
.map(|entry| {
entry.map_err(|e| {
- DataFusionError::from(e)
- .context(format!("Error reading directory entry in {dir:?}"))
+ DataFusionError::from(e).context(format!(
+ "Error reading directory entry in {}",
+ dir.display()
+ ))
})
})
.collect::<Result<Vec<DirEntry>>>()?;
diff --git a/datafusion-examples/examples/proto/composed_extension_codec.rs b/datafusion-examples/examples/proto/composed_extension_codec.rs
index 51c1bc7c55..d3bcdc73df 100644
--- a/datafusion-examples/examples/proto/composed_extension_codec.rs
+++ b/datafusion-examples/examples/proto/composed_extension_codec.rs
@@ -160,7 +160,7 @@ impl PhysicalExtensionCodec for ParentPhysicalExtensionCodec {
_ctx: &TaskContext,
_proto_converter: &dyn PhysicalProtoConverterExtension,
) -> Result<Arc<dyn ExecutionPlan>> {
- if buf == "ParentExec".as_bytes() {
+ if buf == b"ParentExec" {
Ok(Arc::new(ParentExec {
input: inputs[0].clone(),
}))
@@ -176,7 +176,7 @@ impl PhysicalExtensionCodec for ParentPhysicalExtensionCodec {
_proto_converter: &dyn PhysicalProtoConverterExtension,
) -> Result<()> {
if node.is::<ParentExec>() {
- buf.extend_from_slice("ParentExec".as_bytes());
+ buf.extend_from_slice(b"ParentExec");
Ok(())
} else {
internal_err!("Not supported")
@@ -258,7 +258,7 @@ impl PhysicalExtensionCodec for ChildPhysicalExtensionCodec {
_ctx: &TaskContext,
_proto_converter: &dyn PhysicalProtoConverterExtension,
) -> Result<Arc<dyn ExecutionPlan>> {
- if buf == "ChildExec".as_bytes() {
+ if buf == b"ChildExec" {
Ok(Arc::new(ChildExec {}))
} else {
internal_err!("Not supported")
@@ -272,7 +272,7 @@ impl PhysicalExtensionCodec for ChildPhysicalExtensionCodec {
_proto_converter: &dyn PhysicalProtoConverterExtension,
) -> Result<()> {
if node.is::<ChildExec>() {
- buf.extend_from_slice("ChildExec".as_bytes());
+ buf.extend_from_slice(b"ChildExec");
Ok(())
} else {
internal_err!("Not supported")
diff --git a/datafusion/catalog-listing/src/table.rs b/datafusion/catalog-listing/src/table.rs
index 1749cdac2f..7f5d38b999 100644
--- a/datafusion/catalog-listing/src/table.rs
+++ b/datafusion/catalog-listing/src/table.rs
@@ -583,10 +583,10 @@ impl ListingTable {
Box::pin(self.scan_with_args_inner(state, args))
}
- async fn scan_with_args_inner<'a>(
+ async fn scan_with_args_inner(
&self,
state: &dyn Session,
- args: ScanArgs<'a>,
+ args: ScanArgs<'_>,
) -> datafusion_common::Result<ScanResult> {
let projection = args.projection().map(|p| p.to_vec());
let filters = args.filters().map(|f| f.to_vec()).unwrap_or_default();
diff --git a/datafusion/catalog/src/cte_worktable.rs b/datafusion/catalog/src/cte_worktable.rs
index 5f5094793c..9180e01043 100644
--- a/datafusion/catalog/src/cte_worktable.rs
+++ b/datafusion/catalog/src/cte_worktable.rs
@@ -128,10 +128,10 @@ impl TableProvider for CteWorkTable {
}
impl CteWorkTable {
- fn scan_with_args_inner<'a>(
+ fn scan_with_args_inner(
&self,
_state: &dyn Session,
- args: &ScanArgs<'a>,
+ args: &ScanArgs<'_>,
) -> Result<ScanResult> {
Ok(ScanResult::new(Arc::new(WorkTableExec::new(
self.name.clone(),
diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs
index cb0442392a..bef46702b8 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -10327,22 +10327,19 @@ mod tests {
const SECS_IN_ONE_DAY: i32 = 86_400;
const MICROSECS_IN_ONE_DAY: i64 = 86_400_000_000;
for i in 0..vector_size {
+ let days = rng.random_range(0..5000);
if i % 4 == 0 {
- let days = rng.random_range(0..5000);
// to not break second precision
let millis = rng.random_range(0..SECS_IN_ONE_DAY) * 1000;
intervals.push(ScalarValue::new_interval_dt(days, millis));
} else if i % 4 == 1 {
- let days = rng.random_range(0..5000);
let millisec = rng.random_range(0..(MILLISECS_IN_ONE_DAY as i32));
intervals.push(ScalarValue::new_interval_dt(days, millisec));
} else if i % 4 == 2 {
- let days = rng.random_range(0..5000);
// to not break microsec precision
let nanosec = rng.random_range(0..MICROSECS_IN_ONE_DAY) * 1000;
intervals.push(ScalarValue::new_interval_mdn(0, days, nanosec));
} else {
- let days = rng.random_range(0..5000);
let nanosec = rng.random_range(0..NANOSECS_IN_ONE_DAY);
intervals.push(ScalarValue::new_interval_mdn(0, days, nanosec));
}
diff --git a/datafusion/common/src/utils/mod.rs b/datafusion/common/src/utils/mod.rs
index 8df160187a..71bd87b54d 100644
--- a/datafusion/common/src/utils/mod.rs
+++ b/datafusion/common/src/utils/mod.rs
@@ -950,7 +950,7 @@ pub mod datafusion_strsim {
let mut distance_b = i;
for (j, b_elem) in b.into_iter().enumerate() {
- let cost = if a_elem == b_elem { 0usize } else { 1usize };
+ let cost = usize::from(a_elem != b_elem);
let distance_a = distance_b + cost;
distance_b = cache[j];
result = min(result + 1, min(distance_a, distance_b + 1));
diff --git a/datafusion/core/benches/topk_aggregate.rs b/datafusion/core/benches/topk_aggregate.rs
index d8ca0d58b8..8fc6c954ca 100644
--- a/datafusion/core/benches/topk_aggregate.rs
+++ b/datafusion/core/benches/topk_aggregate.rs
@@ -335,6 +335,10 @@ fn assert_string_results_match(
}
}
+#[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `{rows}`/`{limit}` placeholders are substituted with `str::replace`"
+)]
fn criterion_benchmark(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
let limit = LIMIT;
diff --git a/datafusion/core/src/bin/print_functions_docs.rs b/datafusion/core/src/bin/print_functions_docs.rs
index 86f433ac8e..c4b5fc4ef6 100644
--- a/datafusion/core/src/bin/print_functions_docs.rs
+++ b/datafusion/core/src/bin/print_functions_docs.rs
@@ -34,12 +34,11 @@ use std::sync::Arc;
fn main() -> Result<()> {
let args: Vec<String> = args().collect();
- if args.len() != 2 {
- panic!(
- "Usage: {} type (one of 'aggregate', 'scalar', 'window')",
- args[0]
- );
- }
+ assert!(
+ args.len() == 2,
+ "Usage: {} type (one of 'aggregate', 'scalar', 'window')",
+ args[0]
+ );
let function_type = args[1].trim().to_lowercase();
let docs = match function_type.as_str() {
diff --git a/datafusion/core/src/dataframe/parquet.rs b/datafusion/core/src/dataframe/parquet.rs
index 83ffbb1517..1685dff23d 100644
--- a/datafusion/core/src/dataframe/parquet.rs
+++ b/datafusion/core/src/dataframe/parquet.rs
@@ -221,8 +221,7 @@ mod tests {
// relative to datafusion.execution.batch_size does not panic
let ctx = SessionContext::new_with_config(SessionConfig::from_string_hash_map(
&HashMap::from_iter(
- [("datafusion.execution.batch_size", "10")]
- .iter()
+ std::iter::once(&("datafusion.execution.batch_size", "10"))
.map(|(s1, s2)| ((*s1).to_string(), (*s2).to_string())),
),
)?);
diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs
index f5a76c2cf5..982766dc88 100644
--- a/datafusion/core/src/datasource/listing/table.rs
+++ b/datafusion/core/src/datasource/listing/table.rs
@@ -76,18 +76,18 @@ impl ListingTableConfigExt for ListingTableConfig {
}
/// Body of [`ListingTableConfigExt::infer`].
-fn infer_boxed<'a>(
+fn infer_boxed(
config: ListingTableConfig,
- state: &'a dyn Session,
-) -> BoxFuture<'a, datafusion_common::Result<ListingTableConfig>> {
+ state: &dyn Session,
+) -> BoxFuture<'_, datafusion_common::Result<ListingTableConfig>> {
Box::pin(async move { config.infer_options(state).await?.infer_schema(state).await })
}
/// Body of [`ListingTableConfigExt::infer_options`].
-fn infer_options_boxed<'a>(
+fn infer_options_boxed(
config: ListingTableConfig,
- state: &'a dyn Session,
-) -> BoxFuture<'a, datafusion_common::Result<ListingTableConfig>> {
+ state: &dyn Session,
+) -> BoxFuture<'_, datafusion_common::Result<ListingTableConfig>> {
Box::pin(async move {
let store = if let Some(url) = config.table_paths.first() {
state.runtime_env().object_store(url)?
diff --git a/datafusion/core/src/datasource/physical_plan/csv.rs b/datafusion/core/src/datasource/physical_plan/csv.rs
index 56642d583e..7980df87fa 100644
--- a/datafusion/core/src/datasource/physical_plan/csv.rs
+++ b/datafusion/core/src/datasource/physical_plan/csv.rs
@@ -780,9 +780,10 @@ mod tests {
}
}
- if part_0_name.is_empty() {
- panic!("Did not find part_0 in csv output files!")
- }
+ assert!(
+ !part_0_name.is_empty(),
+ "Did not find part_0 in csv output files!"
+ );
// register each partition as well as the top level dir
let csv_read_option = CsvReadOptions::new().schema(&schema).has_header(false);
ctx.register_csv(
diff --git a/datafusion/core/src/datasource/physical_plan/json.rs b/datafusion/core/src/datasource/physical_plan/json.rs
index b70791c7b2..6b4361e0c4 100644
--- a/datafusion/core/src/datasource/physical_plan/json.rs
+++ b/datafusion/core/src/datasource/physical_plan/json.rs
@@ -426,9 +426,10 @@ mod tests {
}
}
- if part_0_name.is_empty() {
- panic!("Did not find part_0 in json output files!")
- }
+ assert!(
+ !part_0_name.is_empty(),
+ "Did not find part_0 in json output files!"
+ );
// register each partition as well as the top level dir
let json_read_option = JsonReadOptions::default();
diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs
index 5b287f103a..78497604da 100644
--- a/datafusion/core/src/execution/context/mod.rs
+++ b/datafusion/core/src/execution/context/mod.rs
@@ -1107,9 +1107,7 @@ impl SessionContext {
}
fn set_variable(&self, stmt: SetVariable) -> Result<()> {
- let SetVariable {
- variable, value, ..
- } = stmt;
+ let SetVariable { variable, value } = stmt;
// Check if this is a runtime configuration
if variable.starts_with("datafusion.runtime.") {
@@ -1551,9 +1549,7 @@ impl SessionContext {
}
fn execute_prepared(&self, execute: Execute) -> Result<DataFrame> {
- let Execute {
- name, parameters, ..
- } = execute;
+ let Execute { name, parameters } = execute;
let prepared = self.state.read().get_prepared(&name).ok_or_else(|| {
exec_datafusion_err!("Prepared statement '{}' does not exist", name)
})?;
@@ -2959,8 +2955,8 @@ mod tests {
// Valid durations
for (duration, want) in [
("1s", Duration::from_secs(1)),
- ("1m", Duration::from_secs(60)),
- ("1m0s", Duration::from_secs(60)),
+ ("1m", Duration::from_mins(1)),
+ ("1m0s", Duration::from_mins(1)),
("1m1s", Duration::from_secs(61)),
] {
let have =
@@ -2985,6 +2981,10 @@ mod tests {
}
#[test]
+ #[expect(
+ clippy::duration_suboptimal_units,
+ reason = "Each `Duration` deliberately uses the same unit as the suffix in the string it is parsed from"
+ )]
fn test_parse_duration_with_overflow_check() {
const LIST_FILES_CACHE_TTL: &str = "datafusion.runtime.list_files_cache_ttl";
@@ -2996,7 +2996,7 @@ mod tests {
),
(
"307445734561825860m",
- Duration::from_secs(307445734561825860 * 60),
+ Duration::from_mins(307445734561825860),
),
(
"307445734561825860m10s",
diff --git a/datafusion/core/src/execution/context/parquet.rs b/datafusion/core/src/execution/context/parquet.rs
index 3c750352f1..aad8518ba4 100644
--- a/datafusion/core/src/execution/context/parquet.rs
+++ b/datafusion/core/src/execution/context/parquet.rs
@@ -314,12 +314,7 @@ mod tests {
// Read the dataframe from 'output1.parquet' with the default file extension.
let read_df = ctx
- .read_parquet(
- &path1,
- ParquetReadOptions {
- ..Default::default()
- },
- )
+ .read_parquet(&path1, ParquetReadOptions::default())
.await?;
let results = read_df.collect().await?;
@@ -342,12 +337,7 @@ mod tests {
// Read the dataframe from 'output3.parquet.snappy.parquet' with the wrong file extension.
let read_df = ctx
- .read_parquet(
- &path2,
- ParquetReadOptions {
- ..Default::default()
- },
- )
+ .read_parquet(&path2, ParquetReadOptions::default())
.await;
let binding = DataFilePaths::to_urls(&path2).unwrap();
let expected_path = binding[0].as_str();
@@ -360,12 +350,7 @@ mod tests {
// Read the dataframe from 'output3.parquet.snappy.parquet' with the correct file extension.
let read_df = ctx
- .read_parquet(
- &path3,
- ParquetReadOptions {
- ..Default::default()
- },
- )
+ .read_parquet(&path3, ParquetReadOptions::default())
.await?;
let results = read_df.collect().await?;
@@ -376,12 +361,7 @@ mod tests {
// errors on an empty location instead of producing a 0-column table.
std::fs::create_dir(&path4)?;
let err = ctx
- .read_parquet(
- &path4,
- ParquetReadOptions {
- ..Default::default()
- },
- )
+ .read_parquet(&path4, ParquetReadOptions::default())
.await
.expect_err("read_parquet on an empty folder should error");
assert!(
@@ -391,12 +371,7 @@ mod tests {
// Read the dataframe from double dot folder;
let read_df = ctx
- .read_parquet(
- &path5,
- ParquetReadOptions {
- ..Default::default()
- },
- )
+ .read_parquet(&path5, ParquetReadOptions::default())
.await?;
let results = read_df.collect().await?;
diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs
index 7002a4b04d..bd1c29aa6d 100644
--- a/datafusion/core/src/physical_planner.rs
+++ b/datafusion/core/src/physical_planner.rs
@@ -1243,9 +1243,7 @@ impl DefaultPhysicalPlanner {
physical_partitioning,
)?)
}
- LogicalPlan::Sort(Sort {
- expr, input, fetch, ..
- }) => {
+ LogicalPlan::Sort(Sort { expr, input, fetch }) => {
let physical_input = children.one()?;
let input_dfschema = input.as_ref().schema();
let sort_exprs = create_physical_sort_exprs(
diff --git a/datafusion/core/tests/custom_sources_cases/provider_filter_pushdown.rs b/datafusion/core/tests/custom_sources_cases/provider_filter_pushdown.rs
index 51d31360f6..d4693b025a 100644
--- a/datafusion/core/tests/custom_sources_cases/provider_filter_pushdown.rs
+++ b/datafusion/core/tests/custom_sources_cases/provider_filter_pushdown.rs
@@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-use std::ops::Deref;
use std::sync::Arc;
use arrow::array::{Int32Builder, Int64Array};
@@ -204,7 +203,7 @@ impl TableProvider for CustomProvider {
Expr::Literal(ScalarValue::Int16(Some(i)), _) => *i as i64,
Expr::Literal(ScalarValue::Int32(Some(i)), _) => *i as i64,
Expr::Literal(ScalarValue::Int64(Some(i)), _) => *i,
- Expr::Cast(Cast { expr, field: _ }) => match expr.deref() {
+ Expr::Cast(Cast { expr, field: _ }) => match &**expr {
Expr::Literal(lit_value, _) => match lit_value {
ScalarValue::Int8(Some(v)) => *v as i64,
ScalarValue::Int16(Some(v)) => *v as i64,
diff --git a/datafusion/core/tests/dataframe/mod.rs b/datafusion/core/tests/dataframe/mod.rs
index 4966c7aa9a..44ab14e6cc 100644
--- a/datafusion/core/tests/dataframe/mod.rs
+++ b/datafusion/core/tests/dataframe/mod.rs
@@ -3303,6 +3303,10 @@ async fn union_with_mix_of_presorted_and_explicitly_resorted_inputs_with_reparti
Ok(())
}
+#[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The `{testdata}` placeholder is substituted with `str::replace`"
+)]
async fn union_with_mix_of_presorted_and_explicitly_resorted_inputs_impl(
repartition_sorts: bool,
) -> Result<String> {
diff --git a/datafusion/core/tests/datasource/object_store_access.rs b/datafusion/core/tests/datasource/object_store_access.rs
index 2503de862e..2ed97abb02 100644
--- a/datafusion/core/tests/datasource/object_store_access.rs
+++ b/datafusion/core/tests/datasource/object_store_access.rs
@@ -929,6 +929,10 @@ struct Test {
/// * `None`: uses the default (does not set a size_hint)
/// * `Some(None)`L: set prefetch hint to None (prefetching)
/// * `Some(Some(size))`: set prefetch hint to size
+ #[expect(
+ clippy::option_option,
+ reason = "The nesting is meaningful, see the doc comment above"
+ )]
parquet_metadata_size_hint: Option<Option<usize>>,
}
diff --git a/datafusion/core/tests/execution/logical_plan.rs b/datafusion/core/tests/execution/logical_plan.rs
index 3eaa3fb2ed..79d8b30610 100644
--- a/datafusion/core/tests/execution/logical_plan.rs
+++ b/datafusion/core/tests/execution/logical_plan.rs
@@ -86,7 +86,7 @@ async fn count_only_nulls() -> Result<()> {
let column = only(result.columns());
assert_eq!(field.data_type(), &DataType::Int64); // TODO should be UInt64
- assert_eq!(column.deref(), &Int64Array::from(vec![0]));
+ assert_eq!(&**column, &Int64Array::from(vec![0]));
Ok(())
}
diff --git a/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs b/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs
index 316cb177fa..80df91cb10 100644
--- a/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs
+++ b/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs
@@ -259,12 +259,11 @@ async fn run_query(
let result =
run_query_with_config(&query, cfg_with_dynamic_filters, dataset.clone()).await;
// Check that dynamic filters were actually pushed down
- if !has_dynamic_filter_expr_pushdown(&result.explain_plan) {
- panic!(
- "Dynamic filter was not pushed down in query: {query}\n\n{}",
- result.explain_plan
- );
- }
+ assert!(
+ has_dynamic_filter_expr_pushdown(&result.explain_plan),
+ "Dynamic filter was not pushed down in query: {query}\n\n{}",
+ result.explain_plan
+ );
RunQueryResult {
query: query.to_string(),
diff --git a/datafusion/core/tests/memory_limit/memory_limit_validation/sort_mem_validation.rs b/datafusion/core/tests/memory_limit/memory_limit_validation/sort_mem_validation.rs
index b55a3039ec..689915f4aa 100644
--- a/datafusion/core/tests/memory_limit/memory_limit_validation/sort_mem_validation.rs
+++ b/datafusion/core/tests/memory_limit/memory_limit_validation/sort_mem_validation.rs
@@ -163,7 +163,7 @@ async fn sort_with_mem_limit_2_cols_1() {
// TODO: Query fails, fix it
// Issue: https://github.com/apache/datafusion/issues/14143
-#[ignore]
+#[ignore = "Query fails, see the issue above"]
#[tokio::test]
async fn sort_with_mem_limit_2_cols_2() {
let memory_usage_in_theory = 80_000_000 * 2; // 2 columns
diff --git a/datafusion/core/tests/memory_limit/mod.rs b/datafusion/core/tests/memory_limit/mod.rs
index 472ff07aac..bf52c4ab0f 100644
--- a/datafusion/core/tests/memory_limit/mod.rs
+++ b/datafusion/core/tests/memory_limit/mod.rs
@@ -941,11 +941,10 @@ impl TestCase {
match df.collect().await {
Ok(_batches) => {
- if !expected_success {
- panic!(
- "Unexpected success when running, expected memory limit failure"
- )
- }
+ assert!(
+ expected_success,
+ "Unexpected success when running, expected memory limit failure"
+ );
}
Err(e) => {
if expected_success {
diff --git a/datafusion/core/tests/parquet/encryption.rs b/datafusion/core/tests/parquet/encryption.rs
index 12bdb600c2..a59871f30e 100644
--- a/datafusion/core/tests/parquet/encryption.rs
+++ b/datafusion/core/tests/parquet/encryption.rs
@@ -41,10 +41,10 @@ use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::{Arc, Mutex};
use tempfile::TempDir;
-async fn read_parquet_test_data<'a, T: Into<String>>(
+async fn read_parquet_test_data<T: Into<String>>(
path: T,
ctx: &SessionContext,
- options: ParquetReadOptions<'a>,
+ options: ParquetReadOptions<'_>,
) -> Vec<RecordBatch> {
ctx.read_parquet(path.into(), options)
.await
diff --git a/datafusion/core/tests/sql/aggregates/basic.rs b/datafusion/core/tests/sql/aggregates/basic.rs
index 3e5dc6a0b1..0cf40a9172 100644
--- a/datafusion/core/tests/sql/aggregates/basic.rs
+++ b/datafusion/core/tests/sql/aggregates/basic.rs
@@ -401,8 +401,8 @@ async fn count_distinct_dictionary_all_null_values() -> Result<()> {
/// Test COUNT(DISTINCT) with mixed null and non-null dictionary values
#[tokio::test]
async fn count_distinct_dictionary_mixed_values() -> Result<()> {
- let n: usize = 6;
- let num = Arc::new(Int32Array::from_iter(0..n as i32)) as ArrayRef;
+ let n: i32 = 6;
+ let num = Arc::new(Int32Array::from_iter(0..n)) as ArrayRef;
// Dictionary values array with nulls and non-nulls
let dict_values = StringArray::from(vec![None, Some("abc"), Some("def"), None]);
diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs
index 7c0e89ee96..bb526895b6 100644
--- a/datafusion/core/tests/sql/joins.rs
+++ b/datafusion/core/tests/sql/joins.rs
@@ -39,8 +39,7 @@ async fn join_change_in_planner() -> Result<()> {
]));
// Specify the ordering:
let file_sort_order = vec![
- [col("a1")]
- .into_iter()
+ std::iter::once(col("a1"))
.map(|e| {
let ascending = true;
let nulls_first = false;
@@ -98,8 +97,7 @@ async fn join_no_order_on_filter() -> Result<()> {
]));
// Specify the ordering:
let file_sort_order = vec![
- [col("a1")]
- .into_iter()
+ std::iter::once(col("a1"))
.map(|e| {
let ascending = true;
let nulls_first = false;
@@ -225,7 +223,7 @@ async fn join_using_uppercase_column() -> Result<()> {
let tmp_dir = TempDir::new()?;
let file_path = tmp_dir.path().join("uppercase-column.csv");
let mut file = File::create(file_path.clone())?;
- file.write_all("0".as_bytes())?;
+ file.write_all(b"0")?;
drop(file);
let ctx = SessionContext::new();
diff --git a/datafusion/core/tests/sql/runtime_config.rs b/datafusion/core/tests/sql/runtime_config.rs
index b0e4bccf30..1275edc6d8 100644
--- a/datafusion/core/tests/sql/runtime_config.rs
+++ b/datafusion/core/tests/sql/runtime_config.rs
@@ -368,7 +368,7 @@ async fn test_list_files_cache_ttl() {
};
update_limit(&ctx, "1m").await;
- assert_eq!(get_limit(&ctx), Duration::from_secs(60));
+ assert_eq!(get_limit(&ctx), Duration::from_mins(1));
update_limit(&ctx, "30s").await;
assert_eq!(get_limit(&ctx), Duration::from_secs(30));
diff --git a/datafusion/core/tests/sql/unparser.rs b/datafusion/core/tests/sql/unparser.rs
index 355a58fd6f..3982c60dbc 100644
--- a/datafusion/core/tests/sql/unparser.rs
+++ b/datafusion/core/tests/sql/unparser.rs
@@ -970,14 +970,13 @@ async fn run_roundtrip_tests<F, Fut>(
println!("\x1b[32m✓\x1b[0m {} query: {}", suite_name, sql.name);
}
}
- if !errors.is_empty() {
- panic!(
- "{} {} test(s) failed:\n\n{}",
- errors.len(),
- suite_name,
- errors.join("\n\n---\n\n")
- );
- }
+ assert!(
+ errors.is_empty(),
+ "{} {} test(s) failed:\n\n{}",
+ errors.len(),
+ suite_name,
+ errors.join("\n\n---\n\n")
+ )
}
#[tokio::test]
diff --git a/datafusion/core/tests/tracing/asserting_tracer.rs b/datafusion/core/tests/tracing/asserting_tracer.rs
index 700f9f3308..a73a7f28c8 100644
--- a/datafusion/core/tests/tracing/asserting_tracer.rs
+++ b/datafusion/core/tests/tracing/asserting_tracer.rs
@@ -17,7 +17,6 @@
use std::any::Any;
use std::collections::VecDeque;
-use std::ops::Deref;
use std::sync::{Arc, LazyLock};
use datafusion_common::{HashMap, HashSet};
@@ -28,7 +27,7 @@ use tokio::sync::{Mutex, MutexGuard};
/// Initializes the global join set tracer with the asserting tracer.
/// Call this function before spawning any tasks that should be traced.
pub fn init_asserting_tracer() {
- set_join_set_tracer(ASSERTING_TRACER.deref())
+ set_join_set_tracer(&*ASSERTING_TRACER)
.expect("Failed to initialize asserting tracer");
}
diff --git a/datafusion/core/tests/user_defined/user_defined_aggregates.rs b/datafusion/core/tests/user_defined/user_defined_aggregates.rs
index 323925bcfa..d035fa25e1 100644
--- a/datafusion/core/tests/user_defined/user_defined_aggregates.rs
+++ b/datafusion/core/tests/user_defined/user_defined_aggregates.rs
@@ -1019,8 +1019,7 @@ async fn test_metadata_based_aggregate() -> Result<()> {
let schema = Arc::new(Schema::new(vec![
Field::new("no_metadata", DataType::UInt64, true),
Field::new("with_metadata", DataType::UInt64, true).with_metadata(
- [("modify_values".to_string(), "double_output".to_string())]
- .into_iter()
+ std::iter::once(("modify_values".to_string(), "double_output".to_string()))
.collect(),
),
]));
@@ -1037,8 +1036,7 @@ async fn test_metadata_based_aggregate() -> Result<()> {
let no_output_meta_udf =
AggregateUDF::from(MetadataBasedAggregateUdf::new(HashMap::new()));
let with_output_meta_udf = AggregateUDF::from(MetadataBasedAggregateUdf::new(
- [("output_metatype".to_string(), "custom_value".to_string())]
- .into_iter()
+ std::iter::once(("output_metatype".to_string(), "custom_value".to_string()))
.collect(),
));
@@ -1094,8 +1092,7 @@ async fn test_metadata_based_aggregate_as_window() -> Result<()> {
let schema = Arc::new(Schema::new(vec![
Field::new("no_metadata", DataType::UInt64, true),
Field::new("with_metadata", DataType::UInt64, true).with_metadata(
- [("modify_values".to_string(), "double_output".to_string())]
- .into_iter()
+ std::iter::once(("modify_values".to_string(), "double_output".to_string()))
.collect(),
),
]));
@@ -1114,8 +1111,7 @@ async fn test_metadata_based_aggregate_as_window() -> Result<()> {
));
let with_output_meta_udf =
Arc::new(AggregateUDF::from(MetadataBasedAggregateUdf::new(
- [("output_metatype".to_string(), "custom_value".to_string())]
- .into_iter()
+ std::iter::once(("output_metatype".to_string(), "custom_value".to_string()))
.collect(),
)));
diff --git a/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs b/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
index b758aeb520..da71ffb10e 100644
--- a/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
+++ b/datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
@@ -1646,8 +1646,7 @@ async fn test_metadata_based_udf() -> Result<()> {
let schema = Arc::new(Schema::new(vec![
Field::new("no_metadata", DataType::UInt64, true),
Field::new("with_metadata", DataType::UInt64, true).with_metadata(
- [("modify_values".to_string(), "double_output".to_string())]
- .into_iter()
+ std::iter::once(("modify_values".to_string(), "double_output".to_string()))
.collect(),
),
]));
@@ -1661,8 +1660,7 @@ async fn test_metadata_based_udf() -> Result<()> {
let t = ctx.table("t").await?;
let no_output_meta_udf = ScalarUDF::from(MetadataBasedUdf::new(HashMap::new()));
let with_output_meta_udf = ScalarUDF::from(MetadataBasedUdf::new(
- [("output_metatype".to_string(), "custom_value".to_string())]
- .into_iter()
+ std::iter::once(("output_metatype".to_string(), "custom_value".to_string()))
.collect(),
));
@@ -1716,8 +1714,7 @@ async fn test_metadata_based_udf() -> Result<()> {
async fn test_metadata_based_udf_with_literal() -> Result<()> {
let ctx = SessionContext::new();
let input_metadata: HashMap<String, String> =
- [("modify_values".to_string(), "double_output".to_string())]
- .into_iter()
+ std::iter::once(("modify_values".to_string(), "double_output".to_string()))
.collect();
let input_metadata = FieldMetadata::from(input_metadata);
let df = ctx.sql("select 0;").await?.select(vec![
@@ -1728,8 +1725,7 @@ async fn test_metadata_based_udf_with_literal() -> Result<()> {
])?;
let output_metadata: HashMap<String, String> =
- [("output_metatype".to_string(), "custom_value".to_string())]
- .into_iter()
+ std::iter::once(("output_metatype".to_string(), "custom_value".to_string()))
.collect();
let custom_udf = ScalarUDF::from(MetadataBasedUdf::new(output_metadata.clone()));
@@ -1820,11 +1816,11 @@ impl ScalarUDFImpl for ExtensionBasedUdf {
// If we have the extension type set, we are outputting a boolean value.
// Otherwise we output a string representation of the numeric value.
- fn print_value(v: Option<i8>, as_bool: bool) -> Option<String> {
- v.map(|x| match as_bool {
+ fn print_value(x: i8, as_bool: bool) -> String {
+ match as_bool {
true => format!("{}", x != 0),
false => format!("{x}"),
- })
+ }
}
match &args.args[0] {
@@ -1834,7 +1830,7 @@ impl ScalarUDFImpl for ExtensionBasedUdf {
.downcast_ref::<Int8Array>()
.unwrap()
.iter()
- .map(|v| print_value(v, output_as_bool))
+ .map(|v| v.map(|v| print_value(v, output_as_bool)))
.collect();
let array_ref = Arc::new(StringArray::from(array_values)) as ArrayRef;
Ok(ColumnarValue::Array(array_ref))
@@ -1844,10 +1840,9 @@ impl ScalarUDFImpl for ExtensionBasedUdf {
return exec_err!("incorrect data type");
};
- Ok(ColumnarValue::Scalar(ScalarValue::Utf8(print_value(
- *value,
- output_as_bool,
- ))))
+ Ok(ColumnarValue::Scalar(ScalarValue::Utf8(
+ value.map(|v| print_value(v, output_as_bool)),
+ )))
}
}
}
@@ -1877,7 +1872,7 @@ impl ExtensionType for MyUserExtensionType {
&self,
data_type: &DataType,
) -> std::result::Result<(), ArrowError> {
- if let DataType::Utf8 = data_type {
+ if *data_type == DataType::Utf8 {
Ok(())
} else {
Err(ArrowError::InvalidArgumentError(
diff --git a/datafusion/core/tests/user_defined/user_defined_window_functions.rs b/datafusion/core/tests/user_defined/user_defined_window_functions.rs
index afaf269ca1..fc14b9a1c6 100644
--- a/datafusion/core/tests/user_defined/user_defined_window_functions.rs
+++ b/datafusion/core/tests/user_defined/user_defined_window_functions.rs
@@ -869,8 +869,7 @@ async fn test_metadata_based_window_fn() -> Result<()> {
let schema = Arc::new(Schema::new(vec![
Field::new("no_metadata", DataType::UInt64, true),
Field::new("with_metadata", DataType::UInt64, true).with_metadata(
- [("modify_values".to_string(), "double_output".to_string())]
- .into_iter()
+ std::iter::once(("modify_values".to_string(), "double_output".to_string()))
.collect(),
),
]));
@@ -886,8 +885,7 @@ async fn test_metadata_based_window_fn() -> Result<()> {
let no_output_meta_udf = WindowUDF::from(MetadataBasedWindowUdf::new(HashMap::new()));
let with_output_meta_udf = WindowUDF::from(MetadataBasedWindowUdf::new(
- [("output_metatype".to_string(), "custom_value".to_string())]
- .into_iter()
+ std::iter::once(("output_metatype".to_string(), "custom_value".to_string()))
.collect(),
));
diff --git a/datafusion/datasource-arrow/src/source.rs b/datafusion/datasource-arrow/src/source.rs
index dd973c03ae..dff3c6ffae 100644
--- a/datafusion/datasource-arrow/src/source.rs
+++ b/datafusion/datasource-arrow/src/source.rs
@@ -315,7 +315,7 @@ impl FileSource for ArrowSource {
}
fn with_batch_size(&self, _batch_size: usize) -> Arc<dyn FileSource> {
- Arc::new(Self { ..self.clone() })
+ Arc::new(self.clone())
}
fn metrics(&self) -> &ExecutionPlanMetricsSet {
diff --git a/datafusion/datasource-avro/src/source.rs b/datafusion/datasource-avro/src/source.rs
index fcc50b559f..db98e167ab 100644
--- a/datafusion/datasource-avro/src/source.rs
+++ b/datafusion/datasource-avro/src/source.rs
@@ -412,14 +412,14 @@ mod tests {
assert_eq!(8, date_string_col.0);
assert_eq!(&DataType::Binary, date_string_col.1.data_type());
let col = get_col::<BinaryArray>(&batch, date_string_col).unwrap();
- assert_eq!("01/01/09".as_bytes(), col.value(0));
- assert_eq!("01/01/09".as_bytes(), col.value(1));
+ assert_eq!(b"01/01/09", col.value(0));
+ assert_eq!(b"01/01/09", col.value(1));
let string_col = schema.column_with_name("string_col").unwrap();
assert_eq!(9, string_col.0);
assert_eq!(&DataType::Binary, string_col.1.data_type());
let col = get_col::<BinaryArray>(&batch, string_col).unwrap();
- assert_eq!("0".as_bytes(), col.value(0));
- assert_eq!("1".as_bytes(), col.value(1));
+ assert_eq!(b"0", col.value(0));
+ assert_eq!(b"1", col.value(1));
let timestamp_col = schema.column_with_name("timestamp_col").unwrap();
assert_eq!(10, timestamp_col.0);
assert_eq!(
@@ -456,8 +456,8 @@ mod tests {
.as_any()
.downcast_ref::<BinaryArray>()
.unwrap();
- assert_eq!("0".as_bytes(), col.value(0));
- assert_eq!("1".as_bytes(), col.value(1));
+ assert_eq!(b"0", col.value(0));
+ assert_eq!(b"1", col.value(1));
// Second column should be double_col (was at index 7 in original)
assert_eq!("double_col", schema.field(1).name());
diff --git a/datafusion/datasource-parquet/src/metrics.rs b/datafusion/datasource-parquet/src/metrics.rs
index cbdcb73196..a3573c8624 100644
--- a/datafusion/datasource-parquet/src/metrics.rs
+++ b/datafusion/datasource-parquet/src/metrics.rs
@@ -215,22 +215,22 @@ impl ParquetFileMetrics {
files_ranges_pruned_statistics,
predicate_evaluation_errors,
row_groups_pruned_bloom_filter,
- row_groups_pruned_statistics,
limit_pruned_row_groups,
+ row_groups_pruned_statistics,
+ row_groups_pruned_dynamic_filter,
bytes_scanned,
pushdown_rows_pruned,
pushdown_rows_matched,
row_pushdown_eval_time,
- page_index_rows_pruned,
- page_index_pages_pruned,
statistics_eval_time,
bloom_filter_eval_time,
+ page_index_rows_pruned,
+ page_index_pages_pruned,
page_index_eval_time,
metadata_load_time,
scan_efficiency_ratio,
predicate_cache_inner_records,
predicate_cache_records,
- row_groups_pruned_dynamic_filter,
}
}
diff --git a/datafusion/datasource-parquet/src/opener/mod.rs b/datafusion/datasource-parquet/src/opener/mod.rs
index 693e9bd2cb..b3ce024d66 100644
--- a/datafusion/datasource-parquet/src/opener/mod.rs
+++ b/datafusion/datasource-parquet/src/opener/mod.rs
@@ -676,7 +676,7 @@ impl ParquetMorselPlanner {
impl MorselPlanner for ParquetMorselPlanner {
fn plan(self: Box<Self>) -> Result<Option<MorselPlan>> {
- if let ParquetOpenState::Done = self.state {
+ if matches!(self.state, ParquetOpenState::Done) {
return Ok(None);
}
diff --git a/datafusion/datasource/src/sink.rs b/datafusion/datasource/src/sink.rs
index 4bf04133b7..1557e41531 100644
--- a/datafusion/datasource/src/sink.rs
+++ b/datafusion/datasource/src/sink.rs
@@ -290,7 +290,7 @@ impl ExecutionPlan for DataSinkExec {
fn required_input_ordering(&self) -> Vec<Option<OrderingRequirements>> {
// The required input ordering is set externally (e.g. by a `ListingTable`).
// Otherwise, there is no specific requirement (i.e. `sort_order` is `None`).
- vec![self.sort_order.as_ref().cloned().map(Into::into)]
+ vec![self.sort_order.clone().map(Into::into)]
}
fn maintains_input_order(&self) -> Vec<bool> {
diff --git a/datafusion/datasource/src/test_util.rs b/datafusion/datasource/src/test_util.rs
index 20dfae5b3a..8b787aa104 100644
--- a/datafusion/datasource/src/test_util.rs
+++ b/datafusion/datasource/src/test_util.rs
@@ -91,7 +91,7 @@ impl FileSource for MockSource {
}
fn with_batch_size(&self, _batch_size: usize) -> Arc<dyn FileSource> {
- Arc::new(Self { ..self.clone() })
+ Arc::new(self.clone())
}
fn metrics(&self) -> &ExecutionPlanMetricsSet {
diff --git a/datafusion/execution/src/async_stream.rs b/datafusion/execution/src/async_stream.rs
index 7ca6ba4850..0462c53a0f 100644
--- a/datafusion/execution/src/async_stream.rs
+++ b/datafusion/execution/src/async_stream.rs
@@ -20,7 +20,6 @@ use futures::future::FusedFuture;
use futures::stream::FusedStream;
use parking_lot::Mutex;
use pin_project_lite::pin_project;
-use std::ops::DerefMut;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
@@ -181,7 +180,7 @@ impl<T> Emitter<T> {
/// nothing yields control back to the consumer in between.
fn set(&mut self, value: T) {
let mut guard = self.slot.lock();
- match guard.deref_mut() {
+ match &mut *guard {
Some(_) => panic!("Misuse: await was not called after calling emit"),
slot => *slot = Some(value),
}
@@ -200,7 +199,7 @@ impl<T, E> TryEmitter<T, E> {
/// Panics if called before the previous emit future has been awaited.
pub fn emit(&mut self, value: T) -> impl FusedFuture<Output = ()> {
let mut guard = self.slot.lock();
- match guard.deref_mut() {
+ match &mut *guard {
Some(_) => panic!("Misuse: await was not called after calling emit"),
slot => *slot = Some(Ok::<T, E>(value)),
}
diff --git a/datafusion/execution/src/cache/cache_manager.rs b/datafusion/execution/src/cache/cache_manager.rs
index 83dcf70975..5b8c098e3a 100644
--- a/datafusion/execution/src/cache/cache_manager.rs
+++ b/datafusion/execution/src/cache/cache_manager.rs
@@ -562,7 +562,7 @@ mod tests {
// Put cache in config WITH a different TTL set
let config = CacheManagerConfig::default()
.with_list_files_cache(Some(Arc::new(list_file_cache)))
- .with_list_files_cache_ttl(Some(Duration::from_secs(60)));
+ .with_list_files_cache_ttl(Some(Duration::from_mins(1)));
// Create CacheManager from config
let cache_manager = CacheManager::try_new(&config).unwrap();
@@ -572,7 +572,7 @@ mod tests {
assert_eq!(
cache_ttl,
- Some(Duration::from_secs(60)),
+ Some(Duration::from_mins(1)),
"TTL should be overridden to 60 seconds when set in config"
);
}
diff --git a/datafusion/execution/src/task.rs b/datafusion/execution/src/task.rs
index 1c1a717d19..184bae502e 100644
--- a/datafusion/execution/src/task.rs
+++ b/datafusion/execution/src/task.rs
@@ -104,8 +104,8 @@ impl TaskContext {
runtime: Arc<RuntimeEnv>,
) -> Self {
Self {
- task_id,
session_id,
+ task_id,
session_config,
scalar_functions,
higher_order_functions,
diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs
index 8927fcf4d0..ee70e90153 100644
--- a/datafusion/expr/src/expr_schema.rs
+++ b/datafusion/expr/src/expr_schema.rs
@@ -284,56 +284,51 @@ impl ExprSchemable for Expr {
Expr::OuterReferenceColumn(field, _) => Ok(field.is_nullable()),
Expr::Literal(value, _) => Ok(value.is_null()),
Expr::Case(case) => {
- let nullable_then = case
- .when_then_expr
- .iter()
- .filter_map(|(w, t)| {
- let is_nullable = match t.nullable(input_schema) {
- Err(e) => return Some(Err(e)),
- Ok(n) => n,
- };
-
- // Branches with a then expression that is not nullable do not impact the
- // nullability of the case expression.
- if !is_nullable {
- return None;
- }
-
- // For case-with-expression assume all 'then' expressions are reachable
- if case.expr.is_some() {
- return Some(Ok(()));
- }
+ let nullable_then = case.when_then_expr.iter().find_map(|(w, t)| {
+ let is_nullable = match t.nullable(input_schema) {
+ Err(e) => return Some(Err(e)),
+ Ok(n) => n,
+ };
+
+ // Branches with a then expression that is not nullable do not impact the
+ // nullability of the case expression.
+ if !is_nullable {
+ return None;
+ }
- // For branches with a nullable 'then' expression, try to determine
- // if the 'then' expression is ever reachable in the situation where
- // it would evaluate to null.
- let bounds = match predicate_bounds::evaluate_bounds(
- w,
- Some(unwrap_certainly_null_expr(t)),
- input_schema,
- ) {
- Err(e) => return Some(Err(e)),
- Ok(b) => b,
- };
+ // For case-with-expression assume all 'then' expressions are reachable
+ if case.expr.is_some() {
+ return Some(Ok(()));
+ }
- let can_be_true = match bounds
- .contains_value(ScalarValue::Boolean(Some(true)))
- {
+ // For branches with a nullable 'then' expression, try to determine
+ // if the 'then' expression is ever reachable in the situation where
+ // it would evaluate to null.
+ let bounds = match predicate_bounds::evaluate_bounds(
+ w,
+ Some(unwrap_certainly_null_expr(t)),
+ input_schema,
+ ) {
+ Err(e) => return Some(Err(e)),
+ Ok(b) => b,
+ };
+
+ let can_be_true =
+ match bounds.contains_value(ScalarValue::Boolean(Some(true))) {
Err(e) => return Some(Err(e)),
Ok(b) => b,
};
- if !can_be_true {
- // If the derived 'when' expression can never evaluate to true, the
- // 'then' expression is not reachable when it would evaluate to NULL.
- // The most common pattern for this is `WHEN x IS NOT NULL THEN x`.
- None
- } else {
- // The branch might be taken
- Some(Ok(()))
- }
- })
- .next();
+ if !can_be_true {
+ // If the derived 'when' expression can never evaluate to true, the
+ // 'then' expression is not reachable when it would evaluate to NULL.
+ // The most common pattern for this is `WHEN x IS NOT NULL THEN x`.
+ None
+ } else {
+ // The branch might be taken
+ Some(Ok(()))
+ }
+ });
if let Some(nullable_then) = nullable_then {
// There is at least one reachable nullable 'then' expression, so the case
@@ -546,7 +541,6 @@ impl ExprSchemable for Expr {
let WindowFunction {
fun,
params: WindowFunctionParams { args, .. },
- ..
} = window_function.as_ref();
let fields = args
diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs
index 4b728fe447..ef5e496b0d 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -2972,9 +2972,7 @@ mod tests {
#[test]
fn test_values_metadata() -> Result<()> {
let metadata: HashMap<String, String> =
- [("ARROW:extension:metadata".to_string(), "test".to_string())]
- .into_iter()
- .collect();
+ once(("ARROW:extension:metadata".to_string(), "test".to_string())).collect();
let metadata = FieldMetadata::from(metadata);
let values = LogicalPlanBuilder::values(vec![
vec![lit_with_metadata(1, Some(metadata.clone()))],
@@ -2985,9 +2983,7 @@ mod tests {
// Do not allow VALUES with different metadata mixed together
let metadata2: HashMap<String, String> =
- [("ARROW:extension:metadata".to_string(), "test2".to_string())]
- .into_iter()
- .collect();
+ once(("ARROW:extension:metadata".to_string(), "test2".to_string())).collect();
let metadata2 = FieldMetadata::from(metadata2);
assert!(
LogicalPlanBuilder::values(vec![
diff --git a/datafusion/expr/src/logical_plan/invariants.rs b/datafusion/expr/src/logical_plan/invariants.rs
index d6867d1ceb..f36653694c 100644
--- a/datafusion/expr/src/logical_plan/invariants.rs
+++ b/datafusion/expr/src/logical_plan/invariants.rs
@@ -185,11 +185,7 @@ pub fn check_subquery_expr(
}
}
_ => {
- if inner_plan
- .max_rows()
- .filter(|max_row| *max_row <= 1)
- .is_some()
- {
+ if inner_plan.max_rows().is_some_and(|max_row| max_row <= 1) {
Ok(())
} else {
plan_err!(
@@ -221,7 +217,6 @@ pub fn check_subquery_expr(
),
}?;
}
- check_correlations_in_subquery(inner_plan)
} else {
if let Expr::InSubquery(subquery) = expr {
// InSubquery should only return one column
@@ -265,8 +260,8 @@ pub fn check_subquery_expr(
outer_plan.display()
),
}?;
- check_correlations_in_subquery(inner_plan)
}
+ check_correlations_in_subquery(inner_plan)
}
// Recursively check the unsupported outer references in the sub query plan.
diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs
index 1a141ea52a..ba4fccfb06 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -1914,7 +1914,7 @@ impl LogicalPlan {
produce_one_row,
schema: _,
}) => {
- let rows = if *produce_one_row { 1 } else { 0 };
+ let rows = i32::from(*produce_one_row);
write!(f, "EmptyRelation: rows={rows}")
}
LogicalPlan::RecursiveQuery(RecursiveQuery {
diff --git a/datafusion/expr/src/logical_plan/statement.rs b/datafusion/expr/src/logical_plan/statement.rs
index daf29d7c81..77f1ac3651 100644
--- a/datafusion/expr/src/logical_plan/statement.rs
+++ b/datafusion/expr/src/logical_plan/statement.rs
@@ -93,20 +93,13 @@ impl Statement {
Statement::TransactionStart(TransactionStart {
access_mode,
isolation_level,
- ..
}) => {
write!(f, "TransactionStart: {access_mode:?} {isolation_level:?}")
}
- Statement::TransactionEnd(TransactionEnd {
- conclusion,
- chain,
- ..
- }) => {
+ Statement::TransactionEnd(TransactionEnd { conclusion, chain }) => {
write!(f, "TransactionEnd: {conclusion:?} chain:={chain}")
}
- Statement::SetVariable(SetVariable {
- variable, value, ..
- }) => {
+ Statement::SetVariable(SetVariable { variable, value }) => {
write!(f, "SetVariable: set {variable:?} to {value:?}")
}
Statement::ResetVariable(ResetVariable { variable }) => {
@@ -125,9 +118,7 @@ impl Statement {
.join(", ")
)
}
- Statement::Execute(Execute {
- name, parameters, ..
- }) => {
+ Statement::Execute(Execute { name, parameters }) => {
write!(
f,
"Execute: {} params=[{}]",
diff --git a/datafusion/expr/src/predicate_bounds.rs b/datafusion/expr/src/predicate_bounds.rs
index 6b672221a7..aa947416c8 100644
--- a/datafusion/expr/src/predicate_bounds.rs
+++ b/datafusion/expr/src/predicate_bounds.rs
@@ -166,7 +166,7 @@ impl PredicateBoundsEvaluator<'_> {
}
// If `expr` is not nullable, we can be certain `expr` is not null
- if let Ok(false) = expr.nullable(self.input_schema) {
+ if expr.nullable(self.input_schema).ok() == Some(false) {
return NullableInterval::FALSE;
}
diff --git a/datafusion/ffi/src/expr/interval.rs b/datafusion/ffi/src/expr/interval.rs
index 6334f7bb24..7aae7a9e3f 100644
--- a/datafusion/ffi/src/expr/interval.rs
+++ b/datafusion/ffi/src/expr/interval.rs
@@ -36,7 +36,7 @@ impl TryFrom<&Interval> for FFI_Interval {
let upper = value.upper().try_into()?;
let lower = value.lower().try_into()?;
- Ok(FFI_Interval { upper, lower })
+ Ok(FFI_Interval { lower, upper })
}
}
impl TryFrom<Interval> for FFI_Interval {
diff --git a/datafusion/ffi/src/lib.rs b/datafusion/ffi/src/lib.rs
index de8f8cba9c..43624e2188 100644
--- a/datafusion/ffi/src/lib.rs
+++ b/datafusion/ffi/src/lib.rs
@@ -85,7 +85,7 @@ static LIBRARY_MARKER: u8 = 0;
///
/// See the crate's `README.md` for additional information.
pub extern "C" fn get_library_marker_id() -> usize {
- &LIBRARY_MARKER as *const u8 as usize
+ std::ptr::from_ref::<u8>(&LIBRARY_MARKER) as usize
}
/// For unit testing in this crate we need to trick the providers
diff --git a/datafusion/ffi/src/table_provider.rs b/datafusion/ffi/src/table_provider.rs
index b1d54b5f33..e9271f61ce 100644
--- a/datafusion/ffi/src/table_provider.rs
+++ b/datafusion/ffi/src/table_provider.rs
@@ -1061,11 +1061,10 @@ mod tests {
let session =
FFI_SessionRef::new(&state, None, ffi_provider.logical_codec.clone());
- let assignments = [FFI_TableProviderUpdateAssignment {
+ let assignments = std::iter::once(FFI_TableProviderUpdateAssignment {
column: SString::from("b"),
expr_serialized: SVec::new(),
- }]
- .into_iter()
+ })
.collect();
let result = unsafe {
(ffi_provider.update)(&ffi_provider, session, assignments, SVec::new()).await
diff --git a/datafusion/ffi/src/tests/async_provider.rs b/datafusion/ffi/src/tests/async_provider.rs
index cb5d27c6e6..8217f52fa2 100644
--- a/datafusion/ffi/src/tests/async_provider.rs
+++ b/datafusion/ffi/src/tests/async_provider.rs
@@ -75,7 +75,7 @@ fn async_table_provider_thread(
runtime.block_on(async move {
let mut num_received = 0;
- while let Some(true) = batch_request.recv().await {
+ while batch_request.recv().await == Some(true) {
let record_batch = match num_received {
0 => Some(create_record_batch(1, 5)),
1 => Some(create_record_batch(6, 1)),
diff --git a/datafusion/ffi/src/udaf/accumulator.rs b/datafusion/ffi/src/udaf/accumulator.rs
index 9dae09291f..4d696cadb7 100644
--- a/datafusion/ffi/src/udaf/accumulator.rs
+++ b/datafusion/ffi/src/udaf/accumulator.rs
@@ -17,7 +17,6 @@
use std::any::Any;
use std::ffi::c_void;
-use std::ops::Deref;
use std::ptr::null_mut;
use arrow::array::ArrayRef;
@@ -96,7 +95,7 @@ impl FFI_Accumulator {
unsafe fn inner(&self) -> &dyn Accumulator {
unsafe {
let private_data = self.private_data as *const AccumulatorPrivateData;
- (*private_data).accumulator.deref()
+ &*(*private_data).accumulator
}
}
}
@@ -417,8 +416,9 @@ mod tests {
// Verify local libraries can be downcast to their original
let foreign_accum: Box<dyn Accumulator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn Accumulator
- as *const AvgAccumulator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn Accumulator>(foreign_accum.as_ref())
+ as *const AvgAccumulator);
assert_eq!(original_size, concrete.size());
}
@@ -429,8 +429,9 @@ mod tests {
ffi_accum.library_marker_id = crate::mock_foreign_marker_id;
let foreign_accum: Box<dyn Accumulator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn Accumulator
- as *const ForeignAccumulator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn Accumulator>(foreign_accum.as_ref())
+ as *const ForeignAccumulator);
assert_eq!(original_size, concrete.size());
}
diff --git a/datafusion/ffi/src/udaf/groups_accumulator.rs b/datafusion/ffi/src/udaf/groups_accumulator.rs
index 4d1b0b4be0..ad2714da0c 100644
--- a/datafusion/ffi/src/udaf/groups_accumulator.rs
+++ b/datafusion/ffi/src/udaf/groups_accumulator.rs
@@ -17,7 +17,6 @@
use std::any::Any;
use std::ffi::c_void;
-use std::ops::Deref;
use std::ptr::null_mut;
use std::sync::Arc;
@@ -103,7 +102,7 @@ impl FFI_GroupsAccumulator {
unsafe fn inner(&self) -> &dyn GroupsAccumulator {
unsafe {
let private_data = self.private_data as *const GroupsAccumulatorPrivateData;
- (*private_data).accumulator.deref()
+ &*(*private_data).accumulator
}
}
}
@@ -540,8 +539,9 @@ mod tests {
// Verify local libraries can be downcast to their original
let foreign_accum: Box<dyn GroupsAccumulator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn GroupsAccumulator
- as *const StddevGroupsAccumulator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn GroupsAccumulator>(foreign_accum.as_ref())
+ as *const StddevGroupsAccumulator);
assert_eq!(original_size, concrete.size());
}
@@ -552,8 +552,9 @@ mod tests {
ffi_accum.library_marker_id = crate::mock_foreign_marker_id;
let foreign_accum: Box<dyn GroupsAccumulator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn GroupsAccumulator
- as *const ForeignGroupsAccumulator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn GroupsAccumulator>(foreign_accum.as_ref())
+ as *const ForeignGroupsAccumulator);
assert_eq!(original_size, concrete.size());
}
diff --git a/datafusion/ffi/src/udaf/mod.rs b/datafusion/ffi/src/udaf/mod.rs
index b3a087e5d0..28d2221ac1 100644
--- a/datafusion/ffi/src/udaf/mod.rs
+++ b/datafusion/ffi/src/udaf/mod.rs
@@ -777,9 +777,7 @@ mod tests {
let foreign_udaf = AggregateUDF::new_from_shared_impl(foreign_udaf);
let metadata: HashMap<String, String> =
- [("a_key".to_string(), "a_value".to_string())]
- .into_iter()
- .collect();
+ std::iter::once(("a_key".to_string(), "a_value".to_string())).collect();
let input_field = Arc::new(
Field::new("a", DataType::Float64, false).with_metadata(metadata.clone()),
);
diff --git a/datafusion/ffi/src/udwf/partition_evaluator.rs b/datafusion/ffi/src/udwf/partition_evaluator.rs
index c4c43f00d8..2e6243ddd1 100644
--- a/datafusion/ffi/src/udwf/partition_evaluator.rs
+++ b/datafusion/ffi/src/udwf/partition_evaluator.rs
@@ -394,8 +394,9 @@ mod tests {
// Verify local libraries can be downcast to their original
let foreign_accum: Box<dyn PartitionEvaluator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn PartitionEvaluator
- as *const TestPartitionEvaluator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn PartitionEvaluator>(foreign_accum.as_ref())
+ as *const TestPartitionEvaluator);
assert!(!concrete.uses_window_frame());
}
@@ -406,8 +407,9 @@ mod tests {
ffi_accum.library_marker_id = crate::mock_foreign_marker_id;
let foreign_accum: Box<dyn PartitionEvaluator> = ffi_accum.into();
unsafe {
- let concrete = &*(foreign_accum.as_ref() as *const dyn PartitionEvaluator
- as *const ForeignPartitionEvaluator);
+ let concrete =
+ &*(std::ptr::from_ref::<dyn PartitionEvaluator>(foreign_accum.as_ref())
+ as *const ForeignPartitionEvaluator);
assert!(!concrete.uses_window_frame());
}
diff --git a/datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/accumulate.rs b/datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/accumulate.rs
index 09e1df4eae..a5ed75f346 100644
--- a/datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/accumulate.rs
+++ b/datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/accumulate.rs
@@ -264,7 +264,7 @@ impl NullState {
.zip(data.iter())
.zip(filter.iter())
.for_each(|((&group_index, new_value), filter_value)| {
- if let Some(true) = filter_value {
+ if filter_value == Some(true) {
seen_values.set_bit(group_index, true);
value_fn(group_index, new_value);
}
@@ -278,7 +278,7 @@ impl NullState {
.zip(group_indices.iter())
.zip(values.iter())
.for_each(|((filter_value, &group_index), new_value)| {
- if let Some(true) = filter_value
+ if filter_value == Some(true)
&& let Some(new_value) = new_value
{
seen_values.set_bit(group_index, true);
@@ -442,7 +442,7 @@ pub fn accumulate<T, F>(
.zip(data.iter())
.zip(filter.iter())
.for_each(|((&group_index, &new_value), filter_value)| {
- if let Some(true) = filter_value {
+ if filter_value == Some(true) {
value_fn(group_index, new_value);
}
})
@@ -458,7 +458,7 @@ pub fn accumulate<T, F>(
.zip(group_indices.iter())
.zip(values.iter())
.for_each(|((filter_value, &group_index), new_value)| {
- if let Some(true) = filter_value
+ if filter_value == Some(true)
&& let Some(new_value) = new_value
{
value_fn(group_index, new_value)
@@ -903,7 +903,7 @@ mod test {
.zip(filter.iter())
.for_each(|((&group_index, value), is_included)| {
// if value passed filter
- if let Some(true) = is_included
+ if is_included == Some(true)
&& let Some(value) = value
{
mock.saw_value(group_index);
@@ -966,7 +966,7 @@ mod test {
),
(None, Some(filter)) => group_indices.iter().zip(filter.iter()).for_each(
|(&group_index, is_included)| {
- if let Some(true) = is_included {
+ if is_included == Some(true) {
expected_values.push(group_index);
}
},
@@ -978,7 +978,7 @@ mod test {
.zip(filter.iter())
.for_each(|((&group_index, is_valid), is_included)| {
// if value passed filter
- if let (true, Some(true)) = (is_valid, is_included) {
+ if is_valid && is_included == Some(true) {
expected_values.push(group_index);
}
});
@@ -1032,7 +1032,7 @@ mod test {
.zip(filter.iter())
.for_each(|((&group_index, value), is_included)| {
// if value passed filter
- if let Some(true) = is_included
+ if is_included == Some(true)
&& let Some(value) = value
{
mock.saw_value(group_index);
diff --git a/datafusion/functions-aggregate-common/src/tdigest.rs b/datafusion/functions-aggregate-common/src/tdigest.rs
index 8db7d0bc8a..860f56f6c0 100644
--- a/datafusion/functions-aggregate-common/src/tdigest.rs
+++ b/datafusion/functions-aggregate-common/src/tdigest.rs
@@ -688,12 +688,12 @@ impl TDigest {
}
Ok(Self {
+ centroids,
max_size,
sum,
count,
max,
min,
- centroids,
})
}
}
diff --git a/datafusion/functions-aggregate/src/hyperloglog.rs b/datafusion/functions-aggregate/src/hyperloglog.rs
index 9968e5a981..ce374c3106 100644
--- a/datafusion/functions-aggregate/src/hyperloglog.rs
+++ b/datafusion/functions-aggregate/src/hyperloglog.rs
@@ -79,6 +79,10 @@ where
/// Creates a HyperLogLog from already populated registers
/// note that this method should not be invoked in untrusted environment
/// because the internal structure of registers are not examined.
+ #[expect(
+ clippy::large_types_passed_by_value,
+ reason = "The registers are moved into the returned `Self`, so taking a reference would only add a copy"
+ )]
pub(crate) fn new_with_registers(registers: [u8; NUM_REGISTERS]) -> Self {
Self {
registers,
diff --git a/datafusion/functions-aggregate/src/variance.rs b/datafusion/functions-aggregate/src/variance.rs
index b8e52f849a..a2ec830578 100644
--- a/datafusion/functions-aggregate/src/variance.rs
+++ b/datafusion/functions-aggregate/src/variance.rs
@@ -409,7 +409,7 @@ impl Accumulator for VarianceAccumulator {
Ok(ScalarValue::Float64(match self.count {
0 => None,
1 => {
- if let StatsType::Population = self.stats_type {
+ if self.stats_type == StatsType::Population {
Some(0.0)
} else {
None
@@ -486,7 +486,7 @@ impl VarianceGroupsAccumulator {
let _ = emit_to.take_needed(&mut self.means);
let m2s = emit_to.take_needed(&mut self.m2s);
- if let StatsType::Sample = self.stats_type {
+ if self.stats_type == StatsType::Sample {
counts.iter_mut().for_each(|count| {
*count = count.saturating_sub(1);
});
diff --git a/datafusion/functions-nested/src/array_has.rs b/datafusion/functions-nested/src/array_has.rs
index 0f680469f6..bb3c2dd13f 100644
--- a/datafusion/functions-nested/src/array_has.rs
+++ b/datafusion/functions-nested/src/array_has.rs
@@ -330,8 +330,8 @@ impl<'a> ArrayWrapper<'a> {
/// Primitive and string element types take a per-type fast path; nested (and any
/// other) element types fall back to the per-row `eq` kernel, which allocates a
/// `BooleanArray` per row.
-fn array_has_dispatch_for_array<'a>(
- haystack: ArrayWrapper<'a>,
+fn array_has_dispatch_for_array(
+ haystack: ArrayWrapper<'_>,
needle: &ArrayRef,
) -> Result<ArrayRef> {
let combined_nulls = NullBuffer::union(haystack.nulls(), needle.nulls());
diff --git a/datafusion/functions/src/core/union_tag.rs b/datafusion/functions/src/core/union_tag.rs
index 9a349a4b9a..7c36f6bf0b 100644
--- a/datafusion/functions/src/core/union_tag.rs
+++ b/datafusion/functions/src/core/union_tag.rs
@@ -160,9 +160,9 @@ mod tests {
// when it becomes possible to construct union scalars in SQL, this should go to sqllogictests
#[test]
fn union_scalar() {
- let fields = [(0, Arc::new(Field::new("a", DataType::UInt32, false)))]
- .into_iter()
- .collect();
+ let fields =
+ std::iter::once((0, Arc::new(Field::new("a", DataType::UInt32, false))))
+ .collect();
let scalar = ScalarValue::Union(
Some((0, Box::new(ScalarValue::UInt32(Some(0))))),
diff --git a/datafusion/functions/src/string/common.rs b/datafusion/functions/src/string/common.rs
index 11ebf7d3d6..e37e7ad362 100644
--- a/datafusion/functions/src/string/common.rs
+++ b/datafusion/functions/src/string/common.rs
@@ -624,7 +624,6 @@ fn case_conversion_utf8view_ascii_inner<F: Fn(&u8) -> u8>(
for b in &mut bytes[4..4 + len] {
*b = convert(b);
}
- new_views.push(u128::from_le_bytes(bytes));
} else {
// Long: input view points into shared `data_buffers` we can't
// mutate, so copy-convert into our own buffer and rewrite the
@@ -676,8 +675,8 @@ fn case_conversion_utf8view_ascii_inner<F: Fn(&u8) -> u8>(
bytes[4..8].copy_from_slice(&prefix);
bytes[8..12].copy_from_slice(&buffer_index.to_le_bytes());
bytes[12..16].copy_from_slice(&new_offset.to_le_bytes());
- new_views.push(u128::from_le_bytes(bytes));
}
+ new_views.push(u128::from_le_bytes(bytes));
}
if !in_progress.is_empty() {
diff --git a/datafusion/functions/src/string/concat.rs b/datafusion/functions/src/string/concat.rs
index 1c1f6d6407..aa42d918eb 100644
--- a/datafusion/functions/src/string/concat.rs
+++ b/datafusion/functions/src/string/concat.rs
@@ -495,7 +495,7 @@ mod tests {
ColumnarValue::Scalar(ScalarValue::Binary(Some(
"Café".as_bytes().into()
))),
- ColumnarValue::Scalar(ScalarValue::Binary(Some("cc".as_bytes().into()))),
+ ColumnarValue::Scalar(ScalarValue::Binary(Some(b"cc".into()))),
],
Ok(Some("Cafécc".as_bytes())),
&[u8],
@@ -508,9 +508,7 @@ mod tests {
ColumnarValue::Scalar(ScalarValue::Binary(Some(
"Café".as_bytes().into()
))),
- ColumnarValue::Scalar(ScalarValue::LargeBinary(Some(
- "cc".as_bytes().into()
- ))),
+ ColumnarValue::Scalar(ScalarValue::LargeBinary(Some(b"cc".into()))),
],
Ok(Some("Cafécc".as_bytes())),
&[u8],
@@ -523,9 +521,7 @@ mod tests {
ColumnarValue::Scalar(ScalarValue::Binary(Some(
"Café".as_bytes().into()
))),
- ColumnarValue::Scalar(ScalarValue::BinaryView(Some(
- "cc".as_bytes().into()
- ))),
+ ColumnarValue::Scalar(ScalarValue::BinaryView(Some(b"cc".into()))),
],
Ok(Some("Cafécc".as_bytes())),
&[u8],
@@ -538,9 +534,7 @@ mod tests {
ColumnarValue::Scalar(ScalarValue::BinaryView(Some(
"Café".as_bytes().into()
))),
- ColumnarValue::Scalar(ScalarValue::BinaryView(Some(
- "cc".as_bytes().into()
- ))),
+ ColumnarValue::Scalar(ScalarValue::BinaryView(Some(b"cc".into()))),
],
Ok(Some("Cafécc".as_bytes())),
&[u8],
diff --git a/datafusion/functions/src/unicode/lpad.rs b/datafusion/functions/src/unicode/lpad.rs
index 40bffeecf4..0ffd027149 100644
--- a/datafusion/functions/src/unicode/lpad.rs
+++ b/datafusion/functions/src/unicode/lpad.rs
@@ -118,7 +118,7 @@ impl ScalarUDFImpl for LPadFunc {
// fast path.
if let Some(target_len) = try_as_scalar_i64(&args[1]) {
let target_len: usize = match usize::try_from(target_len) {
- Ok(n) if n <= i32::MAX as usize => n,
+ Ok(n) if i32::try_from(n).is_ok() => n,
Ok(n) => {
return exec_err!(
"lpad requested length {n} too large, maximum allowed length is {}",
diff --git a/datafusion/functions/src/unicode/rpad.rs b/datafusion/functions/src/unicode/rpad.rs
index 784a2037cf..d89ebd0057 100644
--- a/datafusion/functions/src/unicode/rpad.rs
+++ b/datafusion/functions/src/unicode/rpad.rs
@@ -118,7 +118,7 @@ impl ScalarUDFImpl for RPadFunc {
// scalar fast path.
if let Some(target_len) = try_as_scalar_i64(&args[1]) {
let target_len: usize = match usize::try_from(target_len) {
- Ok(n) if n <= i32::MAX as usize => n,
+ Ok(n) if i32::try_from(n).is_ok() => n,
Ok(n) => {
return exec_err!(
"rpad requested length {n} too large, maximum allowed length is {}",
diff --git a/datafusion/optimizer/src/analyzer/resolve_grouping_function.rs b/datafusion/optimizer/src/analyzer/resolve_grouping_function.rs
index 95649ab828..8b1077c6b0 100644
--- a/datafusion/optimizer/src/analyzer/resolve_grouping_function.rs
+++ b/datafusion/optimizer/src/analyzer/resolve_grouping_function.rs
@@ -85,7 +85,7 @@ fn replace_grouping_exprs(
let columns = schema.columns();
let mut new_agg_expr = Vec::new();
let mut projection_exprs = Vec::new();
- let grouping_id_len = if is_grouping_set { 1 } else { 0 };
+ let grouping_id_len = usize::from(is_grouping_set);
let group_expr_len = columns.len() - aggr_expr.len() - grouping_id_len;
projection_exprs.extend(
columns
diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rs
index d11c3e7435..ca1527fac8 100644
--- a/datafusion/optimizer/src/analyzer/type_coercion.rs
+++ b/datafusion/optimizer/src/analyzer/type_coercion.rs
@@ -2660,6 +2660,10 @@ mod test {
)
}
+ #[expect(
+ clippy::unnecessary_box_returns,
+ reason = "`Case` stores boxed expressions, so returning the box reuses the allocation"
+ )]
fn cast_if_not_same_type(
expr: Box<Expr>,
data_type: &DataType,
diff --git a/datafusion/optimizer/src/decorrelate.rs b/datafusion/optimizer/src/decorrelate.rs
index aab58c5519..0c37f00b64 100644
--- a/datafusion/optimizer/src/decorrelate.rs
+++ b/datafusion/optimizer/src/decorrelate.rs
@@ -18,7 +18,6 @@
//! [`PullUpCorrelatedExpr`] converts correlated subqueries to `Joins`
use std::collections::BTreeSet;
-use std::ops::Deref;
use std::sync::Arc;
use crate::simplify_expressions::ExprSimplifier;
@@ -199,7 +198,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
let mut expr_result_map_for_count_bug = HashMap::new();
let pull_up_expr_opt = if let Some(expr_result_map) =
- self.collected_count_expr_map.get(plan_filter.input.deref())
+ self.collected_count_expr_map.get(&*plan_filter.input)
{
if let Some(expr) = conjunction(subquery_filters.clone()) {
filter_exprs_evaluation_result_on_empty_batch(
@@ -258,7 +257,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
let mut expr_result_map_for_count_bug = HashMap::new();
if let Some(expr_result_map) =
- self.collected_count_expr_map.get(projection.input.deref())
+ self.collected_count_expr_map.get(&*projection.input)
{
proj_exprs_evaluation_result_on_empty_batch(
&projection.expr,
@@ -363,8 +362,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
self.correlated_subquery_cols_map
.insert(new_plan.clone(), new_correlated_cols);
- if let Some(input_map) =
- self.collected_count_expr_map.get(alias.input.deref())
+ if let Some(input_map) = self.collected_count_expr_map.get(&*alias.input)
{
self.collected_count_expr_map
.insert(new_plan.clone(), input_map.clone());
@@ -377,10 +375,8 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
}
}
LogicalPlan::Limit(limit) => {
- let input_expr_map = self
- .collected_count_expr_map
- .get(limit.input.deref())
- .cloned();
+ let input_expr_map =
+ self.collected_count_expr_map.get(&*limit.input).cloned();
// handling the limit clause in the subquery
let new_plan = match (self.exists_sub_query, self.join_filters.is_empty())
{
@@ -448,16 +444,16 @@ fn can_pullup_over_aggregation(expr: &Expr) -> bool {
right,
}) = expr
{
- match (left.deref(), right.deref()) {
+ match (&**left, &**right) {
(Expr::Column(_), right) => !right.any_column_refs(),
(left, Expr::Column(_)) => !left.any_column_refs(),
(Expr::Cast(Cast { expr, .. }), right)
- if matches!(expr.deref(), Expr::Column(_)) =>
+ if matches!(&**expr, Expr::Column(_)) =>
{
!right.any_column_refs()
}
(left, Expr::Cast(Cast { expr, .. }))
- if matches!(expr.deref(), Expr::Column(_)) =>
+ if matches!(&**expr, Expr::Column(_)) =>
{
!left.any_column_refs()
}
diff --git a/datafusion/optimizer/src/decorrelate_predicate_subquery.rs b/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
index 0609109ec6..66ea0806bd 100644
--- a/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
+++ b/datafusion/optimizer/src/decorrelate_predicate_subquery.rs
@@ -394,7 +394,7 @@ fn build_join(
right,
})),
) => {
- let right_col = create_col_from_scalar_expr(right.deref(), alias)?;
+ let right_col = create_col_from_scalar_expr(&right, alias)?;
let in_predicate = Expr::eq(left.deref().clone(), Expr::Column(right_col));
in_predicate.and(join_filter)
}
@@ -407,7 +407,7 @@ fn build_join(
right,
})),
) => {
- let right_col = create_col_from_scalar_expr(right.deref(), alias)?;
+ let right_col = create_col_from_scalar_expr(&right, alias)?;
Expr::eq(left.deref().clone(), Expr::Column(right_col))
}
diff --git a/datafusion/optimizer/src/optimizer.rs b/datafusion/optimizer/src/optimizer.rs
index db7ad84752..d784f29650 100644
--- a/datafusion/optimizer/src/optimizer.rs
+++ b/datafusion/optimizer/src/optimizer.rs
@@ -963,7 +963,7 @@ mod tests {
.enumerate()
.map(|(i, (qualifier, field))| {
let metadata =
- [("key".into(), format!("value {i}"))].into_iter().collect();
+ std::iter::once(("key".into(), format!("value {i}"))).collect();
let new_arrow_field = field.as_ref().clone().with_metadata(metadata);
(qualifier.cloned(), Arc::new(new_arrow_field))
diff --git a/datafusion/optimizer/src/simplify_expressions/unwrap_cast.rs b/datafusion/optimizer/src/simplify_expressions/unwrap_cast.rs
index ef0bfa516f..1b07cfa428 100644
--- a/datafusion/optimizer/src/simplify_expressions/unwrap_cast.rs
+++ b/datafusion/optimizer/src/simplify_expressions/unwrap_cast.rs
@@ -118,12 +118,10 @@ pub(super) fn is_cast_expr_and_support_unwrap_cast_in_comparison_for_binary(
Expr::TryCast(TryCast {
expr: left_expr,
field,
- ..
})
| Expr::Cast(Cast {
expr: left_expr,
field,
- ..
}),
Expr::Literal(lit_val, _),
) => {
@@ -161,12 +159,10 @@ pub(super) fn is_cast_expr_and_support_unwrap_cast_in_comparison_for_inlist(
let (Expr::TryCast(TryCast {
expr: left_expr,
field,
- ..
})
| Expr::Cast(Cast {
expr: left_expr,
field,
- ..
})) = expr
else {
return false;
diff --git a/datafusion/optimizer/src/utils.rs b/datafusion/optimizer/src/utils.rs
index 4ea1589cfa..d4ac31e8a5 100644
--- a/datafusion/optimizer/src/utils.rs
+++ b/datafusion/optimizer/src/utils.rs
@@ -141,7 +141,7 @@ impl<'a> ColumnReference<'a> {
}
/// Returns references to all columns in the schema
-pub(crate) fn schema_columns<'a>(schema: &'a DFSchema) -> HashSet<ColumnReference<'a>> {
+pub(crate) fn schema_columns(schema: &DFSchema) -> HashSet<ColumnReference<'_>> {
schema
.iter()
.flat_map(|(qualifier, field)| {
diff --git a/datafusion/physical-expr-adapter/src/schema_rewriter.rs b/datafusion/physical-expr-adapter/src/schema_rewriter.rs
index ef25af7d92..152859b1b7 100644
--- a/datafusion/physical-expr-adapter/src/schema_rewriter.rs
+++ b/datafusion/physical-expr-adapter/src/schema_rewriter.rs
@@ -1017,8 +1017,8 @@ mod tests {
// Should be the same expression (no transformation needed)
// We compare the underlying pointer through the trait object
assert!(std::ptr::eq(
- column_expr.as_ref() as *const dyn PhysicalExpr,
- result.as_ref() as *const dyn PhysicalExpr
+ std::ptr::from_ref::<dyn PhysicalExpr>(column_expr.as_ref()),
+ std::ptr::from_ref::<dyn PhysicalExpr>(result.as_ref())
));
Ok(())
diff --git a/datafusion/physical-expr-common/src/binary_map.rs b/datafusion/physical-expr-common/src/binary_map.rs
index 44ca35c7f8..a95d13ee86 100644
--- a/datafusion/physical-expr-common/src/binary_map.rs
+++ b/datafusion/physical-expr-common/src/binary_map.rs
@@ -467,13 +467,12 @@ where
observe_payload_fn(payload);
}
// Check for overflow in offsets (if more data was sent than can be represented)
- if O::from_usize(self.buffer.len()).is_none() {
- panic!(
- "Put {} bytes in buffer, more than can be represented by a {}",
- self.buffer.len(),
- type_name::<O>()
- );
- }
+ assert!(
+ O::from_usize(self.buffer.len()).is_some(),
+ "Put {} bytes in buffer, more than can be represented by a {}",
+ self.buffer.len(),
+ type_name::<O>()
+ )
}
/// Converts this set into a `StringArray`, `LargeStringArray`,
diff --git a/datafusion/physical-expr/src/equivalence/class.rs b/datafusion/physical-expr/src/equivalence/class.rs
index 1f9a6a583c..c016944f76 100644
--- a/datafusion/physical-expr/src/equivalence/class.rs
+++ b/datafusion/physical-expr/src/equivalence/class.rs
@@ -362,7 +362,7 @@ impl EquivalenceGroup {
let (mut idx, mut change) = (0, false);
while idx < self.classes.len() {
let cls = &mut self.classes[idx];
- if let Some(AcrossPartitions::Heterogeneous) = cls.constant {
+ if cls.constant == Some(AcrossPartitions::Heterogeneous) {
change = true;
if cls.len() == 1 {
// If this class becomes trivial, remove it entirely:
diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rs
index e86748ccc9..ee61d80565 100644
--- a/datafusion/physical-expr/src/expressions/binary.rs
+++ b/datafusion/physical-expr/src/expressions/binary.rs
@@ -5592,7 +5592,7 @@ mod tests {
.unwrap()
.into_array(batch.num_rows())
.unwrap();
- let expected: BooleanArray = [None].iter().collect();
+ let expected: BooleanArray = std::iter::once(&None).collect();
assert_eq!(result.as_ref(), &expected);
}
diff --git a/datafusion/physical-expr/src/expressions/case.rs b/datafusion/physical-expr/src/expressions/case.rs
index 17288a9737..ae0812e0fd 100644
--- a/datafusion/physical-expr/src/expressions/case.rs
+++ b/datafusion/physical-expr/src/expressions/case.rs
@@ -1253,57 +1253,52 @@ impl PhysicalExpr for CaseExpr {
}
fn nullable(&self, input_schema: &Schema) -> Result<bool> {
- let nullable_then = self
- .body
- .when_then_expr
- .iter()
- .filter_map(|(w, t)| {
- let is_nullable = match t.nullable(input_schema) {
- // Pass on error determining nullability verbatim
- Err(e) => return Some(Err(e)),
- Ok(n) => n,
- };
-
- // Branches with a then expression that is not nullable do not impact the
- // nullability of the case expression.
- if !is_nullable {
- return None;
- }
-
- // For case-with-expression assume all 'then' expressions are reachable
- if self.body.expr.is_some() {
- return Some(Ok(()));
- }
-
- // For branches with a nullable 'then' expression, try to determine
- // if the 'then' expression is ever reachable in the situation where
- // it would evaluate to null.
-
- // Replace the `then` expression with `NULL` in the `when` expression
- let with_null = match replace_with_null(
- w,
- unwrap_certainly_null_expr(t.as_ref()),
- input_schema,
- ) {
- Err(e) => return Some(Err(e)),
- Ok(e) => e,
- };
+ let nullable_then = self.body.when_then_expr.iter().find_map(|(w, t)| {
+ let is_nullable = match t.nullable(input_schema) {
+ // Pass on error determining nullability verbatim
+ Err(e) => return Some(Err(e)),
+ Ok(n) => n,
+ };
+
+ // Branches with a then expression that is not nullable do not impact the
+ // nullability of the case expression.
+ if !is_nullable {
+ return None;
+ }
- // Try to const evaluate the modified `when` expression.
- let predicate_result = match evaluate_predicate(&with_null) {
- Err(e) => return Some(Err(e)),
- Ok(b) => b,
- };
+ // For case-with-expression assume all 'then' expressions are reachable
+ if self.body.expr.is_some() {
+ return Some(Ok(()));
+ }
- match predicate_result {
- // Evaluation was inconclusive or true, so the 'then' expression is reachable
- None | Some(true) => Some(Ok(())),
- // Evaluation proves the branch will never be taken.
- // The most common pattern for this is `WHEN x IS NOT NULL THEN x`.
- Some(false) => None,
- }
- })
- .next();
+ // For branches with a nullable 'then' expression, try to determine
+ // if the 'then' expression is ever reachable in the situation where
+ // it would evaluate to null.
+
+ // Replace the `then` expression with `NULL` in the `when` expression
+ let with_null = match replace_with_null(
+ w,
+ unwrap_certainly_null_expr(t.as_ref()),
+ input_schema,
+ ) {
+ Err(e) => return Some(Err(e)),
+ Ok(e) => e,
+ };
+
+ // Try to const evaluate the modified `when` expression.
+ let predicate_result = match evaluate_predicate(&with_null) {
+ Err(e) => return Some(Err(e)),
+ Ok(b) => b,
+ };
+
+ match predicate_result {
+ // Evaluation was inconclusive or true, so the 'then' expression is reachable
+ None | Some(true) => Some(Ok(())),
+ // Evaluation proves the branch will never be taken.
+ // The most common pattern for this is `WHEN x IS NOT NULL THEN x`.
+ Some(false) => None,
+ }
+ });
if let Some(nullable_then) = nullable_then {
// There is at least one reachable nullable 'then' expression, so the case
diff --git a/datafusion/physical-expr/src/expressions/case/literal_lookup_table/mod.rs b/datafusion/physical-expr/src/expressions/case/literal_lookup_table/mod.rs
index 0d4291ccc9..94735c22a5 100644
--- a/datafusion/physical-expr/src/expressions/case/literal_lookup_table/mod.rs
+++ b/datafusion/physical-expr/src/expressions/case/literal_lookup_table/mod.rs
@@ -189,8 +189,8 @@ impl LiteralLookupTable {
Some(Self {
lookup,
- then_and_else_values,
else_index,
+ then_and_else_values,
})
}
diff --git a/datafusion/physical-expr/src/expressions/cast.rs b/datafusion/physical-expr/src/expressions/cast.rs
index dbb91e365a..cb3103d38c 100644
--- a/datafusion/physical-expr/src/expressions/cast.rs
+++ b/datafusion/physical-expr/src/expressions/cast.rs
@@ -1183,7 +1183,7 @@ mod tests {
}
#[test]
- #[ignore] // TODO: https://github.com/apache/datafusion/issues/5396
+ #[ignore = "TODO: https://github.com/apache/datafusion/issues/5396"]
fn test_cast_decimal() -> Result<()> {
let schema = Schema::new(vec![Field::new("a", Int64, false)]);
let a = Int64Array::from(vec![100]);
diff --git a/datafusion/physical-expr/src/simplifier/not.rs b/datafusion/physical-expr/src/simplifier/not.rs
index 886cadd6a2..7496eda6c4 100644
--- a/datafusion/physical-expr/src/simplifier/not.rs
+++ b/datafusion/physical-expr/src/simplifier/not.rs
@@ -69,7 +69,7 @@ pub fn simplify_not_expr(
if let ScalarValue::Boolean(Some(val)) = literal.value() {
return Ok(Transformed::yes(lit(ScalarValue::Boolean(Some(!val)))));
}
- if let ScalarValue::Boolean(None) = literal.value() {
+ if matches!(literal.value(), ScalarValue::Boolean(None)) {
return Ok(Transformed::yes(lit(ScalarValue::Boolean(None))));
}
}
diff --git a/datafusion/physical-plan/benches/multi_group_by.rs b/datafusion/physical-plan/benches/multi_group_by.rs
index 0c689f9fcb..360d311c44 100644
--- a/datafusion/physical-plan/benches/multi_group_by.rs
+++ b/datafusion/physical-plan/benches/multi_group_by.rs
@@ -66,7 +66,7 @@ fn generate_batches(
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
@@ -386,7 +386,7 @@ fn generate_fsb_batches(
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
@@ -477,7 +477,7 @@ fn generate_f16_batches(
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
@@ -559,7 +559,7 @@ fn generate_duration_batches(
) -> Vec<Vec<ArrayRef>> {
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
@@ -643,7 +643,7 @@ fn generate_interval_batches(
) -> Vec<Vec<ArrayRef>> {
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
@@ -730,7 +730,7 @@ fn generate_decimal256_batches(
) -> Vec<Vec<ArrayRef>> {
let num_full_batches = num_rows / batch_size;
let remainder = num_rows % batch_size;
- let num_batches = num_full_batches + if remainder > 0 { 1 } else { 0 };
+ let num_batches = num_full_batches + usize::from(remainder > 0);
(0..num_batches)
.map(|batch_idx| {
diff --git a/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/dictionary.rs b/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/dictionary.rs
index 501b13d0cd..4dd488380a 100644
--- a/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/dictionary.rs
+++ b/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/dictionary.rs
@@ -392,8 +392,8 @@ impl<K: ArrowDictionaryKeyType + Send + Sync> GroupColumn
)
})?;
+ let raw_keys = dict_keys.values();
if dict_keys.null_count() == 0 {
- let raw_keys = dict_keys.values();
for &row in rows {
let val_idx = raw_keys[row].as_usize();
if self.val_to_inner[val_idx] == usize::MAX {
@@ -411,7 +411,6 @@ impl<K: ArrowDictionaryKeyType + Send + Sync> GroupColumn
self.group_to_inner.push(self.val_to_inner[val_idx]);
}
} else {
- let raw_keys = dict_keys.values();
let null_buf = dict_keys.nulls().unwrap();
for &row in rows {
let slot = if null_buf.is_null(row) {
diff --git a/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/row_backed.rs b/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/row_backed.rs
index 1445a81f21..377977029a 100644
--- a/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/row_backed.rs
+++ b/datafusion/physical-plan/src/aggregates/group_values/multi_group_by/row_backed.rs
@@ -337,6 +337,10 @@ mod tests {
/// marks a null list. Variable-length string payloads give retained rows
/// distinct encoded lengths, which is what `take_n`'s byte preallocation
/// depends on.
+ #[expect(
+ clippy::option_option,
+ reason = "The outer `None` marks a null list, the inner one a null string"
+ )]
fn fsl_utf8(rows: Vec<Option<Option<&str>>>) -> ArrayRef {
let child = StringArray::from(
rows.iter()
diff --git a/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs b/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs
index 340df57e5d..c0253093c8 100644
--- a/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs
+++ b/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs
@@ -494,8 +494,11 @@ impl GroupedHashAggregateStream {
let agg_fn_names = aggregate_exprs
.iter()
.map(|expr| {
- format_human_display(expr.human_display(), expr.human_display_alias())
- .map(|display| display.into_owned())
+ expr.human_display()
+ .map(|display| {
+ format_human_display(display, expr.human_display_alias())
+ .into_owned()
+ })
.unwrap_or_else(|| expr.name().to_string())
})
.collect::<Vec<_>>()
diff --git a/datafusion/physical-plan/src/aggregates/mod.rs b/datafusion/physical-plan/src/aggregates/mod.rs
index 1671735ec3..1a7193a7d8 100644
--- a/datafusion/physical-plan/src/aggregates/mod.rs
+++ b/datafusion/physical-plan/src/aggregates/mod.rs
@@ -1985,14 +1985,17 @@ impl DisplayAs for AggregateExec {
fn format_aggregate_exec_expr(agg: &AggregateFunctionExpr) -> Cow<'_, str> {
match agg.human_display_alias() {
- Some(_) => format_human_display(agg.human_display(), agg.human_display_alias())
+ Some(_) => agg
+ .human_display()
+ .map(|display| format_human_display(display, agg.human_display_alias()))
.unwrap_or_else(|| Cow::Borrowed(agg.name())),
None => Cow::Borrowed(agg.name()),
}
}
fn format_tree_aggregate_expr(agg: &AggregateFunctionExpr) -> Cow<'_, str> {
- format_human_display(agg.human_display(), agg.human_display_alias())
+ agg.human_display()
+ .map(|display| format_human_display(display, agg.human_display_alias()))
.unwrap_or_else(|| Cow::Borrowed(agg.name()))
}
@@ -2001,13 +2004,13 @@ fn aggregate_metric_label(agg: &AggregateFunctionExpr) -> String {
}
fn format_human_display<'a>(
- human_display: Option<&'a str>,
+ human_display: &'a str,
alias: Option<&'a str>,
-) -> Option<Cow<'a, str>> {
- human_display.map(|human_display| match alias {
+) -> Cow<'a, str> {
+ match alias {
Some(alias) => Cow::Owned(format!("{human_display} as {alias}")),
None => Cow::Borrowed(human_display),
- })
+ }
}
impl ExecutionPlan for AggregateExec {
@@ -3051,9 +3054,9 @@ pub(crate) fn group_id_array(
{max_ordinal} require {total_bits} bits, which exceeds 64"
);
}
- let semantic_id = group.iter().fold(0u64, |acc, &is_null| {
- (acc << 1) | if is_null { 1 } else { 0 }
- });
+ let semantic_id = group
+ .iter()
+ .fold(0u64, |acc, &is_null| (acc << 1) | u64::from(is_null));
let full_id = semantic_id | ((ordinal as u64) << n);
if total_bits <= 8 {
Ok(Arc::new(UInt8Array::from(vec![full_id as u8; num_rows])))
diff --git a/datafusion/physical-plan/src/buffer.rs b/datafusion/physical-plan/src/buffer.rs
index 24cca6b0b1..5879b98c34 100644
--- a/datafusion/physical-plan/src/buffer.rs
+++ b/datafusion/physical-plan/src/buffer.rs
@@ -650,9 +650,7 @@ mod tests {
// A panic while polling the input must surface as a stream error, not a
// silent end-of-stream that drops the rest of the partition's output.
let input = futures::stream::iter([1, 2, 3, 4]).map(|v| {
- if v == 3 {
- panic!("boom on 3");
- }
+ assert!(v != 3, "boom on 3");
Ok(v)
});
let (_, res) = memory_pool_and_reservation();
diff --git a/datafusion/physical-plan/src/column_rewriter.rs b/datafusion/physical-plan/src/column_rewriter.rs
index 2df95cd614..e03f5ab5d3 100644
--- a/datafusion/physical-plan/src/column_rewriter.rs
+++ b/datafusion/physical-plan/src/column_rewriter.rs
@@ -43,7 +43,7 @@ impl<'a> PhysicalColumnRewriter<'a> {
}
}
-impl<'a> TreeNodeRewriter for PhysicalColumnRewriter<'a> {
+impl TreeNodeRewriter for PhysicalColumnRewriter<'_> {
type Node = Arc<dyn PhysicalExpr>;
fn f_down(
diff --git a/datafusion/physical-plan/src/display.rs b/datafusion/physical-plan/src/display.rs
index d2bdcef2e9..24a559b27f 100644
--- a/datafusion/physical-plan/src/display.rs
+++ b/datafusion/physical-plan/src/display.rs
@@ -1352,7 +1352,7 @@ impl TreeRenderVisitor<'_, '_> {
} else {
let total_spaces = max_render_width - render_width;
let half_spaces = total_spaces / 2;
- let extra_left_space = if total_spaces.is_multiple_of(2) { 0 } else { 1 };
+ let extra_left_space = usize::from(!total_spaces.is_multiple_of(2));
format!(
"{}{}{}",
" ".repeat(half_spaces + extra_left_space),
diff --git a/datafusion/physical-plan/src/filter.rs b/datafusion/physical-plan/src/filter.rs
index c62db109ea..414e5a6d85 100644
--- a/datafusion/physical-plan/src/filter.rs
+++ b/datafusion/physical-plan/src/filter.rs
@@ -2148,9 +2148,7 @@ mod tests {
Statistics {
num_rows: Precision::Inexact(1000),
total_byte_size: Precision::Inexact(4000),
- column_statistics: vec![ColumnStatistics {
- ..Default::default()
- }],
+ column_statistics: vec![ColumnStatistics::default()],
},
schema,
));
@@ -2320,15 +2318,9 @@ mod tests {
max_value: Precision::Inexact(ScalarValue::Int32(Some(100))),
..Default::default()
},
- ColumnStatistics {
- ..Default::default()
- },
- ColumnStatistics {
- ..Default::default()
- },
- ColumnStatistics {
- ..Default::default()
- },
+ ColumnStatistics::default(),
+ ColumnStatistics::default(),
+ ColumnStatistics::default(),
],
},
schema,
diff --git a/datafusion/physical-plan/src/joins/array_map.rs b/datafusion/physical-plan/src/joins/array_map.rs
index 4e56cf013c..1a1cd8d329 100644
--- a/datafusion/physical-plan/src/joins/array_map.rs
+++ b/datafusion/physical-plan/src/joins/array_map.rs
@@ -319,7 +319,6 @@ impl ArrayMap {
build_indices.push((build_value - 1) as u64);
probe_indices.push(prob_idx as u32);
}
- Ok(None)
} else {
let mut remaining_output = limit;
let to_skip = match current_offset {
@@ -376,8 +375,8 @@ impl ArrayMap {
return Ok(Some(offset));
}
}
- Ok(None)
}
+ Ok(None)
}
pub fn contain_keys(&self, probe_side_keys: &[ArrayRef]) -> Result<BooleanArray> {
diff --git a/datafusion/physical-plan/src/joins/hash_join/exec.rs b/datafusion/physical-plan/src/joins/hash_join/exec.rs
index 34e901b9a3..977a36578d 100644
--- a/datafusion/physical-plan/src/joins/hash_join/exec.rs
+++ b/datafusion/physical-plan/src/joins/hash_join/exec.rs
@@ -6179,6 +6179,10 @@ mod tests {
}
#[tokio::test]
+ #[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The braces are part of the expected struct output, not format args"
+ )]
async fn join_on_struct() -> Result<()> {
let task_ctx = Arc::new(TaskContext::default());
let left =
diff --git a/datafusion/physical-plan/src/joins/hash_join/shared_bounds.rs b/datafusion/physical-plan/src/joins/hash_join/shared_bounds.rs
index 94ec4565a4..77b327accf 100644
--- a/datafusion/physical-plan/src/joins/hash_join/shared_bounds.rs
+++ b/datafusion/physical-plan/src/joins/hash_join/shared_bounds.rs
@@ -501,8 +501,8 @@ impl SharedBuildAccumulator {
*completed_partitions += 1;
}
partitions[partition_id] = PartitionStatus::Reported(PartitionData {
- pushdown,
bounds,
+ pushdown,
keys_have_null,
});
}
@@ -520,8 +520,8 @@ impl SharedBuildAccumulator {
) => {
if matches!(data, PartitionStatus::Pending) {
*data = PartitionStatus::Reported(PartitionData {
- pushdown,
bounds,
+ pushdown,
keys_have_null,
});
}
diff --git a/datafusion/physical-plan/src/joins/sort_merge_join/tests.rs b/datafusion/physical-plan/src/joins/sort_merge_join/tests.rs
index 175a9c0ea7..1d29db20dc 100644
--- a/datafusion/physical-plan/src/joins/sort_merge_join/tests.rs
+++ b/datafusion/physical-plan/src/joins/sort_merge_join/tests.rs
@@ -2537,7 +2537,7 @@ async fn spill_join_arrays_memory_accounting() -> Result<()> {
// Memory limit: too small for a full batch, large enough for join_arrays.
// Every batch hits the Err arm → spills → grow(join_arrays_mem).
- let memory_limit = (size_estimation + join_arrays_mem) / 2;
+ let memory_limit = usize::midpoint(size_estimation, join_arrays_mem);
assert!(
memory_limit < size_estimation && memory_limit > join_arrays_mem,
"limit {memory_limit} must be between join_arrays_mem {join_arrays_mem} \
diff --git a/datafusion/physical-plan/src/joins/utils.rs b/datafusion/physical-plan/src/joins/utils.rs
index ecf056560e..62771af4c4 100644
--- a/datafusion/physical-plan/src/joins/utils.rs
+++ b/datafusion/physical-plan/src/joins/utils.rs
@@ -1833,6 +1833,7 @@ impl BuildProbeJoinMetrics {
.ratio_metrics("avg_fanout", partition);
Self {
+ baseline,
build_time,
build_input_batches,
build_input_rows,
@@ -1840,7 +1841,6 @@ impl BuildProbeJoinMetrics {
join_time,
input_batches,
input_rows,
- baseline,
probe_hit_rate,
avg_fanout,
}
diff --git a/datafusion/physical-plan/src/repartition/distributor_channels.rs b/datafusion/physical-plan/src/repartition/distributor_channels.rs
index 22872d1e32..fb86aafadd 100644
--- a/datafusion/physical-plan/src/repartition/distributor_channels.rs
+++ b/datafusion/physical-plan/src/repartition/distributor_channels.rs
@@ -40,7 +40,6 @@
use std::{
collections::VecDeque,
future::Future,
- ops::DerefMut,
pin::Pin,
sync::{
Arc,
@@ -173,12 +172,7 @@ impl<T> Drop for DistributionSender<T> {
// senders and it will decrement the `empty_channels` counter. It will also set `data` to `None`. The sender
// side will then see that `data` is `None` and can therefore infer that the receiver end was dropped, and
// hence it MUST NOT decrement the `empty_channels` counter.
- if state
- .data
- .as_ref()
- .map(|data| data.is_empty())
- .unwrap_or_default()
- {
+ if state.data.as_ref().is_some_and(|data| data.is_empty()) {
// channel is gone, so we need to clear our signal
self.gate.decr_empty_channels();
}
@@ -225,7 +219,7 @@ impl<T> Future for SendFuture<'_, T> {
// if so, allow sender to create another
if this.gate.empty_channels.load(Ordering::SeqCst) == 0 {
let mut guard = this.gate.send_wakers.lock();
- if let Some(send_wakers) = guard.deref_mut() {
+ if let Some(send_wakers) = &mut *guard {
send_wakers.push((cx.waker().clone(), this.channel.id));
return Poll::Pending;
}
@@ -303,7 +297,7 @@ impl<T> Future for RecvFuture<'_, T> {
assert!(!this.rdy, "polled ready future");
let mut guard_channel_state = this.channel.state.lock();
- let channel_state = guard_channel_state.deref_mut();
+ let channel_state = &mut *guard_channel_state;
let data = channel_state.data.as_mut().expect("not dropped yet");
match data.pop_front() {
@@ -436,7 +430,7 @@ impl Gate {
let to_wake = {
let mut guard = self.send_wakers.lock();
- if let Some(send_wakers) = guard.deref_mut() {
+ if let Some(send_wakers) = &mut *guard {
// `drain_filter` is unstable, so implement our own
let (wake, keep) =
send_wakers.drain(..).partition(|(_waker, id2)| id == *id2);
diff --git a/datafusion/physical-plan/src/repartition/mod.rs b/datafusion/physical-plan/src/repartition/mod.rs
index 063954a72a..0334987994 100644
--- a/datafusion/physical-plan/src/repartition/mod.rs
+++ b/datafusion/physical-plan/src/repartition/mod.rs
@@ -551,9 +551,9 @@ impl RepartitionExecState {
tx,
rx,
reservation,
- spill_readers,
- spill_writers,
shared_coalescer,
+ spill_writers,
+ spill_readers,
},
);
}
diff --git a/datafusion/physical-plan/src/sorts/merge.rs b/datafusion/physical-plan/src/sorts/merge.rs
index aa85a07b0a..bdfdbcf38b 100644
--- a/datafusion/physical-plan/src/sorts/merge.rs
+++ b/datafusion/physical-plan/src/sorts/merge.rs
@@ -499,7 +499,7 @@ impl<C: CursorValues> SortPreservingMergeStream<C> {
/// it takes as input the next item at (S0) and the loser of (S3, S4).
#[inline]
fn lt_leaf_node_index(&self, cursor_index: usize) -> usize {
- (self.cursors.len() + cursor_index) / 2
+ usize::midpoint(self.cursors.len(), cursor_index)
}
/// Find the parent node index for the given node index
diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs
index 6c782f5134..f4f1a5e5b4 100644
--- a/datafusion/physical-plan/src/sorts/sort.rs
+++ b/datafusion/physical-plan/src/sorts/sort.rs
@@ -497,14 +497,13 @@ impl ExternalSorter {
while let Some(batch) = sorted_stream.next().await {
let batch = batch?;
let sorted_size = get_reserved_bytes_for_record_batch(&batch)?;
- if self.reservation.try_grow(sorted_size).is_err() {
- // Although the reservation is not enough, the batch is
- // already in memory, so it's okay to combine it with previously
- // sorted batches, and spill together.
- globally_sorted_batches.push(batch);
+ let reservation_failed = self.reservation.try_grow(sorted_size).is_err();
+ // Even if the reservation is not enough, the batch is already in
+ // memory, so it's okay to combine it with previously sorted
+ // batches, and spill together.
+ globally_sorted_batches.push(batch);
+ if reservation_failed {
self.consume_and_spill_append(&mut globally_sorted_batches)?; // reservation is freed in spill()
- } else {
- globally_sorted_batches.push(batch);
}
}
diff --git a/datafusion/physical-plan/src/statistics.rs b/datafusion/physical-plan/src/statistics.rs
index 9246d7d9f5..91fa20ce30 100644
--- a/datafusion/physical-plan/src/statistics.rs
+++ b/datafusion/physical-plan/src/statistics.rs
@@ -47,7 +47,7 @@ impl StatsCache {
partition: Option<usize>,
) -> Option<&Arc<Statistics>> {
let key = (
- plan as *const dyn ExecutionPlan as *const () as usize,
+ std::ptr::from_ref::<dyn ExecutionPlan>(plan) as *const () as usize,
partition,
);
self.0.get(&key)
@@ -60,7 +60,7 @@ impl StatsCache {
stats: Arc<Statistics>,
) {
let key = (
- plan as *const dyn ExecutionPlan as *const () as usize,
+ std::ptr::from_ref::<dyn ExecutionPlan>(plan) as *const () as usize,
partition,
);
self.0.insert(key, stats);
diff --git a/datafusion/physical-plan/src/topk/mod.rs b/datafusion/physical-plan/src/topk/mod.rs
index 1d02397b92..030614eed0 100644
--- a/datafusion/physical-plan/src/topk/mod.rs
+++ b/datafusion/physical-plan/src/topk/mod.rs
@@ -1772,7 +1772,7 @@ impl PartitionedTopKRank {
let mut coalescer = BatchCoalescer::new(Arc::clone(&schema), batch_size);
for pk in sorted_pks {
- let RankPartitionState { mut heap, ties, .. } =
+ let RankPartitionState { mut heap, ties } =
states.remove(&pk).expect("key from states.keys()");
if let Some(batch) = heap.emit()? {
(&batch).record_output(&metrics.baseline);
diff --git a/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs b/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs
index d4c98009ba..11d0f67760 100644
--- a/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs
+++ b/datafusion/physical-plan/src/windows/bounded_window_agg_exec.rs
@@ -2266,7 +2266,7 @@ mod tests {
let chunk_length = 2;
let n_future_range = 1;
- let timeout_duration = Duration::from_millis(2000);
+ let timeout_duration = Duration::from_secs(2);
let source =
generate_never_ending_source(n_rows, chunk_length, 1, true, false, 5)?;
diff --git a/datafusion/physical-plan/src/windows/mod.rs b/datafusion/physical-plan/src/windows/mod.rs
index 089bdc23ee..b031476b35 100644
--- a/datafusion/physical-plan/src/windows/mod.rs
+++ b/datafusion/physical-plan/src/windows/mod.rs
@@ -78,15 +78,13 @@ pub fn schema_add_window_field(
.map(|f| f.as_ref().clone())
.collect_vec();
// Skip extending schema for UDAF
- if let WindowFunctionDefinition::AggregateUDF(_) = window_fn {
- Ok(Arc::new(Schema::new(window_fields)))
- } else {
+ if !matches!(window_fn, WindowFunctionDefinition::AggregateUDF(_)) {
window_fields.extend_from_slice(&[window_expr_return_field
.as_ref()
.clone()
.with_name(fn_name)]);
- Ok(Arc::new(Schema::new(window_fields)))
}
+ Ok(Arc::new(Schema::new(window_fields)))
}
/// Create a physical expression for window function
diff --git a/datafusion/proto-common/gen/src/main.rs b/datafusion/proto-common/gen/src/main.rs
index d672832d43..3623a6357d 100644
--- a/datafusion/proto-common/gen/src/main.rs
+++ b/datafusion/proto-common/gen/src/main.rs
@@ -33,7 +33,7 @@ fn main() -> Result<(), String> {
.map_err(|e| format!("protobuf compilation failed: {e}"))?;
let descriptor_set = std::fs::read(&descriptor_path)
- .unwrap_or_else(|e| panic!("Cannot read {descriptor_path:?}: {e}"));
+ .unwrap_or_else(|e| panic!("Cannot read {}: {e}", descriptor_path.display()));
pbjson_build::Builder::new()
.out_dir("src")
diff --git a/datafusion/proto-models/gen/src/main.rs b/datafusion/proto-models/gen/src/main.rs
index b9cbf81bb1..0579122276 100644
--- a/datafusion/proto-models/gen/src/main.rs
+++ b/datafusion/proto-models/gen/src/main.rs
@@ -35,7 +35,7 @@ fn main() -> Result<(), String> {
.map_err(|e| format!("protobuf compilation failed: {e}"))?;
let descriptor_set = std::fs::read(&descriptor_path)
- .unwrap_or_else(|e| panic!("Cannot read {descriptor_path:?}: {e}"));
+ .unwrap_or_else(|e| panic!("Cannot read {}: {e}", descriptor_path.display()));
pbjson_build::Builder::new()
.out_dir(out_dir)
diff --git a/datafusion/proto/tests/cases/plans/sources.rs b/datafusion/proto/tests/cases/plans/sources.rs
index 5cdd42a0ac..ca8dca74d7 100644
--- a/datafusion/proto/tests/cases/plans/sources.rs
+++ b/datafusion/proto/tests/cases/plans/sources.rs
@@ -504,7 +504,7 @@ fn roundtrip_parquet_exec_with_custom_predicate_expr() -> Result<()> {
inputs: &[Arc<dyn PhysicalExpr>],
_ctx: &PhysicalExprDecodeCtx<'_>,
) -> Result<Arc<dyn PhysicalExpr>> {
- if buf == "CustomPredicateExpr".as_bytes() {
+ if buf == b"CustomPredicateExpr" {
Ok(Arc::new(CustomPredicateExpr {
inner: inputs[0].clone(),
}))
@@ -520,7 +520,7 @@ fn roundtrip_parquet_exec_with_custom_predicate_expr() -> Result<()> {
_ctx: &PhysicalExprEncodeCtx<'_>,
) -> Result<()> {
if node.downcast_ref::<CustomPredicateExpr>().is_some() {
- buf.extend_from_slice("CustomPredicateExpr".as_bytes());
+ buf.extend_from_slice(b"CustomPredicateExpr");
Ok(())
} else {
internal_err!("Not supported")
diff --git a/datafusion/pruning/src/pruning_predicate.rs b/datafusion/pruning/src/pruning_predicate.rs
index 3a63451495..6df5cbc5cc 100644
--- a/datafusion/pruning/src/pruning_predicate.rs
+++ b/datafusion/pruning/src/pruning_predicate.rs
@@ -755,7 +755,7 @@ impl BoolVecBuilder {
// `false` for this conjunct means we know for sure no rows could
// pass the predicate and thus we set the corresponding container
// location to false.
- if let Some(false) = new {
+ if new == Some(false) {
*cur = false;
}
}
@@ -795,14 +795,12 @@ impl BoolVecBuilder {
fn is_always_true(expr: &Arc<dyn PhysicalExpr>) -> bool {
expr.downcast_ref::<phys_expr::Literal>()
- .map(|l| matches!(l.value(), ScalarValue::Boolean(Some(true))))
- .unwrap_or_default()
+ .is_some_and(|l| *l.value() == ScalarValue::Boolean(Some(true)))
}
fn is_always_false(expr: &Arc<dyn PhysicalExpr>) -> bool {
expr.downcast_ref::<phys_expr::Literal>()
- .map(|l| matches!(l.value(), ScalarValue::Boolean(Some(false))))
- .unwrap_or_default()
+ .is_some_and(|l| *l.value() == ScalarValue::Boolean(Some(false)))
}
/// Describes which columns statistics are necessary to evaluate a
@@ -2304,10 +2302,10 @@ mod tests {
.map(|(_values, contained)| Arc::new(contained.clone()) as ArrayRef);
[
- self.min.as_ref().cloned(),
- self.max.as_ref().cloned(),
- self.null_counts.as_ref().cloned(),
- self.row_counts.as_ref().cloned(),
+ self.min.clone(),
+ self.max.clone(),
+ self.null_counts.clone(),
+ self.row_counts.clone(),
]
.into_iter()
.flatten()
@@ -2603,11 +2601,10 @@ mod tests {
let mut fields = HashSet::new();
for (_col, _ty, field) in p.required_columns().iter() {
let was_new = fields.insert(field);
- if !was_new {
- panic!(
- "Duplicate field in required schema: {field:?}. Previous fields:\n{fields:#?}"
- );
- }
+ assert!(
+ was_new,
+ "Duplicate field in required schema: {field:?}. Previous fields:\n{fields:#?}"
+ )
}
}
diff --git a/datafusion/spark/src/function/bitmap/bitmap_count.rs b/datafusion/spark/src/function/bitmap/bitmap_count.rs
index 18d5848688..95e6ec220a 100644
--- a/datafusion/spark/src/function/bitmap/bitmap_count.rs
+++ b/datafusion/spark/src/function/bitmap/bitmap_count.rs
@@ -90,14 +90,17 @@ impl ScalarUDFImpl for BitmapCount {
}
}
-fn binary_count_ones(opt: Option<&[u8]>) -> Option<i64> {
- opt.map(|value| value.iter().map(|b| b.count_ones() as i64).sum())
+fn binary_count_ones(value: &[u8]) -> i64 {
+ value.iter().map(|b| b.count_ones() as i64).sum()
}
macro_rules! downcast_and_count_ones {
($input_array:expr, $array_type:ident) => {{
let arr = downcast_arg!($input_array, $array_type);
- Ok(arr.iter().map(binary_count_ones).collect::<Int64Array>())
+ Ok(arr
+ .iter()
+ .map(|v| v.map(binary_count_ones))
+ .collect::<Int64Array>())
}};
}
@@ -107,7 +110,7 @@ macro_rules! downcast_dict_and_count_ones {
let array = dict_array.downcast_dict::<BinaryArray>().unwrap();
Ok(array
.into_iter()
- .map(binary_count_ones)
+ .map(|v| v.map(binary_count_ones))
.collect::<Int64Array>())
}};
}
diff --git a/datafusion/spark/src/function/url/parse_url.rs b/datafusion/spark/src/function/url/parse_url.rs
index 9ceed8b155..1a20cdc10b 100644
--- a/datafusion/spark/src/function/url/parse_url.rs
+++ b/datafusion/spark/src/function/url/parse_url.rs
@@ -81,7 +81,7 @@ impl ParseUrl {
/// * `Err(DataFusionError)` - If the URL is malformed and cannot be parsed
fn parse(value: &str, part: &str, key: Option<&str>) -> Result<Option<String>> {
let url: std::result::Result<Url, ParseError> = Url::parse(value);
- if let Err(ParseError::RelativeUrlWithoutBase) = url {
+ if url == Err(ParseError::RelativeUrlWithoutBase) {
return if !value.contains("://") {
// Schemeless URLs are treated as relative URIs (like java.net.URI).
// Manually parse path, query, and fragment components.
diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs
index e6bee31fbf..4ad022134a 100644
--- a/datafusion/sql/src/expr/function.rs
+++ b/datafusion/sql/src/expr/function.rs
@@ -48,24 +48,17 @@ pub fn suggest_valid_function(
is_window_func: bool,
ctx: &dyn ContextProvider,
) -> Option<String> {
- let valid_funcs = if is_window_func {
+ let mut valid_funcs = Vec::new();
+ if is_window_func {
// All aggregate functions and builtin window functions
- let mut funcs = Vec::new();
-
- funcs.extend(ctx.udaf_names());
- funcs.extend(ctx.udwf_names());
-
- funcs
+ valid_funcs.extend(ctx.udaf_names());
+ valid_funcs.extend(ctx.udwf_names());
} else {
// All scalar functions and aggregate functions
- let mut funcs = Vec::new();
-
- funcs.extend(ctx.udf_names());
- funcs.extend(ctx.higher_order_function_names());
- funcs.extend(ctx.udaf_names());
-
- funcs
- };
+ valid_funcs.extend(ctx.udf_names());
+ valid_funcs.extend(ctx.higher_order_function_names());
+ valid_funcs.extend(ctx.udaf_names());
+ }
find_closest_match(valid_funcs, input_function_name)
}
diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rs
index b1de4e95fd..22520d86bd 100644
--- a/datafusion/sql/src/expr/mod.rs
+++ b/datafusion/sql/src/expr/mod.rs
@@ -57,6 +57,12 @@ mod substring;
mod unary_op;
mod value;
+/// Returns `None` if `expr` is not a NULL literal, and `Some(span)` where
+/// `span` is the literal's span, if it has one.
+#[expect(
+ clippy::option_option,
+ reason = "The two levels mean different things, see above"
+)]
fn null_value_span(expr: &SQLExpr) -> Option<Option<Span>> {
if let SQLExpr::Value(ValueWithSpan {
value: Value::Null,
diff --git a/datafusion/sql/src/relation/mod.rs b/datafusion/sql/src/relation/mod.rs
index 08a292475f..8549bd833e 100644
--- a/datafusion/sql/src/relation/mod.rs
+++ b/datafusion/sql/src/relation/mod.rs
@@ -39,9 +39,7 @@ struct SqlToRelRelationContext<'a, 'b, S: ContextProvider> {
}
// Implement RelationPlannerContext
-impl<'a, 'b, S: ContextProvider> RelationPlannerContext
- for SqlToRelRelationContext<'a, 'b, S>
-{
+impl<S: ContextProvider> RelationPlannerContext for SqlToRelRelationContext<'_, '_, S> {
fn context_provider(&self) -> &dyn ContextProvider {
self.planner.context_provider
}
diff --git a/datafusion/sql/src/unparser/plan.rs b/datafusion/sql/src/unparser/plan.rs
index f4b60176cf..9922509a0e 100644
--- a/datafusion/sql/src/unparser/plan.rs
+++ b/datafusion/sql/src/unparser/plan.rs
@@ -823,9 +823,9 @@ impl Unparser<'_> {
"derived_projection",
plan,
relation,
- unnest_input_type
- .filter(|t| matches!(t, UnnestInputType::OuterReference))
- .is_some(),
+ unnest_input_type.is_some_and(|t| {
+ matches!(t, UnnestInputType::OuterReference)
+ }),
columns,
);
}
diff --git a/datafusion/sql/src/utils.rs b/datafusion/sql/src/utils.rs
index 3b571eed27..0f0b5fe44c 100644
--- a/datafusion/sql/src/utils.rs
+++ b/datafusion/sql/src/utils.rs
@@ -563,12 +563,10 @@ impl TreeNodeRewriter for RecursiveUnnestRewriter<'_> {
if self.top_most_unnest.is_none() {
self.top_most_unnest = Some(unnest_expr.clone());
}
-
- Ok(Transformed::no(expr))
} else {
self.consecutive_unnest.push(None);
- Ok(Transformed::no(expr))
}
+ Ok(Transformed::no(expr))
}
/// The rewriting only happens when the traversal has reached the top-most unnest expr
diff --git a/datafusion/sql/tests/cases/diagnostic.rs b/datafusion/sql/tests/cases/diagnostic.rs
index 1f2cefdec0..1f4eeca83b 100644
--- a/datafusion/sql/tests/cases/diagnostic.rs
+++ b/datafusion/sql/tests/cases/diagnostic.rs
@@ -170,9 +170,7 @@ fn get_spans(query: &'static str) -> HashMap<String, Span> {
}
}
- if !stack.is_empty() {
- panic!("unbalanced tags");
- }
+ assert!(stack.is_empty(), "unbalanced tags");
spans
}
diff --git a/datafusion/sql/tests/sql_integration.rs b/datafusion/sql/tests/sql_integration.rs
index 08a95381b3..a255b940e6 100644
--- a/datafusion/sql/tests/sql_integration.rs
+++ b/datafusion/sql/tests/sql_integration.rs
@@ -5283,9 +5283,10 @@ fn assert_field_not_found(mut err: DataFusionError, name: &str) {
DataFusionError::SchemaError(_, _) => {
let msg = format!("{err}");
let expected = format!("Schema error: No field named {name}.");
- if !msg.starts_with(&expected) {
- panic!("error [{msg}] did not start with [{expected}]");
- }
+ assert!(
+ msg.starts_with(&expected),
+ "error [{msg}] did not start with [{expected}]"
+ )
}
_ => panic!("assert_field_not_found wrong error type"),
}
diff --git a/datafusion/sqllogictest/bin/sqllogictests.rs b/datafusion/sqllogictest/bin/sqllogictests.rs
index da0beb0c29..ae0eee432a 100644
--- a/datafusion/sqllogictest/bin/sqllogictests.rs
+++ b/datafusion/sqllogictest/bin/sqllogictests.rs
@@ -453,7 +453,7 @@ async fn run_test_file_substrait_round_trip(
let pb = mp.add(ProgressBar::new(count));
pb.set_style(mp_style);
- pb.set_message(format!("{relative_path:?}"));
+ pb.set_message(relative_path.display().to_string());
let mut runner = sqllogictest::Runner::new(|| async {
Ok(DataFusionSubstraitRoundTrip::new(
@@ -512,7 +512,7 @@ async fn run_test_file(
let pb = mp.add(ProgressBar::new(count));
pb.set_style(mp_style);
- pb.set_message(format!("{relative_path:?}"));
+ pb.set_message(relative_path.display().to_string());
// If DataFusion configuration has changed during test file runs, errors will be
// pushed to this vec.
@@ -631,7 +631,7 @@ async fn run_test_file_with_postgres(
let pb = mp.add(ProgressBar::new(count));
pb.set_style(mp_style);
- pb.set_message(format!("{relative_path:?}"));
+ pb.set_message(relative_path.display().to_string());
let mut runner = sqllogictest::Runner::new(|| {
Postgres::connect_with_tracked_sql(
@@ -690,7 +690,7 @@ async fn run_complete_file(
let pb = mp.add(ProgressBar::new(count));
pb.set_style(mp_style);
- pb.set_message(format!("{relative_path:?}"));
+ pb.set_message(relative_path.display().to_string());
let config_change_errors = Arc::new(Mutex::new(Vec::new()));
let mut runner = sqllogictest::Runner::new(|| async {
@@ -746,7 +746,7 @@ async fn run_complete_file_with_postgres(
let pb = mp.add(ProgressBar::new(count));
pb.set_style(mp_style);
- pb.set_message(format!("{relative_path:?}"));
+ pb.set_message(relative_path.display().to_string());
let mut runner = sqllogictest::Runner::new(|| {
Postgres::connect_with_tracked_sql(
diff --git a/datafusion/sqllogictest/src/engines/postgres_engine/mod.rs b/datafusion/sqllogictest/src/engines/postgres_engine/mod.rs
index f085fb5708..5d01befbf9 100644
--- a/datafusion/sqllogictest/src/engines/postgres_engine/mod.rs
+++ b/datafusion/sqllogictest/src/engines/postgres_engine/mod.rs
@@ -171,7 +171,7 @@ impl Postgres {
debug!("Handling COPY command: {sql}");
// Hacky way to find the 'filename' in the statement
- let mut tokens = canonical_sql.split_whitespace().peekable();
+ let mut tokens = canonical_sql.split_whitespace();
let mut filename = None;
// COPY FROM '/opt/data/csv/aggregate_test_100.csv' ...
diff --git a/datafusion/sqllogictest/src/util.rs b/datafusion/sqllogictest/src/util.rs
index b0cf32266e..b0713917ef 100644
--- a/datafusion/sqllogictest/src/util.rs
+++ b/datafusion/sqllogictest/src/util.rs
@@ -33,7 +33,7 @@ pub fn setup_scratch_dir(name: &Path) -> Result<()> {
let file_stem = name.file_stem().expect("File should have a stem");
let path = PathBuf::from("test_files").join("scratch").join(file_stem);
- info!("Creating scratch dir in {path:?}");
+ info!("Creating scratch dir in {}", path.display());
if path.exists() {
fs::remove_dir_all(&path)?;
}
diff --git a/datafusion/substrait/tests/cases/consumer_integration.rs b/datafusion/substrait/tests/cases/consumer_integration.rs
index 1f30a75377..b06230f71d 100644
--- a/datafusion/substrait/tests/cases/consumer_integration.rs
+++ b/datafusion/substrait/tests/cases/consumer_integration.rs
@@ -214,7 +214,7 @@ mod tests {
Ok(())
}
- #[ignore]
+ #[ignore = "Missing support for enum function arguments"]
#[tokio::test]
async fn tpch_test_07() -> Result<()> {
let plan_str = tpch_plan_to_string(7).await?;
@@ -222,7 +222,7 @@ mod tests {
Ok(())
}
- #[ignore]
+ #[ignore = "Missing support for enum function arguments"]
#[tokio::test]
async fn tpch_test_08() -> Result<()> {
let plan_str = tpch_plan_to_string(8).await?;
@@ -230,7 +230,7 @@ mod tests {
Ok(())
}
- #[ignore]
+ #[ignore = "Missing support for enum function arguments"]
#[tokio::test]
async fn tpch_test_09() -> Result<()> {
let plan_str = tpch_plan_to_string(9).await?;
@@ -352,7 +352,7 @@ mod tests {
Ok(())
}
- #[ignore]
+ #[ignore = "Test file is empty"]
#[tokio::test]
async fn tpch_test_15() -> Result<()> {
let plan_str = tpch_plan_to_string(15).await?;
diff --git a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
index 4dc4f03d05..1283295906 100644
--- a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
+++ b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs
@@ -1678,6 +1678,10 @@ async fn roundtrip_literal_named_struct() -> Result<()> {
}
#[tokio::test]
+#[expect(
+ clippy::literal_string_with_formatting_args,
+ reason = "The braces are part of the expected struct output, not format args"
+)]
async fn roundtrip_literal_renamed_struct() -> Result<()> {
// This test aims to hit a case where the struct column itself has the expected name, but its
// inner field needs to be renamed.
@@ -1880,7 +1884,7 @@ async fn new_test_grammar() -> Result<()> {
#[tokio::test]
async fn extension_logical_plan() -> Result<()> {
let ctx = create_context().await?;
- let validation_bytes = "MockUserDefinedLogicalPlan".as_bytes().to_vec();
+ let validation_bytes = b"MockUserDefinedLogicalPlan".to_vec();
let ext_plan = LogicalPlan::Extension(Extension {
node: Arc::new(MockUserDefinedLogicalPlan {
validation_bytes,