diff --git a/Cargo.toml b/Cargo.toml index 66bd816945908..e1846648632a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -283,12 +283,10 @@ explicit_iter_loop = "allow" # 189 hits float_cmp = "allow" # 8 hits; exact float comparisons are often intentional here from_iter_instead_of_collect = "allow" # 51 hits if_not_else = "allow" # 133 hits -ignored_unit_patterns = "allow" # 52 hits implicit_clone = "allow" # 198 hits implicit_hasher = "allow" # 17 hits; some sites feed arrow APIs that require the default hasher inline_always = "allow" # 45 hits items_after_statements = "allow" # 171 hits -manual_string_new = "allow" # 84 hits many_single_char_names = "allow" # 12 hits; short names are idiomatic in the numeric kernels map_unwrap_or = "allow" # 198 hits match_bool = "allow" # 46 hits @@ -300,7 +298,6 @@ missing_panics_doc = "allow" # 244 hits must_use_candidate = "allow" # 2726 hits needless_raw_string_hashes = "allow" # 540 hits redundant_closure_for_method_calls = "allow" # 686 hits -redundant_else = "allow" # 48 hits return_self_not_must_use = "allow" # 644 hits semicolon_if_nothing_returned = "allow" # 1353 hits similar_names = "allow" # 228 hits; too many false positives, e.g. `expr`/`exprs` diff --git a/benchmarks/src/cancellation.rs b/benchmarks/src/cancellation.rs index 5f7fdcc43d99d..47bd76e80fc0d 100644 --- a/benchmarks/src/cancellation.rs +++ b/benchmarks/src/cancellation.rs @@ -127,12 +127,12 @@ fn run_test(wait_time: u64, store: Arc) -> Result { let store = Arc::clone(&store); tokio::select! { biased; - _ = async move { + () = async move { datafusion(store).await.unwrap(); } => { println!("matched case doing work"); }, - _ = captured_token.cancelled() => { + () = captured_token.cancelled() => { println!("Received shutdown request"); return; }, diff --git a/benchmarks/src/sql_benchmark.rs b/benchmarks/src/sql_benchmark.rs index 24db7e0a0fb2e..3959b1211560a 100644 --- a/benchmarks/src/sql_benchmark.rs +++ b/benchmarks/src/sql_benchmark.rs @@ -509,7 +509,7 @@ impl SqlBenchmark { while let Some(result) = reader_result { match result { - Ok(_) => { + Ok(()) => { if !is_blank_or_comment_line(&line) { // boxing required because of recursion Box::pin(self.process_line(ctx, &mut reader, &mut line)).await?; @@ -824,7 +824,7 @@ impl BenchmarkDirective { loop { match reader_result { - Some(Ok(_)) => { + Some(Ok(())) => { if is_comment_line(line) { // comment, ignore } else if is_blank_line(line) { @@ -956,7 +956,7 @@ impl BenchmarkDirective { loop { match reader_result { - Some(Ok(_)) => { + Some(Ok(())) => { if line.trim() == "----" { found_break = true; break; @@ -1045,7 +1045,7 @@ impl BenchmarkDirective { loop { match reader_result { - Some(Ok(_)) => { + Some(Ok(())) => { if line.trim() == "----" { found_break = true; break; @@ -1108,7 +1108,7 @@ impl BenchmarkDirective { loop { match reader_result { - Some(Ok(_)) => { + Some(Ok(())) => { if is_comment_line(line) { // Clear the line buffer for the next iteration. line.clear(); @@ -1449,7 +1449,7 @@ fn read_query_from_reader( loop { match reader_result { - Some(Ok(_)) => { + Some(Ok(())) => { if is_comment_line(&line) { // comment, ignore } else if is_blank_line(&line) { diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rs index 288ce4b7351b6..c0c086e874760 100644 --- a/datafusion-cli/src/exec.rs +++ b/datafusion-cli/src/exec.rs @@ -69,7 +69,7 @@ pub async fn exec_from_lines( reader: &mut BufReader, print_options: &PrintOptions, ) -> Result<()> { - let mut query = "".to_owned(); + let mut query = String::new(); for line in reader.lines() { match line { @@ -79,10 +79,10 @@ pub async fn exec_from_lines( query.push_str(line); if line.ends_with(';') { match exec_and_print(ctx, print_options, query).await { - Ok(_) => {} + Ok(()) => {} Err(err) => eprintln!("{err}"), } - query = "".to_string(); + query = String::new(); } else { query.push('\n'); } @@ -175,7 +175,7 @@ pub async fn exec_from_repl( rl.add_history_entry(line.trim_end())?; tokio::select! { res = exec_and_print(ctx, print_options, line) => match res { - Ok(_) => {} + Ok(()) => {} Err(err) => eprintln!("{err}"), }, _ = signal::ctrl_c() => { diff --git a/datafusion-cli/src/functions.rs b/datafusion-cli/src/functions.rs index 0d7d8f33738fa..76c56d9029d49 100644 --- a/datafusion-cli/src/functions.rs +++ b/datafusion-cli/src/functions.rs @@ -665,8 +665,7 @@ impl TableFunctionImpl for StatisticsCacheFunc { { for (path, entry) in file_statistics_cache.list_entries() { path_arr.push(path.path.to_string()); - table_arr - .push(path.table.map_or_else(|| "".to_string(), |t| t.to_string())); + table_arr.push(path.table.map_or_else(String::new, |t| t.to_string())); file_modified_arr .push(Some(entry.value.meta.last_modified.timestamp_millis())); file_size_bytes_arr.push(entry.value.meta.size); diff --git a/datafusion-cli/src/print_format.rs b/datafusion-cli/src/print_format.rs index 0443a7a289602..d946bf8fa86a7 100644 --- a/datafusion-cli/src/print_format.rs +++ b/datafusion-cli/src/print_format.rs @@ -128,10 +128,9 @@ fn format_batches_with_maxrows( filtered_batches.push(sliced_batch); over_limit = true; break; - } else { - filtered_batches.push(batch.clone()); - row_count += batch.num_rows(); } + filtered_batches.push(batch.clone()); + row_count += batch.num_rows(); } let formatted = diff --git a/datafusion-examples/examples/data_io/parquet_encrypted_with_kms.rs b/datafusion-examples/examples/data_io/parquet_encrypted_with_kms.rs index 8e92f465eafe9..6193c656149f6 100644 --- a/datafusion-examples/examples/data_io/parquet_encrypted_with_kms.rs +++ b/datafusion-examples/examples/data_io/parquet_encrypted_with_kms.rs @@ -200,7 +200,7 @@ async fn read_encrypted_with_sql(ctx: &SessionContext, table_path: &str) -> Resu extensions_options! { struct EncryptionConfig { /// Comma-separated list of columns to encrypt - pub encrypted_columns: String, default = "".to_owned() + pub encrypted_columns: String, default = String::new() } } diff --git a/datafusion-examples/examples/udf/simple_udtf.rs b/datafusion-examples/examples/udf/simple_udtf.rs index 3b55a0456a0aa..0374e913db35c 100644 --- a/datafusion-examples/examples/udf/simple_udtf.rs +++ b/datafusion-examples/examples/udf/simple_udtf.rs @@ -110,10 +110,9 @@ impl TableProvider for LocalCsvTable { let batch_lines = max_return_lines - lines; batches.push(batch.slice(0, batch_lines)); break; - } else { - batches.push(batch.clone()); - lines += batch_lines; } + batches.push(batch.clone()); + lines += batch_lines; } batches } else { diff --git a/datafusion/catalog-listing/src/table.rs b/datafusion/catalog-listing/src/table.rs index 6c294fe077db4..569a1c9a71325 100644 --- a/datafusion/catalog-listing/src/table.rs +++ b/datafusion/catalog-listing/src/table.rs @@ -425,12 +425,11 @@ fn derive_common_ordering_from_files(file_groups: &[FileGroup]) -> Option 0, so ordering must be valid"); - CurrentOrderingState::SomeOrdering(ordering) } + let ordering = + LexOrdering::new(current.as_ref()[..prefix_len].to_vec()) + .expect("prefix_len > 0, so ordering must be valid"); + CurrentOrderingState::SomeOrdering(ordering) } // If one file has ordering and another doesn't, no common ordering // Return None and log a trace message explaining why diff --git a/datafusion/common/src/config.rs b/datafusion/common/src/config.rs index 347721c43d7cf..92ebddcfb20ed 100644 --- a/datafusion/common/src/config.rs +++ b/datafusion/common/src/config.rs @@ -2000,7 +2000,7 @@ config_namespace! { /// instead of being converted into a [`std::fmt::Error`] pub safe: bool, default = true /// Format string for nulls - pub null: String, default = "".into() + pub null: String, default = String::new() /// Date format for date arrays pub date_format: Option, default = Some("%Y-%m-%d".to_string()) /// Format for DateTime arrays @@ -3399,7 +3399,7 @@ impl Default for ConfigFileEncryptionProperties { config_namespace_with_hashmap! { pub struct ColumnEncryptionProperties { /// Per column encryption key - pub column_key_as_hex: String, default = "".to_string() + pub column_key_as_hex: String, default = String::new() /// Per column encryption key metadata pub column_metadata_as_hex: Option, default = None } @@ -3578,7 +3578,7 @@ pub struct ConfigFileDecryptionProperties { config_namespace_with_hashmap! { pub struct ColumnDecryptionProperties { /// Per column encryption key - pub column_key_as_hex: String, default = "".to_string() + pub column_key_as_hex: String, default = String::new() } } @@ -4548,7 +4548,7 @@ mod tests { let parsed_metadata = table_config.parquet.key_value_metadata.clone(); assert_eq!(parsed_metadata.get("should not exist1"), None); - assert_eq!(parsed_metadata.get("key1"), Some(&Some("".into()))); + assert_eq!(parsed_metadata.get("key1"), Some(&Some(String::new()))); assert_eq!(parsed_metadata.get("key2"), Some(&Some("value2".into()))); assert_eq!( parsed_metadata.get("key3"), diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rs index d1fcb50f73492..5e2df49d95530 100644 --- a/datafusion/common/src/error.rs +++ b/datafusion/common/src/error.rs @@ -555,11 +555,11 @@ impl DataFusionError { return format!("{}{}", Self::BACK_TRACE_SEP, back_trace); } - "".to_owned() + String::new() } #[cfg(not(feature = "backtrace"))] - "".to_owned() + String::new() } /// Return a [`DataFusionErrorBuilder`] to build a [`DataFusionError`] @@ -606,7 +606,7 @@ impl DataFusionError { pub fn message(&self) -> Cow<'_, str> { match *self { DataFusionError::ArrowError(ref desc, ref backtrace) => { - let backtrace = backtrace.clone().unwrap_or_else(|| "".to_owned()); + let backtrace = backtrace.clone().unwrap_or_else(String::new); Cow::Owned(format!("{desc}{backtrace}")) } #[cfg(feature = "parquet")] @@ -614,8 +614,7 @@ impl DataFusionError { DataFusionError::IoError(ref desc) => Cow::Owned(desc.to_string()), #[cfg(feature = "sql")] DataFusionError::SQL(ref desc, ref backtrace) => { - let backtrace: String = - backtrace.clone().unwrap_or_else(|| "".to_owned()); + let backtrace: String = backtrace.clone().unwrap_or_else(String::new); Cow::Owned(format!("{desc:?}{backtrace}")) } DataFusionError::Configuration(ref desc) => Cow::Owned(desc.to_string()), @@ -628,7 +627,7 @@ impl DataFusionError { DataFusionError::Plan(ref desc) => Cow::Owned(desc.to_string()), DataFusionError::SchemaError(ref desc, ref backtrace) => { let backtrace: &str = - &backtrace.as_ref().clone().unwrap_or_else(|| "".to_owned()); + &backtrace.as_ref().clone().unwrap_or_else(String::new); Cow::Owned(format!("{desc}{backtrace}")) } DataFusionError::Execution(ref desc) => Cow::Owned(desc.to_string()), diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs index bad526a3a2227..07579c60b292a 100644 --- a/datafusion/common/src/scalar/mod.rs +++ b/datafusion/common/src/scalar/mod.rs @@ -1703,9 +1703,9 @@ impl ScalarValue { | DataType::Date64 => ScalarValue::new_zero(datatype), // String types - DataType::Utf8 => Ok(ScalarValue::Utf8(Some("".to_string()))), - DataType::LargeUtf8 => Ok(ScalarValue::LargeUtf8(Some("".to_string()))), - DataType::Utf8View => Ok(ScalarValue::Utf8View(Some("".to_string()))), + DataType::Utf8 => Ok(ScalarValue::Utf8(Some(String::new()))), + DataType::LargeUtf8 => Ok(ScalarValue::LargeUtf8(Some(String::new()))), + DataType::Utf8View => Ok(ScalarValue::Utf8View(Some(String::new()))), // Binary types DataType::Binary => Ok(ScalarValue::Binary(Some(vec![]))), @@ -5650,7 +5650,7 @@ impl fmt::Display for ScalarValue { match epoch.checked_add_signed(Duration::try_days(v as i64).unwrap()) { Some(date) => date.to_string(), - None => "".to_string(), + None => String::new(), } }) )?, @@ -5661,7 +5661,7 @@ impl fmt::Display for ScalarValue { match epoch.checked_add_signed(Duration::try_milliseconds(v).unwrap()) { Some(date) => date.to_string(), - None => "".to_string(), + None => String::new(), } }) )?, @@ -10640,11 +10640,11 @@ mod tests { // Test string types assert_eq!( ScalarValue::new_default(&DataType::Utf8).unwrap(), - ScalarValue::Utf8(Some("".to_string())) + ScalarValue::Utf8(Some(String::new())) ); assert_eq!( ScalarValue::new_default(&DataType::LargeUtf8).unwrap(), - ScalarValue::LargeUtf8(Some("".to_string())) + ScalarValue::LargeUtf8(Some(String::new())) ); // Test binary types diff --git a/datafusion/common/src/test_util.rs b/datafusion/common/src/test_util.rs index 348fe2ef547f0..122f063788717 100644 --- a/datafusion/common/src/test_util.rs +++ b/datafusion/common/src/test_util.rs @@ -285,16 +285,16 @@ pub fn get_data_dir( let trimmed = dir.trim().to_string(); if !trimmed.is_empty() { let pb = PathBuf::from(trimmed); - if pb.is_dir() { - return Ok(pb); + return if pb.is_dir() { + Ok(pb) } else { - return Err(format!( + Err(format!( "the data dir `{}` defined by env {} not found", pb.display(), udf_env ) - .into()); - } + .into()) + }; } } diff --git a/datafusion/core/src/bin/print_functions_docs.rs b/datafusion/core/src/bin/print_functions_docs.rs index 10a259dd8b745..82ccf41750b19 100644 --- a/datafusion/core/src/bin/print_functions_docs.rs +++ b/datafusion/core/src/bin/print_functions_docs.rs @@ -93,7 +93,7 @@ fn print_docs( providers: Vec>, doc_sections: Vec, ) -> Result { - let mut docs = "".to_string(); + let mut docs = String::new(); // Ensure that all providers have documentation let mut providers_with_no_docs = HashSet::new(); diff --git a/datafusion/core/src/datasource/file_format/avro.rs b/datafusion/core/src/datasource/file_format/avro.rs index a8b48cc736c92..14c79f06ff631 100644 --- a/datafusion/core/src/datasource/file_format/avro.rs +++ b/datafusion/core/src/datasource/file_format/avro.rs @@ -60,7 +60,7 @@ mod tests { assert_eq!(11, batch.num_columns()); assert_eq!(2, batch.num_rows()); }) - .fold(0, |acc, _| async move { acc + 1i32 }) + .fold(0, |acc, ()| async move { acc + 1i32 }) .await; assert_eq!(tt_batches, 4 /* 8/2 */); diff --git a/datafusion/core/src/datasource/file_format/csv.rs b/datafusion/core/src/datasource/file_format/csv.rs index 2fb64fd6486e6..c3c983097bdc9 100644 --- a/datafusion/core/src/datasource/file_format/csv.rs +++ b/datafusion/core/src/datasource/file_format/csv.rs @@ -210,7 +210,7 @@ mod tests { assert_eq!(12, batch.num_columns()); assert_eq!(2, batch.num_rows()); }) - .fold(0, |acc, _| async move { acc + 1i32 }) + .fold(0, |acc, ()| async move { acc + 1i32 }) .await; assert_eq!(tt_batches, 50 /* 100/2 */); diff --git a/datafusion/core/src/datasource/file_format/json.rs b/datafusion/core/src/datasource/file_format/json.rs index 1f6f27242e723..02039a880c136 100644 --- a/datafusion/core/src/datasource/file_format/json.rs +++ b/datafusion/core/src/datasource/file_format/json.rs @@ -112,7 +112,7 @@ mod tests { assert_eq!(4, batch.num_columns()); assert_eq!(2, batch.num_rows()); }) - .fold(0, |acc, _| async move { acc + 1i32 }) + .fold(0, |acc, ()| async move { acc + 1i32 }) .await; assert_eq!(tt_batches, 6 /* 12/2 */); diff --git a/datafusion/core/src/datasource/file_format/parquet.rs b/datafusion/core/src/datasource/file_format/parquet.rs index bfcfb74848861..06cf0a8318c35 100644 --- a/datafusion/core/src/datasource/file_format/parquet.rs +++ b/datafusion/core/src/datasource/file_format/parquet.rs @@ -709,7 +709,7 @@ mod tests { assert_eq!(11, batch.num_columns()); assert_eq!(2, batch.num_rows()); }) - .fold(0, |acc, _| async move { acc + 1i32 }) + .fold(0, |acc, ()| async move { acc + 1i32 }) .await; assert_eq!(tt_batches, 4 /* 8/2 */); diff --git a/datafusion/core/src/datasource/listing_table_factory.rs b/datafusion/core/src/datasource/listing_table_factory.rs index 1e597e38fb5b1..5ebe0882befa4 100644 --- a/datafusion/core/src/datasource/listing_table_factory.rs +++ b/datafusion/core/src/datasource/listing_table_factory.rs @@ -332,7 +332,7 @@ fn get_extension(path: &str) -> String { let res = Path::new(path).extension().and_then(|ext| ext.to_str()); match res { Some(ext) => format!(".{ext}"), - None => "".to_string(), + None => String::new(), } } diff --git a/datafusion/core/src/datasource/physical_plan/csv.rs b/datafusion/core/src/datasource/physical_plan/csv.rs index 7980df87fa576..361e36b214341 100644 --- a/datafusion/core/src/datasource/physical_plan/csv.rs +++ b/datafusion/core/src/datasource/physical_plan/csv.rs @@ -764,7 +764,7 @@ mod tests { // get name of first part let paths = fs::read_dir(&out_dir).unwrap(); - let mut part_0_name: String = "".to_owned(); + let mut part_0_name: String = String::new(); for path in paths { let path = path.unwrap(); let name = path diff --git a/datafusion/core/src/datasource/physical_plan/json.rs b/datafusion/core/src/datasource/physical_plan/json.rs index 6b4361e0c4d07..0309a5ae4bcfb 100644 --- a/datafusion/core/src/datasource/physical_plan/json.rs +++ b/datafusion/core/src/datasource/physical_plan/json.rs @@ -410,7 +410,7 @@ mod tests { // get name of first part let paths = fs::read_dir(&out_dir).unwrap(); - let mut part_0_name: String = "".to_owned(); + let mut part_0_name: String = String::new(); for path in paths { let name = path .unwrap() diff --git a/datafusion/core/tests/execution/coop.rs b/datafusion/core/tests/execution/coop.rs index e02364a0530cc..60e1504bf8bf3 100644 --- a/datafusion/core/tests/execution/coop.rs +++ b/datafusion/core/tests/execution/coop.rs @@ -795,12 +795,12 @@ async fn stream_yields( result = join_handle => { match result { Ok(Poll::Pending) => Yielded::ReadyOrPending, - Ok(Poll::Ready(Ok(_))) => Yielded::ReadyOrPending, + Ok(Poll::Ready(Ok(()))) => Yielded::ReadyOrPending, Ok(Poll::Ready(Err(e))) => Yielded::Err(e), Err(_) => Yielded::Err(exec_datafusion_err!("join error")), } }, - _ = tokio::time::sleep(Duration::from_secs(10)) => { + () = tokio::time::sleep(Duration::from_secs(10)) => { Yielded::Timeout } }; diff --git a/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/query_builder.rs b/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/query_builder.rs index d32078ec6331f..6b1654ad70080 100644 --- a/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/query_builder.rs +++ b/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/query_builder.rs @@ -306,7 +306,7 @@ impl QueryBuilder { self.null_opt(), ) } else { - ("".to_string(), "".to_string()) + (String::new(), String::new()) }; let function = format!( diff --git a/datafusion/core/tests/fuzz_cases/window_fuzz.rs b/datafusion/core/tests/fuzz_cases/window_fuzz.rs index f69b5e9a41b02..b7a423e59f7a9 100644 --- a/datafusion/core/tests/fuzz_cases/window_fuzz.rs +++ b/datafusion/core/tests/fuzz_cases/window_fuzz.rs @@ -768,7 +768,7 @@ pub(crate) fn make_staggered_batches( let mut rng = StdRng::seed_from_u64(random_seed); let mut input123: Vec<(i32, i32, i32)> = vec![(0, 0, 0); len]; let mut input4: Vec = vec![0; len]; - let mut input5: Vec = vec!["".to_string(); len]; + let mut input5: Vec = vec![String::new(); len]; for v in &mut input123 { *v = ( rng.random_range(0..n_distinct) as i32, diff --git a/datafusion/core/tests/user_defined/user_defined_table_functions.rs b/datafusion/core/tests/user_defined/user_defined_table_functions.rs index 24205cf8c4010..bbb01b2a76c18 100644 --- a/datafusion/core/tests/user_defined/user_defined_table_functions.rs +++ b/datafusion/core/tests/user_defined/user_defined_table_functions.rs @@ -144,10 +144,9 @@ impl TableProvider for SimpleCsvTable { let batch_lines = max_return_lines as usize - lines; batches.push(batch.slice(0, batch_lines)); break; - } else { - batches.push(batch.clone()); - lines += batch_lines; } + batches.push(batch.clone()); + lines += batch_lines; } batches } else { diff --git a/datafusion/datasource-parquet/src/sink.rs b/datafusion/datasource-parquet/src/sink.rs index 3c66d4dcd74fb..7eca0def43e28 100644 --- a/datafusion/datasource-parquet/src/sink.rs +++ b/datafusion/datasource-parquet/src/sink.rs @@ -693,47 +693,46 @@ fn spawn_parquet_parallel_serialization_task( .await?; current_rg_rows += rb.num_rows(); break; - } else { - let rows_left = max_row_group_rows - current_rg_rows; - let a = rb.slice(0, rows_left); - send_arrays_to_col_writers( - &col_array_channels, - &a, - Arc::clone(&ctx.schema), - ) - .await?; + } + let rows_left = max_row_group_rows - current_rg_rows; + let a = rb.slice(0, rows_left); + send_arrays_to_col_writers( + &col_array_channels, + &a, + Arc::clone(&ctx.schema), + ) + .await?; + + // Signal the parallel column writers that the RowGroup is done, join and finalize RowGroup + // on a separate task, so that we can immediately start on the next RG before waiting + // for the current one to finish. + drop(col_array_channels); + let finalize_rg_task = spawn_rg_join_and_finalize_task( + column_writer_handles, + max_row_group_rows, + &ctx.pool, + encoding_time.clone(), + ); - // Signal the parallel column writers that the RowGroup is done, join and finalize RowGroup - // on a separate task, so that we can immediately start on the next RG before waiting - // for the current one to finish. - drop(col_array_channels); - let finalize_rg_task = spawn_rg_join_and_finalize_task( - column_writer_handles, - max_row_group_rows, - &ctx.pool, - encoding_time.clone(), - ); + // Do not surface error from closed channel (means something + // else hit an error, and the plan is shutting down). + if serialize_tx.send(finalize_rg_task).await.is_err() { + return Ok(()); + } - // Do not surface error from closed channel (means something - // else hit an error, and the plan is shutting down). - if serialize_tx.send(finalize_rg_task).await.is_err() { - return Ok(()); - } + current_rg_rows = 0; + rb = rb.slice(rows_left, rb.num_rows() - rows_left); - current_rg_rows = 0; - rb = rb.slice(rows_left, rb.num_rows() - rows_left); - - row_group_index += 1; - let col_writers = row_group_writer_factory - .create_column_writers(row_group_index)?; - (column_writer_handles, col_array_channels) = - spawn_column_parallel_row_group_writer( - col_writers, - max_buffer_rb, - &ctx.pool, - &encoding_time, - )?; - } + row_group_index += 1; + let col_writers = + row_group_writer_factory.create_column_writers(row_group_index)?; + (column_writer_handles, col_array_channels) = + spawn_column_parallel_row_group_writer( + col_writers, + max_buffer_rb, + &ctx.pool, + &encoding_time, + )?; } } diff --git a/datafusion/datasource/src/file_compression_type.rs b/datafusion/datasource/src/file_compression_type.rs index 89efb580652b1..cad89c880ba58 100644 --- a/datafusion/datasource/src/file_compression_type.rs +++ b/datafusion/datasource/src/file_compression_type.rs @@ -65,7 +65,7 @@ impl GetExt for FileCompressionType { BZIP2 => ".bz2".to_owned(), XZ => ".xz".to_owned(), ZSTD => ".zst".to_owned(), - UNCOMPRESSED => "".to_owned(), + UNCOMPRESSED => String::new(), } } } diff --git a/datafusion/datasource/src/memory.rs b/datafusion/datasource/src/memory.rs index 4c79cf4a9851d..f302fedd2b5db 100644 --- a/datafusion/datasource/src/memory.rs +++ b/datafusion/datasource/src/memory.rs @@ -623,9 +623,8 @@ impl MemorySourceConfig { } // Successful repartition. Break inner loop, and return to outer `cnt_to_repartition` loop. break; - } else { - cannot_split_further.push(new_partitions.remove(0)); } + cannot_split_further.push(new_partitions.remove(0)); } } let mut partitions = max_heap diff --git a/datafusion/datasource/src/write/orchestration.rs b/datafusion/datasource/src/write/orchestration.rs index cd821b3b87897..387e929b9f30d 100644 --- a/datafusion/datasource/src/write/orchestration.rs +++ b/datafusion/datasource/src/write/orchestration.rs @@ -115,7 +115,7 @@ pub(crate) async fn serialize_rb_stream_to_object_store( match task.join().await { Ok(Ok((cnt, bytes))) => { match writer.write_all(&bytes).await { - Ok(_) => (), + Ok(()) => (), Err(e) => { return SerializedRecordBatchResult::failure( None, @@ -142,7 +142,7 @@ pub(crate) async fn serialize_rb_stream_to_object_store( } match serialize_task.join().await { - Ok(Ok(_)) => (), + Ok(Ok(())) => (), Ok(Err(e)) => return SerializedRecordBatchResult::failure(Some(writer), e), Err(_) => { return SerializedRecordBatchResult::failure( diff --git a/datafusion/execution/src/async_stream.rs b/datafusion/execution/src/async_stream.rs index 0462c53a0ffd3..e49f0c6980c29 100644 --- a/datafusion/execution/src/async_stream.rs +++ b/datafusion/execution/src/async_stream.rs @@ -402,7 +402,7 @@ mod test { let s = async_stream(|mut emitter| async move { select! { - _ = do_stuff_async() => emitter.emit(()).await, + () = do_stuff_async() => emitter.emit(()).await, else => emitter.emit(()).await, } }); @@ -422,8 +422,8 @@ mod test { let s = async_stream(|mut emitter| async move { select! { - _ = do_stuff_async() => emitter.emit("hey").await, - _ = more_async_work() => emitter.emit("hey").await, + () = do_stuff_async() => emitter.emit("hey").await, + () = more_async_work() => emitter.emit("hey").await, else => emitter.emit("hey").await, } }); @@ -464,7 +464,7 @@ mod test { pin_mut!(s); for i in 0..3 { - assert_matches!(tx.send(i).await, Ok(_)); + assert_matches!(tx.send(i).await, Ok(())); assert_eq!(Some(i), s.next().await); } @@ -573,7 +573,7 @@ mod test { let _ = async_stream(|mut emitter| async move { select! { - _ = do_stuff_async() => { + () = do_stuff_async() => { let another_s = async_try_stream(|mut inner_emitter| async move { inner_emitter.emit(()).await; Ok(()) diff --git a/datafusion/expr-common/src/casts.rs b/datafusion/expr-common/src/casts.rs index 3518c02772672..2677d6bd7353f 100644 --- a/datafusion/expr-common/src/casts.rs +++ b/datafusion/expr-common/src/casts.rs @@ -1478,9 +1478,9 @@ mod tests { // Test empty string expect_cast( - ScalarValue::Utf8(Some("".to_string())), + ScalarValue::Utf8(Some(String::new())), DataType::Utf8View, - ExpectedCast::Value(ScalarValue::Utf8View(Some("".to_string()))), + ExpectedCast::Value(ScalarValue::Utf8View(Some(String::new()))), ); // Test large string diff --git a/datafusion/expr-common/src/interval_arithmetic.rs b/datafusion/expr-common/src/interval_arithmetic.rs index 9f1291353dc29..e1168cf8352ed 100644 --- a/datafusion/expr-common/src/interval_arithmetic.rs +++ b/datafusion/expr-common/src/interval_arithmetic.rs @@ -1410,18 +1410,18 @@ pub fn satisfy_greater( ); if !left.upper.is_null() && left.upper <= right.lower { - if !strict && left.upper == right.lower { + return if !strict && left.upper == right.lower { // Singleton intervals: - return Ok(Some(( + Ok(Some(( Interval::new(left.upper.clone(), left.upper.clone()), Interval::new(left.upper.clone(), left.upper.clone()), - ))); + ))) } else { // Left-hand side: <--======----0------------> // Right-hand side: <------------0--======----> // No intersection, infeasible to propagate: - return Ok(None); - } + Ok(None) + }; } // Only the lower bound of left-hand side and the upper bound of the right-hand diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs index 75b3a60af1465..bc5fd4977d1f7 100644 --- a/datafusion/expr/src/expr_schema.rs +++ b/datafusion/expr/src/expr_schema.rs @@ -317,7 +317,7 @@ impl ExprSchemable for Expr { .transpose()?; Ok(match has_nullable { // If a nullable subexpression is found, the result may also be nullable. - Some(_) => true, + Some(()) => true, // If the list is too long, we assume it is nullable. None if list.len() + 1 > MAX_INSPECT_LIMIT => true, // All the subexpressions are non-nullable, so the result must be non-nullable. @@ -385,7 +385,7 @@ impl ExprSchemable for Expr { // There is at least one reachable nullable 'then' expression, so the case // expression itself is nullable. // Use `Result::map` to propagate the error from `nullable_then` if there is one. - nullable_then.map(|_| true) + nullable_then.map(|()| true) } else if let Some(e) = &case.else_expr { // There are no reachable nullable 'then' expressions, so all we still need to // check is the 'else' expression's nullability. @@ -1244,7 +1244,7 @@ mod tests { let placeholder_meta = FieldMetadata::from(placeholder_meta); let expr = Expr::Placeholder(Placeholder::new_with_field( - "".to_string(), + String::new(), Some( Field::new("", DataType::Utf8, true) .with_metadata(placeholder_meta.to_hashmap()) @@ -1269,7 +1269,7 @@ mod tests { // Non-nullable placeholder field should remain non-nullable let expr = Expr::Placeholder(Placeholder::new_with_field( - "".to_string(), + String::new(), Some(Field::new("", DataType::Utf8, false).into()), )); let expr_field = expr.to_field(&schema).unwrap().1; diff --git a/datafusion/expr/src/logical_plan/display.rs b/datafusion/expr/src/logical_plan/display.rs index 3009253f53d11..0710c8b4d7ad0 100644 --- a/datafusion/expr/src/logical_plan/display.rs +++ b/datafusion/expr/src/logical_plan/display.rs @@ -485,7 +485,7 @@ impl<'a, 'b> PgJsonVisitor<'a, 'b> { let filter_expr = filter .as_ref() .map(|expr| format!(" Filter: {expr}")) - .unwrap_or_else(|| "".to_string()); + .unwrap_or_else(String::new); json!({ "Node Type": format!("{} Join", join_type), "Join Constraint": format!("{:?}", join_constraint), diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs index 649c82a16ad88..c3a9d43b799ec 100644 --- a/datafusion/expr/src/logical_plan/plan.rs +++ b/datafusion/expr/src/logical_plan/plan.rs @@ -2117,7 +2117,7 @@ impl LogicalPlan { .collect(); format!(" projection=[{}]", names.join(", ")) } - _ => "".to_string(), + _ => String::new(), }; write!(f, "TableScan: {table_name}{projected_fields}")?; @@ -2257,7 +2257,7 @@ impl LogicalPlan { let filter_expr = filter .as_ref() .map(|expr| format!(" Filter: {expr}")) - .unwrap_or_else(|| "".to_string()); + .unwrap_or_else(String::new); let null_aware_expr = if *null_aware { " null_aware" } else { "" }; let join_type = if filter.is_none() @@ -2386,7 +2386,7 @@ impl LogicalPlan { if let Some(sort_expr) = sort_expr { expr_vec_fmt!(sort_expr) } else { - "".to_string() + String::new() }, ), }, @@ -6265,7 +6265,7 @@ mod tests { .unwrap(); let prepared_builder = LogicalPlanBuilder::new(plan) .prepare( - "".to_string(), + String::new(), vec![Field::new("", DataType::Int32, true).into()], ) .unwrap(); diff --git a/datafusion/expr/src/predicate_bounds.rs b/datafusion/expr/src/predicate_bounds.rs index aa947416c87b5..3e7191b6bb33b 100644 --- a/datafusion/expr/src/predicate_bounds.rs +++ b/datafusion/expr/src/predicate_bounds.rs @@ -158,11 +158,11 @@ impl PredicateBoundsEvaluator<'_> { fn is_null(&self, expr: &Expr) -> NullableInterval { // Fast path for literals if let Expr::Literal(scalar, _) = expr { - if scalar.is_null() { - return NullableInterval::TRUE; + return if scalar.is_null() { + NullableInterval::TRUE } else { - return NullableInterval::FALSE; - } + NullableInterval::FALSE + }; } // If `expr` is not nullable, we can be certain `expr` is not null diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 8e86cb3685e90..dde7105f9362b 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -115,17 +115,17 @@ pub fn fields_with_udf( let type_signature = &signature.type_signature; if current_fields.is_empty() && type_signature != &TypeSignature::UserDefined { - if type_signature.supports_zero_argument() { - return Ok(vec![]); + return if type_signature.supports_zero_argument() { + Ok(vec![]) } else if type_signature.used_to_support_zero_arguments() { // Special error to help during upgrade: https://github.com/apache/datafusion/issues/13763 - return plan_err!( + plan_err!( "'{}' does not support zero arguments. Use TypeSignature::Nullary for zero arguments", func.name() - ); + ) } else { - return plan_err!("'{}' does not support zero arguments", func.name()); - } + plan_err!("'{}' does not support zero arguments", func.name()) + }; } let current_types = current_fields .iter() @@ -246,15 +246,15 @@ pub fn value_fields_with_higher_order_udf( current_fields.iter().zip(expected.iter()).enumerate() { match (actual, expected) { - (ValueOrLambda::Value(_), ValueOrLambda::Value(_)) => {} - (ValueOrLambda::Lambda(_), ValueOrLambda::Lambda(_)) => {} - (ValueOrLambda::Value(_), ValueOrLambda::Lambda(_)) => { + (ValueOrLambda::Value(_), ValueOrLambda::Value(())) => {} + (ValueOrLambda::Lambda(_), ValueOrLambda::Lambda(())) => {} + (ValueOrLambda::Value(_), ValueOrLambda::Lambda(())) => { let name = func.name(); return plan_err!( "The function '{name}' expected a lambda at position {i} but received a value" ); } - (ValueOrLambda::Lambda(_), ValueOrLambda::Value(_)) => { + (ValueOrLambda::Lambda(_), ValueOrLambda::Value(())) => { let name = func.name(); return plan_err!( "The function '{name}' expected a value at position {i} but received a lambda" @@ -438,20 +438,20 @@ pub fn data_types( let type_signature = &signature.type_signature; if current_types.is_empty() && type_signature != &TypeSignature::UserDefined { - if type_signature.supports_zero_argument() { - return Ok(vec![]); + return if type_signature.supports_zero_argument() { + Ok(vec![]) } else if type_signature.used_to_support_zero_arguments() { // Special error to help during upgrade: https://github.com/apache/datafusion/issues/13763 - return plan_err!( + plan_err!( "function '{}' has signature {type_signature} which does not support zero arguments. Use TypeSignature::Nullary for zero arguments", function_name.as_ref() - ); + ) } else { - return plan_err!( + plan_err!( "Function '{}' has signature {type_signature} which does not support zero arguments", function_name.as_ref() - ); - } + ) + }; } let valid_types = @@ -566,9 +566,8 @@ fn get_valid_types_with_udf( func.name(), errors.join(",") ); - } else { - res } + res } _ => get_valid_types(func.name(), signature, current_types)?, }; diff --git a/datafusion/functions-aggregate/src/correlation.rs b/datafusion/functions-aggregate/src/correlation.rs index 21859006ea943..14545ee238cd8 100644 --- a/datafusion/functions-aggregate/src/correlation.rs +++ b/datafusion/functions-aggregate/src/correlation.rs @@ -212,11 +212,11 @@ impl Accumulator for CorrelationAccumulator { && let ScalarValue::Float64(Some(s1)) = stddev1 && let ScalarValue::Float64(Some(s2)) = stddev2 { - if s1 == 0_f64 || s2 == 0_f64 { - return Ok(ScalarValue::Float64(None)); + return if s1 == 0_f64 || s2 == 0_f64 { + Ok(ScalarValue::Float64(None)) } else { - return Ok(ScalarValue::Float64(Some(c / s1 / s2))); - } + Ok(ScalarValue::Float64(Some(c / s1 / s2))) + }; } Ok(ScalarValue::Float64(None)) diff --git a/datafusion/functions-aggregate/src/first_last.rs b/datafusion/functions-aggregate/src/first_last.rs index d36ea5d63074b..0b9e5cb5f9d48 100644 --- a/datafusion/functions-aggregate/src/first_last.rs +++ b/datafusion/functions-aggregate/src/first_last.rs @@ -912,10 +912,9 @@ impl FirstValueAccumulator { } } return Ok(None); - } else { - // If not ignoring nulls, return the first value if it exists. - return Ok((!value.is_empty()).then_some(0)); } + // If not ignoring nulls, return the first value if it exists. + return Ok((!value.is_empty()).then_some(0)); } let sort_columns = ordering_values @@ -1301,9 +1300,8 @@ impl LastValueAccumulator { } } return Ok(None); - } else { - return Ok((!value.is_empty()).then_some(value.len() - 1)); } + return Ok((!value.is_empty()).then_some(value.len() - 1)); } let sort_columns = ordering_values diff --git a/datafusion/functions-nested/src/planner.rs b/datafusion/functions-nested/src/planner.rs index e96fdb7d4baca..8ca7bde758f60 100644 --- a/datafusion/functions-nested/src/planner.rs +++ b/datafusion/functions-nested/src/planner.rs @@ -85,13 +85,13 @@ impl ExprPlanner for NestedFunctionPlanner { let right_list_ndims = list_ndims(&right_type); // if both are list if left_list_ndims > 0 && right_list_ndims > 0 { - if op == BinaryOperator::AtArrow { + return if op == BinaryOperator::AtArrow { // array1 @> array2 -> array_has_all(array1, array2) - return Ok(PlannerResult::Planned(array_has_all(left, right))); + Ok(PlannerResult::Planned(array_has_all(left, right))) } else { // array1 <@ array2 -> array_has_all(array2, array1) - return Ok(PlannerResult::Planned(array_has_all(right, left))); - } + Ok(PlannerResult::Planned(array_has_all(right, left))) + }; } } diff --git a/datafusion/functions-window/src/nth_value.rs b/datafusion/functions-window/src/nth_value.rs index b3678e80f2273..75da3ab443f9e 100644 --- a/datafusion/functions-window/src/nth_value.rs +++ b/datafusion/functions-window/src/nth_value.rs @@ -407,9 +407,8 @@ impl PartitionEvaluator for NthValueEvaluator { state.window_frame_range.end - 1; } return Ok(()); - } else { - // Fall through to the main case because there are no nulls } + // Fall through to the main case because there are no nulls } // Do not memoize for other kinds when nulls are ignored NthValueKind::Last | NthValueKind::Nth => return Ok(()), diff --git a/datafusion/functions/src/datetime/common.rs b/datafusion/functions/src/datetime/common.rs index 118b6b371bc17..39707e907c53d 100644 --- a/datafusion/functions/src/datetime/common.rs +++ b/datafusion/functions/src/datetime/common.rs @@ -517,9 +517,8 @@ where if let Ok(inner) = r { val = Some(Ok(op2(inner))); break; - } else { - val = Some(r); } + val = Some(r); } } diff --git a/datafusion/functions/src/datetime/date_bin.rs b/datafusion/functions/src/datetime/date_bin.rs index 15cdecc3c2842..4e59e87cd1925 100644 --- a/datafusion/functions/src/datetime/date_bin.rs +++ b/datafusion/functions/src/datetime/date_bin.rs @@ -531,9 +531,8 @@ fn date_bin_impl( return not_impl_err!( "DATE_BIN stride does not support combination of month, day and nanosecond intervals" ); - } else { - Interval::Months(months as i64) } + Interval::Months(months as i64) } else { let nanos = (TimeDelta::try_days(days as i64).unwrap() + Duration::nanoseconds(nanos)) diff --git a/datafusion/functions/src/regex/regexpcount.rs b/datafusion/functions/src/regex/regexpcount.rs index 2920b687ed33f..e19c4ea358220 100644 --- a/datafusion/functions/src/regex/regexpcount.rs +++ b/datafusion/functions/src/regex/regexpcount.rs @@ -674,7 +674,7 @@ mod tests { let re = regexp_count_with_scalar_values(&[ ScalarValue::Utf8(Some(value.to_string())), - ScalarValue::Utf8(Some("".to_string())), + ScalarValue::Utf8(Some(String::new())), start_sv.clone(), ]); match re { @@ -686,7 +686,7 @@ mod tests { let re = regexp_count_with_scalar_values(&[ ScalarValue::LargeUtf8(Some(value.to_string())), - ScalarValue::LargeUtf8(Some("".to_string())), + ScalarValue::LargeUtf8(Some(String::new())), start_sv.clone(), ]); match re { @@ -698,7 +698,7 @@ mod tests { let re = regexp_count_with_scalar_values(&[ ScalarValue::Utf8View(Some(value.to_string())), - ScalarValue::Utf8View(Some("".to_string())), + ScalarValue::Utf8View(Some(String::new())), start_sv, ]); match re { diff --git a/datafusion/functions/src/string/ascii.rs b/datafusion/functions/src/string/ascii.rs index db539a4d11719..8e99fb66afad2 100644 --- a/datafusion/functions/src/string/ascii.rs +++ b/datafusion/functions/src/string/ascii.rs @@ -242,7 +242,7 @@ mod tests { fn test_functions() -> Result<()> { test_ascii!(Some(String::from("x")), Ok(Some(120))); test_ascii!(Some(String::from("a")), Ok(Some(97))); - test_ascii!(Some(String::from("")), Ok(Some(0))); + test_ascii!(Some(String::new()), Ok(Some(0))); test_ascii!(Some(String::from("🚀")), Ok(Some(128640))); test_ascii!(Some(String::from("\n")), Ok(Some(10))); test_ascii!(Some(String::from("\t")), Ok(Some(9))); diff --git a/datafusion/functions/src/string/concat.rs b/datafusion/functions/src/string/concat.rs index aa42d918eb4b7..1396a0108a8b3 100644 --- a/datafusion/functions/src/string/concat.rs +++ b/datafusion/functions/src/string/concat.rs @@ -319,7 +319,7 @@ pub(crate) fn simplify_concat(args: Vec) -> Result { } let mut new_args = Vec::with_capacity(args.len()); - let mut contiguous_scalar = "".to_string(); + let mut contiguous_scalar = String::new(); let return_type = { let data_types: Vec<_> = args @@ -369,7 +369,7 @@ pub(crate) fn simplify_concat(args: Vec) -> Result { .push(lit(ScalarValue::Utf8View(Some(contiguous_scalar)))), _ => unreachable!(), } - contiguous_scalar = "".to_string(); + contiguous_scalar = String::new(); } new_args.push(arg); } diff --git a/datafusion/functions/src/string/octet_length.rs b/datafusion/functions/src/string/octet_length.rs index 02df262ee27aa..73d52140d6573 100644 --- a/datafusion/functions/src/string/octet_length.rs +++ b/datafusion/functions/src/string/octet_length.rs @@ -185,9 +185,9 @@ mod tests { ); test_function!( OctetLengthFunc::new(), - vec![ColumnarValue::Scalar(ScalarValue::Utf8(Some( - String::from("") - )))], + vec![ColumnarValue::Scalar(ScalarValue::Utf8( + Some(String::new()) + ))], Ok(Some(0)), i32, Int32, @@ -224,7 +224,7 @@ mod tests { test_function!( OctetLengthFunc::new(), vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( - String::from("") + String::new() )))], Ok(Some(0)), i32, diff --git a/datafusion/functions/src/string/replace.rs b/datafusion/functions/src/string/replace.rs index 549b8e1a3b0f9..0f84ed16e446c 100644 --- a/datafusion/functions/src/string/replace.rs +++ b/datafusion/functions/src/string/replace.rs @@ -429,7 +429,7 @@ mod tests { ReplaceFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(String::from("abc")))), - ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(String::from("x")))), ], Ok(Some("abc")), diff --git a/datafusion/functions/src/string/split_part.rs b/datafusion/functions/src/string/split_part.rs index 9b73a1af88501..d11bb90c13e9b 100644 --- a/datafusion/functions/src/string/split_part.rs +++ b/datafusion/functions/src/string/split_part.rs @@ -747,7 +747,7 @@ mod tests { SplitPartFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a,b")))), - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::Int64(Some(1))), ], Ok(Some("a,b")), @@ -759,7 +759,7 @@ mod tests { SplitPartFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a,b")))), - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::Int64(Some(2))), ], Ok(Some("")), @@ -797,7 +797,7 @@ mod tests { SplitPartFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a,b")))), - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::Int64(Some(-1))), ], Ok(Some("a,b")), @@ -821,7 +821,7 @@ mod tests { SplitPartFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a,b")))), - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::Int64(Some(-2))), ], Ok(Some("")), diff --git a/datafusion/functions/src/unicode/character_length.rs b/datafusion/functions/src/unicode/character_length.rs index 9f0d952a02636..e92ab2b494a1a 100644 --- a/datafusion/functions/src/unicode/character_length.rs +++ b/datafusion/functions/src/unicode/character_length.rs @@ -228,7 +228,7 @@ mod tests { test_character_length!(Some(String::from("josé")), Ok(Some(4))); // test long strings (more than 12 bytes for StringView) test_character_length!(Some(String::from("joséjoséjoséjosé")), Ok(Some(16))); - test_character_length!(Some(String::from("")), Ok(Some(0))); + test_character_length!(Some(String::new()), Ok(Some(0))); test_character_length!(None, Ok(None)); } diff --git a/datafusion/functions/src/unicode/find_in_set.rs b/datafusion/functions/src/unicode/find_in_set.rs index 5378aaf714f4d..b7156569ab32d 100644 --- a/datafusion/functions/src/unicode/find_in_set.rs +++ b/datafusion/functions/src/unicode/find_in_set.rs @@ -443,7 +443,7 @@ mod tests { test_function!( FindInSetFunc::new(), vec![ - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a,b,c")))), ], Ok(Some(0)), @@ -455,7 +455,7 @@ mod tests { FindInSetFunc::new(), vec![ ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("a")))), - ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::from("")))), + ColumnarValue::Scalar(ScalarValue::Utf8(Some(String::new()))), ], Ok(Some(0)), i32, diff --git a/datafusion/functions/src/unicode/initcap.rs b/datafusion/functions/src/unicode/initcap.rs index 0332ab5d4427f..ddbfa3eb1936a 100644 --- a/datafusion/functions/src/unicode/initcap.rs +++ b/datafusion/functions/src/unicode/initcap.rs @@ -398,7 +398,7 @@ mod tests { test_function!( InitcapFunc::new(), vec![ColumnarValue::Scalar(ScalarValue::Utf8View(Some( - "".to_string() + String::new() )))], Ok(Some("")), &str, diff --git a/datafusion/functions/src/unicode/left.rs b/datafusion/functions/src/unicode/left.rs index 0788e69d92528..bbf7d9ac3554f 100644 --- a/datafusion/functions/src/unicode/left.rs +++ b/datafusion/functions/src/unicode/left.rs @@ -281,7 +281,7 @@ mod tests { test_function!( LeftFunc::new(), vec![ - ColumnarValue::Scalar(ScalarValue::Utf8View(Some("".to_string()))), + ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::from(200i64)), ], Ok(Some("")), diff --git a/datafusion/functions/src/unicode/lpad.rs b/datafusion/functions/src/unicode/lpad.rs index 0ffd02714957c..32932697844ee 100644 --- a/datafusion/functions/src/unicode/lpad.rs +++ b/datafusion/functions/src/unicode/lpad.rs @@ -725,7 +725,7 @@ mod tests { test_lpad!( Some("hi".into()), ScalarValue::Int64(Some(5i64)), - Some("".into()), + Some(String::new()), Ok(Some("hi")) ); test_lpad!( diff --git a/datafusion/functions/src/unicode/right.rs b/datafusion/functions/src/unicode/right.rs index 21fb0690a11a2..77d155cbe5aeb 100644 --- a/datafusion/functions/src/unicode/right.rs +++ b/datafusion/functions/src/unicode/right.rs @@ -281,7 +281,7 @@ mod tests { test_function!( RightFunc::new(), vec![ - ColumnarValue::Scalar(ScalarValue::Utf8View(Some("".to_string()))), + ColumnarValue::Scalar(ScalarValue::Utf8View(Some(String::new()))), ColumnarValue::Scalar(ScalarValue::from(200i64)), ], Ok(Some("")), diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rs index 8a1dcc12ef874..623c23cee4672 100644 --- a/datafusion/optimizer/src/push_down_filter.rs +++ b/datafusion/optimizer/src/push_down_filter.rs @@ -1174,9 +1174,8 @@ impl OptimizerRule for PushDownFilter { { filter.input = Arc::new(LogicalPlan::TableScan(scan)); return Ok(Transformed::no(LogicalPlan::Filter(filter))); - } else { - scan.filters = new_scan_filters; } + scan.filters = new_scan_filters; // Compose predicates to be of `Unsupported` or `Inexact` pushdown type, // and also include volatile and subquery-containing filters diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs index 5436bd092163e..e83def89395c2 100644 --- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs +++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs @@ -1550,12 +1550,10 @@ impl TreeNodeRewriter for Simplifier<'_> { // CASE WHEN false THEN A ELSE B END --> B if let Some(else_expr) = else_expr { return Ok(Transformed::yes(*else_expr)); - // CASE WHEN false THEN A END --> NULL - } else { - let null = - Expr::Literal(ScalarValue::try_new_null(&out_type)?, None); - return Ok(Transformed::yes(null)); } + // CASE WHEN false THEN A END --> NULL + let null = Expr::Literal(ScalarValue::try_new_null(&out_type)?, None); + return Ok(Transformed::yes(null)); } Transformed::yes(Expr::Case(Case { diff --git a/datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs index 17112d4f0ae24..a5b27da3d8b18 100644 --- a/datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs +++ b/datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs @@ -55,8 +55,8 @@ impl TreeNodeRewriter for ShortenInListSimplifier { ) { let first_val = list[0].clone(); - if negated { - return Ok(Transformed::yes(list.iter().skip(1).cloned().fold( + return if negated { + Ok(Transformed::yes(list.iter().skip(1).cloned().fold( (*expr.clone()).not_eq(first_val), |acc, y| { // Note that `A and B and C and D` is a left-deep tree structure @@ -78,16 +78,16 @@ impl TreeNodeRewriter for ShortenInListSimplifier { // The code below maintain the left-deep tree structure. acc.and((*expr.clone()).not_eq(y)) }, - ))); + ))) } else { - return Ok(Transformed::yes(list.iter().skip(1).cloned().fold( + Ok(Transformed::yes(list.iter().skip(1).cloned().fold( (*expr.clone()).eq(first_val), |acc, y| { // Same reasoning as above acc.or((*expr.clone()).eq(y)) }, - ))); - } + ))) + }; } Ok(Transformed::no(expr)) diff --git a/datafusion/optimizer/src/simplify_expressions/utils.rs b/datafusion/optimizer/src/simplify_expressions/utils.rs index 78d801630c7ba..7ed15be9fa3e3 100644 --- a/datafusion/optimizer/src/simplify_expressions/utils.rs +++ b/datafusion/optimizer/src/simplify_expressions/utils.rs @@ -91,19 +91,19 @@ pub fn delete_xor_in_complex_expr(expr: &Expr, needle: &Expr, is_left: bool) -> if result_expr.normalize_eq(needle) { return needle.clone(); } else if xor_counter % 2 == 0 { - if is_left { - return Expr::BinaryExpr(BinaryExpr::new( + return if is_left { + Expr::BinaryExpr(BinaryExpr::new( Box::new(needle.clone()), Operator::BitwiseXor, Box::new(result_expr), - )); + )) } else { - return Expr::BinaryExpr(BinaryExpr::new( + Expr::BinaryExpr(BinaryExpr::new( Box::new(result_expr), Operator::BitwiseXor, Box::new(needle.clone()), - )); - } + )) + }; } result_expr } diff --git a/datafusion/physical-expr-common/src/binary_map.rs b/datafusion/physical-expr-common/src/binary_map.rs index 16e00b6549fb4..6024006f3278b 100644 --- a/datafusion/physical-expr-common/src/binary_map.rs +++ b/datafusion/physical-expr-common/src/binary_map.rs @@ -818,7 +818,7 @@ mod tests { let values: ArrayRef = Arc::new(StringArray::from_iter_values( (0..1_000).map(|i| format!("distinct value number {i}")), )); - map.insert_if_new(&values, |_| (), |_| ()); + map.insert_if_new(&values, |_| (), |()| {}); let populated_size = map.size(); assert!(populated_size > INITIAL_BUFFER_CAPACITY); @@ -950,8 +950,8 @@ mod tests { let value = format!("{}:{i}", batch * 1_000 + i); format!("{value:value_len$}") }))); - lazy.insert_if_new(&values, |_| (), |_| ()); - pre_allocated.insert_if_new(&values, |_| (), |_| ()); + lazy.insert_if_new(&values, |_| (), |()| {}); + pre_allocated.insert_if_new(&values, |_| (), |()| {}); assert_eq!(lazy.buffer.len(), pre_allocated.buffer.len()); assert_eq!( @@ -973,7 +973,7 @@ mod tests { let values: ArrayRef = Arc::new(StringArray::from_iter_values( (0..10).map(|i| format!("distinct value number {i}")), )); - lazy.insert_if_new(&values, |_| (), |_| ()); + lazy.insert_if_new(&values, |_| (), |()| {}); assert!( lazy.buffer.capacity() < INITIAL_BUFFER_CAPACITY, diff --git a/datafusion/physical-expr-common/src/binary_view_map.rs b/datafusion/physical-expr-common/src/binary_view_map.rs index 29f4014c5f9a4..7c0cdae11b70f 100644 --- a/datafusion/physical-expr-common/src/binary_view_map.rs +++ b/datafusion/physical-expr-common/src/binary_view_map.rs @@ -904,7 +904,7 @@ mod tests { let values: ArrayRef = Arc::new(StringViewArray::from_iter_values( (0..1_000).map(|i| format!("distinct value number {i}")), )); - map.insert_if_new(&values, |_| (), |_| ()); + map.insert_if_new(&values, |_| (), |()| {}); let warm_size = map.map.allocation_size(); assert!(warm_size > 0); @@ -944,7 +944,7 @@ mod tests { ])); let mut map = ArrowBytesViewMap::new(OutputType::Utf8View); - map.insert_if_new(&values, |_| (), |_| {}); + map.insert_if_new(&values, |_| (), |()| {}); // Make unused vector capacity explicit; the completed buffers were created // by the map's flush path. @@ -989,7 +989,7 @@ mod tests { assert_eq!(map.size() - legacy_size, retained_capacity_delta); let size_after_insert = map.size(); - map.insert_if_new(&values, |_| (), |_| {}); + map.insert_if_new(&values, |_| (), |()| {}); assert_eq!(map.size(), size_after_insert); } diff --git a/datafusion/physical-expr/src/equivalence/class.rs b/datafusion/physical-expr/src/equivalence/class.rs index 06f384ac2db03..63966b4fd5edc 100644 --- a/datafusion/physical-expr/src/equivalence/class.rs +++ b/datafusion/physical-expr/src/equivalence/class.rs @@ -395,9 +395,8 @@ impl EquivalenceGroup { // If this class becomes trivial, remove it entirely: self.remove_class_at_idx(idx); continue; - } else { - cls.constant = None; } + cls.constant = None; } idx += 1; } diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rs index dfb1d136d0ff0..9e237ecf6cb1d 100644 --- a/datafusion/physical-expr/src/expressions/binary.rs +++ b/datafusion/physical-expr/src/expressions/binary.rs @@ -589,20 +589,18 @@ impl PhysicalExpr for BinaryExpr { ); } ColumnarValue::Scalar(scalar) => { - if let ScalarValue::Boolean(v) = scalar { + return if let ScalarValue::Boolean(v) = scalar { // A scalar RHS applies uniformly to all selected rows. if let Some(v) = v { - return Ok(uniform_pre_selection_result( - *v, fill_value, lhs, - )); + Ok(uniform_pre_selection_result(*v, fill_value, lhs)) } else { - return pre_selection_scatter(&mask, None, fill_value); + pre_selection_scatter(&mask, None, fill_value) } } else { - return internal_err!( + internal_err!( "Expected boolean scalar value, found: {right_ret:?}" - ); - } + ) + }; } } } @@ -1259,11 +1257,11 @@ fn check_short_circuit(lhs: &ColumnarValue, op: &Operator) -> ShortCircuitStrate // Return Left for: // - AND with false value // - OR with true value - if (is_and && !is_true) || (!is_and && *is_true) { - return ShortCircuitStrategy::ReturnLeft; + return if (is_and && !is_true) || (!is_and && *is_true) { + ShortCircuitStrategy::ReturnLeft } else { - return ShortCircuitStrategy::ReturnRight; - } + ShortCircuitStrategy::ReturnRight + }; } } } diff --git a/datafusion/physical-expr/src/expressions/case.rs b/datafusion/physical-expr/src/expressions/case.rs index dd98029c739a8..94e223398b2b9 100644 --- a/datafusion/physical-expr/src/expressions/case.rs +++ b/datafusion/physical-expr/src/expressions/case.rs @@ -1311,7 +1311,7 @@ impl PhysicalExpr for CaseExpr { // There is at least one reachable nullable 'then' expression, so the case // expression itself is nullable. // Use `Result::map` to propagate the error from `nullable_then` if there is one. - nullable_then.map(|_| true) + nullable_then.map(|()| true) } else if let Some(e) = &self.body.else_expr { // There are no reachable nullable 'then' expressions, so all we still need to // check is the 'else' expression's nullability. diff --git a/datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs b/datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs index ae9774c9f8c2d..b82edf1969e3c 100644 --- a/datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs +++ b/datafusion/physical-optimizer/src/ensure_requirements/enforce_distribution.rs @@ -234,9 +234,8 @@ pub fn adjust_input_keys_ordering( if aggregate_exec.mode() == &AggregateMode::FinalPartitioned { return reorder_aggregate_keys(requirements, aggregate_exec) .map(Transformed::yes); - } else { - requirements.data.clear(); } + requirements.data.clear(); } else { // Keep everything unchanged return Ok(Transformed::no(requirements)); diff --git a/datafusion/physical-optimizer/src/ensure_requirements/enforce_sorting/sort_pushdown.rs b/datafusion/physical-optimizer/src/ensure_requirements/enforce_sorting/sort_pushdown.rs index d7f556b90d9fe..9450c98ee9603 100644 --- a/datafusion/physical-optimizer/src/ensure_requirements/enforce_sorting/sort_pushdown.rs +++ b/datafusion/physical-optimizer/src/ensure_requirements/enforce_sorting/sort_pushdown.rs @@ -320,28 +320,27 @@ fn pushdown_sorts_helper( distribution_requirement: Distribution::UnspecifiedDistribution, }; return Ok(Transformed::yes(sort_push_down)); - } else { - // Sort was unnecessary, just propagate the stricter fetch and - // ordering requirements. Reset distribution to Unspecified - // because the sort we're removing may have been below a - // partition-merging node (like SortPreservingMergeExec) that - // already satisfies SinglePartition. - sort_push_down.data.fetch = min_fetch(sort_fetch, parent_fetch); - sort_push_down.data.distribution_requirement = - Distribution::UnspecifiedDistribution; - let current_is_stricter = eqp.requirements_compatible( - sort_ordering.clone().into(), - parent_requirement.first().clone(), - ); - sort_push_down.data.ordering_requirement = if current_is_stricter { - Some(OrderingRequirements::from(sort_ordering)) - } else { - Some(parent_requirement) - }; - // Recursive call to helper, so it doesn't transform_down and miss - // the new node (previous child of sort): - return pushdown_sorts_helper(sort_push_down); } + // Sort was unnecessary, just propagate the stricter fetch and + // ordering requirements. Reset distribution to Unspecified + // because the sort we're removing may have been below a + // partition-merging node (like SortPreservingMergeExec) that + // already satisfies SinglePartition. + sort_push_down.data.fetch = min_fetch(sort_fetch, parent_fetch); + sort_push_down.data.distribution_requirement = + Distribution::UnspecifiedDistribution; + let current_is_stricter = eqp.requirements_compatible( + sort_ordering.clone().into(), + parent_requirement.first().clone(), + ); + sort_push_down.data.ordering_requirement = if current_is_stricter { + Some(OrderingRequirements::from(sort_ordering)) + } else { + Some(parent_requirement) + }; + // Recursive call to helper, so it doesn't transform_down and miss + // the new node (previous child of sort): + return pushdown_sorts_helper(sort_push_down); } let can_push_fetch_to_children = can_push_fetch_through(&plan); diff --git a/datafusion/physical-plan/src/aggregates/aggregate_stream.rs b/datafusion/physical-plan/src/aggregates/aggregate_stream.rs index 23f74e6352a15..4d1609b999035 100644 --- a/datafusion/physical-plan/src/aggregates/aggregate_stream.rs +++ b/datafusion/physical-plan/src/aggregates/aggregate_stream.rs @@ -396,7 +396,7 @@ impl AggregateStream { match result .and_then(|allocated| this.reservation.try_grow(allocated)) { - Ok(_) => continue, + Ok(()) => continue, Err(e) => Err(e), } } diff --git a/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs b/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs index 24bb4c16d887c..fa3c44c51089b 100644 --- a/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs +++ b/datafusion/physical-plan/src/aggregates/grouped_hash_stream.rs @@ -987,7 +987,7 @@ impl GroupedHashAggregateStream { let oom = match self.update_memory_reservation() { Err(e @ DataFusionError::ResourcesExhausted(_)) => e, Err(e) => return Err(e), - Ok(_) => return Ok(None), + Ok(()) => return Ok(None), }; match self.oom_mode { diff --git a/datafusion/physical-plan/src/buffer.rs b/datafusion/physical-plan/src/buffer.rs index df87fee7da087..00656c6e642c0 100644 --- a/datafusion/physical-plan/src/buffer.rs +++ b/datafusion/physical-plan/src/buffer.rs @@ -429,7 +429,7 @@ impl MemoryBufferedStream { // in order to consider aborting the stream let item_or_err = tokio::select! { biased; - _ = batch_tx.closed() => break, + () = batch_tx.closed() => break, // Catch a panic in the input poll so it surfaces as a stream error // instead of dropping `batch_tx` and looking like a clean EOF. polled = AssertUnwindSafe(input.next()).catch_unwind() => { diff --git a/datafusion/physical-plan/src/column_rewriter.rs b/datafusion/physical-plan/src/column_rewriter.rs index e03f5ab5d3d9d..1caf4877e53e2 100644 --- a/datafusion/physical-plan/src/column_rewriter.rs +++ b/datafusion/physical-plan/src/column_rewriter.rs @@ -51,20 +51,20 @@ impl TreeNodeRewriter for PhysicalColumnRewriter<'_> { node: Self::Node, ) -> datafusion_common::Result> { if let Some(column) = node.downcast_ref::() { - if let Some(new_column) = self.column_map.get(column) { + return if let Some(new_column) = self.column_map.get(column) { // jump to prevent rewriting the new sub-expression again - return Ok(Transformed::new( + Ok(Transformed::new( Arc::clone(new_column), true, TreeNodeRecursion::Jump, - )); + )) } else { // Column not found in mapping - return Err(DataFusionError::Internal(format!( + Err(DataFusionError::Internal(format!( "Column {column:?} not found in column mapping {:?}", self.column_map - ))); - } + ))) + }; } Ok(Transformed::no(node)) } diff --git a/datafusion/physical-plan/src/display.rs b/datafusion/physical-plan/src/display.rs index 44522e76afa31..404be3c210e44 100644 --- a/datafusion/physical-plan/src/display.rs +++ b/datafusion/physical-plan/src/display.rs @@ -681,7 +681,7 @@ impl ExecutionPlanVisitor for GraphvizVisitor<'_, '_> { let label = { format!("{}", Wrapper(plan, self.t)) }; let metrics = match self.show_metrics { - ShowMetrics::None => "".to_string(), + ShowMetrics::None => String::new(), ShowMetrics::Aggregated => { if let Some(metrics) = plan.metrics() { let mut metrics = metrics @@ -722,7 +722,7 @@ impl ExecutionPlanVisitor for GraphvizVisitor<'_, '_> { .map_err(|_e| fmt::Error)?; format!("statistics=[{stats}]") } else { - "".to_string() + String::new() }; let delimiter = if !metrics.is_empty() && !statistics.is_empty() { diff --git a/datafusion/physical-plan/src/filter.rs b/datafusion/physical-plan/src/filter.rs index 12771eec78470..45c6dc72d374a 100644 --- a/datafusion/physical-plan/src/filter.rs +++ b/datafusion/physical-plan/src/filter.rs @@ -521,11 +521,11 @@ impl DisplayAs for FilterExec { .join(", ") ) } else { - "".to_string() + String::new() }; let fetch = self .fetch - .map_or_else(|| "".to_string(), |f| format!(", fetch={f}")); + .map_or_else(String::new, |f| format!(", fetch={f}")); write!( f, "FilterExec: {}{}{}", diff --git a/datafusion/physical-plan/src/joins/asof_join.rs b/datafusion/physical-plan/src/joins/asof_join.rs index 3e67e929d0971..96968fd2f23d3 100644 --- a/datafusion/physical-plan/src/joins/asof_join.rs +++ b/datafusion/physical-plan/src/joins/asof_join.rs @@ -585,7 +585,7 @@ async fn collect_right_input( let batches = input .try_fold(Vec::new(), |mut batches, batch| { let batch_size = memory_counter.count_batch(&batch); - futures::future::ready(reservation.try_grow(batch_size).map(|_| { + futures::future::ready(reservation.try_grow(batch_size).map(|()| { metrics.build_mem_used.add(batch_size); batches.push(batch); batches diff --git a/datafusion/physical-plan/src/joins/hash_join/exec.rs b/datafusion/physical-plan/src/joins/hash_join/exec.rs index 24b70a22e37e5..94875cb6189aa 100644 --- a/datafusion/physical-plan/src/joins/hash_join/exec.rs +++ b/datafusion/physical-plan/src/joins/hash_join/exec.rs @@ -1319,10 +1319,10 @@ impl DisplayAs for HashJoinExec { fn fmt_as(&self, t: DisplayFormatType, f: &mut fmt::Formatter) -> fmt::Result { match t { DisplayFormatType::Default | DisplayFormatType::Verbose => { - let display_filter = self.filter.as_ref().map_or_else( - || "".to_string(), - |f| format!(", filter={}", f.expression()), - ); + let display_filter = self + .filter + .as_ref() + .map_or_else(String::new, |f| format!(", filter={}", f.expression())); let display_projections = if self.contains_projection() { format!( ", projection=[{}]", @@ -1339,7 +1339,7 @@ impl DisplayAs for HashJoinExec { .join(", ") ) } else { - "".to_string() + String::new() }; let display_null_equality = if self.null_equality() == NullEquality::NullEqualsNull { diff --git a/datafusion/physical-plan/src/joins/nested_loop_join.rs b/datafusion/physical-plan/src/joins/nested_loop_join.rs index fd2e0ae21c2ea..d22270c3550b5 100644 --- a/datafusion/physical-plan/src/joins/nested_loop_join.rs +++ b/datafusion/physical-plan/src/joins/nested_loop_join.rs @@ -504,10 +504,10 @@ impl DisplayAs for NestedLoopJoinExec { fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> std::fmt::Result { match t { DisplayFormatType::Default | DisplayFormatType::Verbose => { - let display_filter = self.filter.as_ref().map_or_else( - || "".to_string(), - |f| format!(", filter={}", f.expression()), - ); + let display_filter = self + .filter + .as_ref() + .map_or_else(String::new, |f| format!(", filter={}", f.expression())); let display_projections = if self.contains_projection() { format!( ", projection=[{}]", @@ -524,7 +524,7 @@ impl DisplayAs for NestedLoopJoinExec { .join(", ") ) } else { - "".to_string() + String::new() }; write!( f, diff --git a/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs b/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs index 911eca0a97928..55d02bccef1c9 100644 --- a/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs +++ b/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs @@ -433,10 +433,10 @@ impl DisplayAs for SortMergeJoinExec { Self::static_name(), self.join_type, on, - self.filter.as_ref().map_or_else( - || "".to_string(), - |f| format!(", filter={}", f.expression()) - ), + self.filter.as_ref().map_or_else(String::new, |f| format!( + ", filter={}", + f.expression() + )), display_null_equality, display_projections, ) diff --git a/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs b/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs index 96b903f63bc1e..eb2c27df7c5ef 100644 --- a/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs +++ b/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs @@ -1075,7 +1075,7 @@ impl MaterializingSortMergeJoinStream { fn allocate_reservation(&mut self, mut buffered_batch: BufferedBatch) -> Result<()> { match self.reservation.try_grow(buffered_batch.size_estimation) { - Ok(_) => { + Ok(()) => { buffered_batch.reserved_amount = buffered_batch.size_estimation; self.join_metrics .peak_mem_used() diff --git a/datafusion/physical-plan/src/joins/symmetric_hash_join.rs b/datafusion/physical-plan/src/joins/symmetric_hash_join.rs index 99a12796c688e..5665ddef0f9e3 100644 --- a/datafusion/physical-plan/src/joins/symmetric_hash_join.rs +++ b/datafusion/physical-plan/src/joins/symmetric_hash_join.rs @@ -368,10 +368,10 @@ impl DisplayAs for SymmetricHashJoinExec { fn fmt_as(&self, t: DisplayFormatType, f: &mut fmt::Formatter) -> fmt::Result { match t { DisplayFormatType::Default | DisplayFormatType::Verbose => { - let display_filter = self.filter.as_ref().map_or_else( - || "".to_string(), - |f| format!(", filter={}", f.expression()), - ); + let display_filter = self + .filter + .as_ref() + .map_or_else(String::new, |f| format!(", filter={}", f.expression())); let on = self .on .iter() diff --git a/datafusion/physical-plan/src/limit.rs b/datafusion/physical-plan/src/limit.rs index 73d98d8105215..6e029240cd9eb 100644 --- a/datafusion/physical-plan/src/limit.rs +++ b/datafusion/physical-plan/src/limit.rs @@ -672,9 +672,8 @@ impl LimitStream { Poll::Ready(Some(Ok(batch))) => { if batch.num_rows() > 0 { break poll; - } else { - // Continue to poll input stream } + // Continue to poll input stream } Poll::Ready(Some(Err(_e))) => break poll, Poll::Ready(None) => break poll, diff --git a/datafusion/physical-plan/src/render_tree.rs b/datafusion/physical-plan/src/render_tree.rs index 40e2763698093..2fb220df8aa33 100644 --- a/datafusion/physical-plan/src/render_tree.rs +++ b/datafusion/physical-plan/src/render_tree.rs @@ -204,7 +204,7 @@ fn create_tree_recursive( if let Some((key, value)) = line.split_once('=') { extra_info.insert(key.to_string(), value.to_string()); } else { - extra_info.insert(line.to_string(), "".to_string()); + extra_info.insert(line.to_string(), String::new()); } } diff --git a/datafusion/physical-plan/src/repartition/mod.rs b/datafusion/physical-plan/src/repartition/mod.rs index 0bbc68641c6e9..cc956b3a36dd5 100644 --- a/datafusion/physical-plan/src/repartition/mod.rs +++ b/datafusion/physical-plan/src/repartition/mod.rs @@ -232,7 +232,7 @@ impl OutputChannel { // across an await point. let (payload, is_memory_batch) = { match self.reservation.try_grow(size) { - Ok(_) => (Ok(RepartitionBatch::Memory(batch)), true), + Ok(()) => (Ok(RepartitionBatch::Memory(batch)), true), Err(_) => match self.spill_writer.push_batch(&batch) { Ok(()) => (Ok(RepartitionBatch::Spilled), false), Err(err) => (Err(err), false), diff --git a/datafusion/physical-plan/src/sorts/multi_level_merge.rs b/datafusion/physical-plan/src/sorts/multi_level_merge.rs index b5aa5c4d54015..3bd97359e118e 100644 --- a/datafusion/physical-plan/src/sorts/multi_level_merge.rs +++ b/datafusion/physical-plan/src/sorts/multi_level_merge.rs @@ -514,7 +514,7 @@ impl MultiLevelMergeBuilder { // this is not and there should be some upper limit to memory // reservation so we won't starve the system. match try_grow_reservation_to_at_least(reservation, total_needed) { - Ok(_) => { + Ok(()) => { number_of_spills_to_read_for_current_phase += 1; } // If we can't grow the reservation, we need to stop diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index 490ea7cc85776..4259696a04b64 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -836,7 +836,7 @@ impl ExternalSorter { let size = get_reserved_bytes_for_record_batch(input)?; match self.reservation.try_grow(size) { - Ok(_) => Ok(()), + Ok(()) => Ok(()), Err(e) => { if self.in_mem_batches.is_empty() { return Err(Self::err_with_oom_context(e)); diff --git a/datafusion/physical-plan/src/spill/spill_pool.rs b/datafusion/physical-plan/src/spill/spill_pool.rs index a3366d6766170..f27c862e6f93a 100644 --- a/datafusion/physical-plan/src/spill/spill_pool.rs +++ b/datafusion/physical-plan/src/spill/spill_pool.rs @@ -1765,7 +1765,7 @@ mod tests { let mut inner = Some(self.inner.read_stream()?); Ok(Box::pin( futures::stream::once(tokio::time::sleep(delay)) - .flat_map(move |_| inner.take().expect("polled once")), + .flat_map(move |()| inner.take().expect("polled once")), )) } diff --git a/datafusion/physical-plan/src/test/exec.rs b/datafusion/physical-plan/src/test/exec.rs index f9517469d55ab..043c81012b881 100644 --- a/datafusion/physical-plan/src/test/exec.rs +++ b/datafusion/physical-plan/src/test/exec.rs @@ -1069,12 +1069,11 @@ impl Stream for PanicStream { self.ready = false; let batch = RecordBatch::new_empty(Arc::clone(&self.schema)); return Poll::Ready(Some(Ok(batch))); - } else { - self.ready = true; - // get called again - cx.waker().wake_by_ref(); - return Poll::Pending; } + self.ready = true; + // get called again + cx.waker().wake_by_ref(); + return Poll::Pending; } panic!("PanickingStream did panic: {}", self.partition) } diff --git a/datafusion/physical-plan/src/topk/mod.rs b/datafusion/physical-plan/src/topk/mod.rs index 0ca700cb37655..c97aba3552f5b 100644 --- a/datafusion/physical-plan/src/topk/mod.rs +++ b/datafusion/physical-plan/src/topk/mod.rs @@ -815,13 +815,12 @@ impl TopK { (&batch).record_output(&metrics.baseline); batches.push(Ok(batch)); break; - } else { - let head = batch.slice(0, batch_size); - (&head).record_output(&metrics.baseline); - batches.push(Ok(head)); - let remaining_length = batch.num_rows() - batch_size; - batch = batch.slice(batch_size, remaining_length); } + let head = batch.slice(0, batch_size); + (&head).record_output(&metrics.baseline); + batches.push(Ok(head)); + let remaining_length = batch.num_rows() - batch_size; + batch = batch.slice(batch_size, remaining_length); } } Ok(Box::pin(RecordBatchStreamAdapter::new( diff --git a/datafusion/physical-plan/src/union.rs b/datafusion/physical-plan/src/union.rs index da496b99fc6f7..1652c1a5d660c 100644 --- a/datafusion/physical-plan/src/union.rs +++ b/datafusion/physical-plan/src/union.rs @@ -394,9 +394,8 @@ impl ExecutionPlan for UnionExec { baseline_metrics, None, ))); - } else { - partition -= input.output_partitioning().partition_count(); } + partition -= input.output_partitioning().partition_count(); } warn!("Error in Union: Partition {partition} not found"); diff --git a/datafusion/proto/src/logical_plan/from_proto.rs b/datafusion/proto/src/logical_plan/from_proto.rs index 1eac6f974beed..c1da0b3ee9418 100644 --- a/datafusion/proto/src/logical_plan/from_proto.rs +++ b/datafusion/proto/src/logical_plan/from_proto.rs @@ -205,7 +205,7 @@ pub fn parse_expr( let window_frame = WindowFrame::try_from(window_frame.clone())?; window_frame .regularize_order_bys(&mut order_by) - .map(|_| window_frame) + .map(|()| window_frame) }) .transpose()? .ok_or_else(|| { diff --git a/datafusion/proto/src/physical_plan/mod.rs b/datafusion/proto/src/physical_plan/mod.rs index 887337e291f43..93492ec612ad9 100644 --- a/datafusion/proto/src/physical_plan/mod.rs +++ b/datafusion/proto/src/physical_plan/mod.rs @@ -1358,7 +1358,7 @@ pub trait PhysicalPlanNodeExt: Sized { let mut buf: Vec = vec![]; match codec.try_encode(Arc::clone(&plan_clone), &mut buf, proto_converter) { - Ok(_) => { + Ok(()) => { let inputs: Vec = plan_clone .children() .into_iter() @@ -2065,7 +2065,7 @@ impl ComposedPhysicalExtensionCodec { // find the encoder for (position, codec) in self.codecs.iter().enumerate() { match encode(codec.as_ref(), &mut data) { - Ok(_) => { + Ok(()) => { encoder_position = Some(position as u32); break; } diff --git a/datafusion/proto/src/physical_plan/to_proto.rs b/datafusion/proto/src/physical_plan/to_proto.rs index 5ae57752de676..94fa42b09b48b 100644 --- a/datafusion/proto/src/physical_plan/to_proto.rs +++ b/datafusion/proto/src/physical_plan/to_proto.rs @@ -323,7 +323,7 @@ pub fn serialize_physical_expr_with_converter( } else { let mut buf: Vec = vec![]; match codec.try_encode_expr(value, &mut buf, &ctx) { - Ok(_) => { + Ok(()) => { let inputs: Vec = value .children() .into_iter() diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs index 750b20323ad2e..65894f2d437a5 100644 --- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs @@ -1673,7 +1673,7 @@ async fn roundtrip_logical_plan_prepared_statement_with_metadata() -> Result<()> .unwrap(); let prepared = LogicalPlanBuilder::new(plan) .prepare( - "".to_string(), + String::new(), vec![ Field::new("", DataType::Int32, true) .with_metadata( diff --git a/datafusion/pruning/src/pruning_predicate.rs b/datafusion/pruning/src/pruning_predicate.rs index c3362c63299e1..c7179d03a262c 100644 --- a/datafusion/pruning/src/pruning_predicate.rs +++ b/datafusion/pruning/src/pruning_predicate.rs @@ -1701,12 +1701,12 @@ fn build_predicate_expression( } if let Some(not) = expr.downcast_ref::() { // match !col (don't do so recursively) - if let Some(col) = not.arg().downcast_ref::() { - return build_single_column_expr(col, schema, required_columns, true) - .unwrap_or_else(|| unhandled_hook.handle(expr)); + return if let Some(col) = not.arg().downcast_ref::() { + build_single_column_expr(col, schema, required_columns, true) + .unwrap_or_else(|| unhandled_hook.handle(expr)) } else { - return unhandled_hook.handle(expr); - } + unhandled_hook.handle(expr) + }; } if let Some(in_list) = expr.downcast_ref::() { // Keep the existing expression shape for lists of at most 20 values. @@ -1751,9 +1751,8 @@ fn build_predicate_expression( max_in_list_size, properties, ); - } else { - return unhandled_hook.handle(expr); } + return unhandled_hook.handle(expr); } let (left, op, right) = { diff --git a/datafusion/spark/src/function/string/char.rs b/datafusion/spark/src/function/string/char.rs index 5d6de3ae368e3..0f6efd23ee4d0 100644 --- a/datafusion/spark/src/function/string/char.rs +++ b/datafusion/spark/src/function/string/char.rs @@ -86,9 +86,9 @@ fn spark_chr(args: &[ColumnarValue]) -> Result { } ColumnarValue::Scalar(ScalarValue::Int64(Some(value))) => { if value < 0 { - Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some( - "".to_string(), - )))) + Ok(ColumnarValue::Scalar(ScalarValue::Utf8( + Some(String::new()), + ))) } else { match core::char::from_u32((value % 256) as u32) { Some(ch) => Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some( diff --git a/datafusion/spark/src/function/string/format_string.rs b/datafusion/spark/src/function/string/format_string.rs index 131d1c14dfe5b..d7c1039623542 100644 --- a/datafusion/spark/src/function/string/format_string.rs +++ b/datafusion/spark/src/function/string/format_string.rs @@ -1817,13 +1817,13 @@ impl ConversionSpecifier { let (prefix, suffix) = if negative && self.negative_in_parentheses { ("(".to_owned(), ")".to_owned()) } else if negative { - ("-".to_owned(), "".to_owned()) + ("-".to_owned(), String::new()) } else if self.force_sign { - ("+".to_owned(), "".to_owned()) + ("+".to_owned(), String::new()) } else if self.space_sign { - (" ".to_owned(), "".to_owned()) + (" ".to_owned(), String::new()) } else { - ("".to_owned(), "".to_owned()) + (String::new(), String::new()) }; self.format_decimal_integer(writer, abs_val, prefix, &suffix); diff --git a/datafusion/spark/src/function/string/length.rs b/datafusion/spark/src/function/string/length.rs index 8c5539a0577d8..8e19e84edfc4c 100644 --- a/datafusion/spark/src/function/string/length.rs +++ b/datafusion/spark/src/function/string/length.rs @@ -270,7 +270,7 @@ mod tests { test_spark_length_string!(Some(String::from("josé")), Ok(Some(4))); // test long strings (more than 12 bytes for StringView) test_spark_length_string!(Some(String::from("joséjoséjoséjosé")), Ok(Some(16))); - test_spark_length_string!(Some(String::from("")), Ok(Some(0))); + test_spark_length_string!(Some(String::new()), Ok(Some(0))); test_spark_length_string!(None, Ok(None)); test_spark_length_binary!(Some(String::from("chars").into_bytes()), Ok(Some(5))); @@ -280,7 +280,7 @@ mod tests { Some(String::from("joséjoséjoséjosé").into_bytes()), Ok(Some(20)) ); - test_spark_length_binary!(Some(String::from("").into_bytes()), Ok(Some(0))); + test_spark_length_binary!(Some(String::new().into_bytes()), Ok(Some(0))); test_spark_length_binary!(None, Ok(None)); Ok(()) diff --git a/datafusion/spark/src/function/url/parse_url.rs b/datafusion/spark/src/function/url/parse_url.rs index c385f43e49343..bed23c24f4276 100644 --- a/datafusion/spark/src/function/url/parse_url.rs +++ b/datafusion/spark/src/function/url/parse_url.rs @@ -404,7 +404,7 @@ mod tests { fn test_parse_path_empty_vs_root() -> Result<()> { assert_eq!( ParseUrl::parse("https://example.com", "PATH", None)?, - Some("".to_string()) + Some(String::new()) ); assert_eq!( ParseUrl::parse("https://example.com/", "PATH", None)?, @@ -430,7 +430,7 @@ mod tests { ); assert_eq!( ParseUrl::parse("http://ex.com?key=", "QUERY", Some("key"))?, - Some("".to_string()) + Some(String::new()) ); assert_eq!( ParseUrl::parse("http://ex.com?keyonly", "QUERY", Some("keyonly"))?, @@ -449,10 +449,10 @@ mod tests { #[test] fn test_parse_empty_path_file() -> Result<()> { - assert_eq!(ParseUrl::parse("", "PATH", None)?, Some("".to_string())); + assert_eq!(ParseUrl::parse("", "PATH", None)?, Some(String::new())); assert_eq!( ParseUrl::parse("http://example.com", "FILE", None)?, - Some("".to_string()) + Some(String::new()) ); assert_eq!( ParseUrl::parse("http://example.com?foo=bar", "FILE", None)?, @@ -460,7 +460,7 @@ mod tests { ); assert_eq!( ParseUrl::parse("http://example.com#fragment", "FILE", None)?, - Some("".to_string()) + Some(String::new()) ); assert_eq!( ParseUrl::parse("http://example.com/?foo=bar", "FILE", None)?, diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs index a7f7979a67b36..4417799d3c3e8 100644 --- a/datafusion/sql/src/expr/function.rs +++ b/datafusion/sql/src/expr/function.rs @@ -358,20 +358,19 @@ impl SqlToRel<'_, S> { if name.eq_ignore_ascii_case(inner.name()) { return Ok(Expr::ScalarFunction(inner)); - } else { - // If the function is called by an alias, a verbose string representation is created - // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` - // to ensure the output column name matches the user's query. - let arg_names = inner - .args - .iter() - .map(|arg| arg.to_string()) - .collect::>() - .join(","); - let verbose_alias = format!("{name}({arg_names})"); - - return Ok(Expr::ScalarFunction(inner).alias(verbose_alias)); } + // If the function is called by an alias, a verbose string representation is created + // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` + // to ensure the output column name matches the user's query. + let arg_names = inner + .args + .iter() + .map(|arg| arg.to_string()) + .collect::>() + .join(","); + let verbose_alias = format!("{name}({arg_names})"); + + return Ok(Expr::ScalarFunction(inner).alias(verbose_alias)); } if let Some(fm) = self.context_provider.get_higher_order_meta(&name) { @@ -536,20 +535,19 @@ impl SqlToRel<'_, S> { if name.eq_ignore_ascii_case(inner.name()) { return Ok(Expr::HigherOrderFunction(inner)); - } else { - // If the function is called by an alias, a verbose string representation is created - // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` - // to ensure the output column name matches the user's query. - let arg_names = inner - .args - .iter() - .map(|arg| arg.to_string()) - .collect::>() - .join(","); - let verbose_alias = format!("{name}({arg_names})"); - - return Ok(Expr::HigherOrderFunction(inner).alias(verbose_alias)); } + // If the function is called by an alias, a verbose string representation is created + // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` + // to ensure the output column name matches the user's query. + let arg_names = inner + .args + .iter() + .map(|arg| arg.to_string()) + .collect::>() + .join(","); + let verbose_alias = format!("{name}({arg_names})"); + + return Ok(Expr::HigherOrderFunction(inner).alias(verbose_alias)); } // Build Unnest expression. @@ -620,7 +618,7 @@ impl SqlToRel<'_, S> { let window_frame: WindowFrame = window_frame.clone().try_into()?; window_frame .regularize_order_bys(&mut order_by) - .map(|_| window_frame) + .map(|()| window_frame) }) .transpose()?; @@ -708,21 +706,20 @@ impl SqlToRel<'_, S> { if name.eq_ignore_ascii_case(inner.fun.name()) { return Ok(Expr::WindowFunction(Box::new(inner))); - } else { - // If the function is called by an alias, a verbose string representation is created - // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` - // to ensure the output column name matches the user's query. - let arg_names = inner - .params - .args - .iter() - .map(|arg| arg.to_string()) - .collect::>() - .join(","); - let verbose_alias = format!("{name}({arg_names})"); - - return Ok(Expr::WindowFunction(Box::new(inner)).alias(verbose_alias)); } + // If the function is called by an alias, a verbose string representation is created + // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` + // to ensure the output column name matches the user's query. + let arg_names = inner + .params + .args + .iter() + .map(|arg| arg.to_string()) + .collect::>() + .join(","); + let verbose_alias = format!("{name}({arg_names})"); + + return Ok(Expr::WindowFunction(Box::new(inner)).alias(verbose_alias)); } } else { // User defined aggregate functions (UDAF) have precedence in case it has the same name as a scalar built-in function @@ -864,21 +861,20 @@ impl SqlToRel<'_, S> { if name.eq_ignore_ascii_case(inner.func.name()) { return Ok(Expr::AggregateFunction(inner)); - } else { - // If the function is called by an alias, a verbose string representation is created - // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` - // to ensure the output column name matches the user's query. - let arg_names = inner - .params - .args - .iter() - .map(|arg| arg.to_string()) - .collect::>() - .join(","); - let verbose_alias = format!("{name}({arg_names})"); - - return Ok(Expr::AggregateFunction(inner).alias(verbose_alias)); } + // If the function is called by an alias, a verbose string representation is created + // (e.g., "my_alias(arg1, arg2)") and the expression is wrapped in an `Alias` + // to ensure the output column name matches the user's query. + let arg_names = inner + .params + .args + .iter() + .map(|arg| arg.to_string()) + .collect::>() + .join(","); + let verbose_alias = format!("{name}({arg_names})"); + + return Ok(Expr::AggregateFunction(inner).alias(verbose_alias)); } } @@ -890,19 +886,15 @@ impl SqlToRel<'_, S> { .map(|part| part.as_ident().cloned().ok_or(())) .collect::, ()>>(); if let Ok(ids) = maybe_ids { - if ids.len() == 1 { - return self.sql_identifier_to_expr( + return if ids.len() == 1 { + self.sql_identifier_to_expr( ids.into_iter().next().unwrap(), schema, planner_context, - ); + ) } else { - return self.sql_compound_identifier_to_expr( - ids, - schema, - planner_context, - ); - } + self.sql_compound_identifier_to_expr(ids, schema, planner_context) + }; } } diff --git a/datafusion/sql/src/expr/value.rs b/datafusion/sql/src/expr/value.rs index 1307e917e4251..d0354b319f089 100644 --- a/datafusion/sql/src/expr/value.rs +++ b/datafusion/sql/src/expr/value.rs @@ -296,9 +296,8 @@ fn interval_literal(interval_value: SQLExpr, negative: bool) -> Result { return not_impl_err!( "Unsupported interval argument. Long number not supported: {interval_value:?}" ); - } else { - v.to_string() } + v.to_string() } SQLExpr::UnaryOp { op, expr } => { let negative = match op { diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs index fcf4708f1bf94..692d562a6088d 100644 --- a/datafusion/sql/src/parser.rs +++ b/datafusion/sql/src/parser.rs @@ -756,9 +756,8 @@ impl<'a> DFParser<'a> { let token = self.parser.peek_token(); if token == Token::EOF || token == Token::SemiColon { break; - } else { - return self.expected("end of statement or ;", &token)?; } + return self.expected("end of statement or ;", &token)?; } } @@ -1208,9 +1207,8 @@ impl<'a> DFParser<'a> { let token = self.parser.peek_token(); if token == Token::EOF || token == Token::SemiColon { break; - } else { - return self.expected("end of statement or ;", &token)?; } + return self.expected("end of statement or ;", &token)?; } } diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs index bbd9d203eb124..85d6a254cce0f 100644 --- a/datafusion/sql/src/select.rs +++ b/datafusion/sql/src/select.rs @@ -818,57 +818,56 @@ impl SqlToRel<'_, S> { if unnest_columns.is_empty() { break; - } else { - let mut unnest_options = UnnestOptions::new().with_preserve_nulls(false); - - #[allow(clippy::allow_attributes, clippy::mutable_key_type)] - // Expr contains Arc with interior mutability but is intentionally used as hash key - let mut projection_exprs = match &aggr_expr_using_columns { - Some(exprs) => (*exprs).clone(), - None => { - #[allow(clippy::allow_attributes, clippy::mutable_key_type)] - let mut columns = HashSet::new(); - for expr in &aggr_expr { - expr.apply(|expr| { - if let Expr::Column(c) = expr { - columns.insert(Expr::Column(c.clone())); - } - Ok(TreeNodeRecursion::Continue) - }) - // As the closure always returns Ok, this "can't" error - .expect("Unexpected error"); - } - aggr_expr_using_columns = Some(columns.clone()); - columns - } - }; - projection_exprs.extend(inner_projection_exprs); - - let mut unnest_col_vec = vec![]; - - for (col, maybe_list_unnest) in unnest_columns.into_iter() { - if let Some(list_unnest) = maybe_list_unnest { - unnest_options = list_unnest.into_iter().fold( - unnest_options, - |options, unnest_list| { - options.with_recursions(RecursionUnnestOption { - input_column: col.clone(), - output_column: unnest_list.output_column, - depth: unnest_list.depth, - }) - }, - ); + } + let mut unnest_options = UnnestOptions::new().with_preserve_nulls(false); + + #[allow(clippy::allow_attributes, clippy::mutable_key_type)] + // Expr contains Arc with interior mutability but is intentionally used as hash key + let mut projection_exprs = match &aggr_expr_using_columns { + Some(exprs) => (*exprs).clone(), + None => { + #[allow(clippy::allow_attributes, clippy::mutable_key_type)] + let mut columns = HashSet::new(); + for expr in &aggr_expr { + expr.apply(|expr| { + if let Expr::Column(c) = expr { + columns.insert(Expr::Column(c.clone())); + } + Ok(TreeNodeRecursion::Continue) + }) + // As the closure always returns Ok, this "can't" error + .expect("Unexpected error"); } - unnest_col_vec.push(col); + aggr_expr_using_columns = Some(columns.clone()); + columns } + }; + projection_exprs.extend(inner_projection_exprs); - intermediate_plan = LogicalPlanBuilder::from(intermediate_plan) - .project(projection_exprs)? - .unnest_columns_with_options(unnest_col_vec, unnest_options)? - .build()?; + let mut unnest_col_vec = vec![]; - intermediate_select_exprs = outer_projection_exprs; + for (col, maybe_list_unnest) in unnest_columns.into_iter() { + if let Some(list_unnest) = maybe_list_unnest { + unnest_options = list_unnest.into_iter().fold( + unnest_options, + |options, unnest_list| { + options.with_recursions(RecursionUnnestOption { + input_column: col.clone(), + output_column: unnest_list.output_column, + depth: unnest_list.depth, + }) + }, + ); + } + unnest_col_vec.push(col); } + + intermediate_plan = LogicalPlanBuilder::from(intermediate_plan) + .project(projection_exprs)? + .unnest_columns_with_options(unnest_col_vec, unnest_options)? + .build()?; + + intermediate_select_exprs = outer_projection_exprs; } Ok((intermediate_plan, intermediate_select_exprs)) diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs index 1a9072212f2f3..93d896201af47 100644 --- a/datafusion/sql/src/statement.rs +++ b/datafusion/sql/src/statement.rs @@ -1412,7 +1412,7 @@ impl SqlToRel<'_, S> { .map(|t| { let name = match t.name.clone() { Some(name) => name.value, - None => "".to_string(), + None => String::new(), }; Arc::new(Field::new(name, t.data_type.clone(), true)) }) @@ -2875,9 +2875,8 @@ impl SqlToRel<'_, S> { return schema_err!(SchemaError::DuplicateUnqualifiedField { name: c, }); - } else { - value_indices[column_index] = Some(i); } + value_indices[column_index] = Some(i); Ok(Arc::clone(table_schema.field(column_index))) }) .collect::>>()?; @@ -3036,7 +3035,7 @@ impl SqlToRel<'_, S> { _ => return plan_err!("Unsupported SHOW FUNCTIONS filter"), } } else { - "".to_string() + String::new() }; // Scalar / aggregate / window functions are resolved by joining diff --git a/datafusion/substrait/src/logical_plan/consumer/expr/literal.rs b/datafusion/substrait/src/logical_plan/consumer/expr/literal.rs index b0756ef060ecf..7d8b8eb0c7130 100644 --- a/datafusion/substrait/src/logical_plan/consumer/expr/literal.rs +++ b/datafusion/substrait/src/logical_plan/consumer/expr/literal.rs @@ -393,9 +393,8 @@ pub(crate) fn from_substrait_literal( return substrait_err!( "Cannot set subseconds field of IntervalDayToSecond without setting precision" ); - } else { - 0_i32 } + 0_i32 } Some(PrecisionMode::Precision(0)) => *subseconds as i32 * 1000, Some(PrecisionMode::Precision(3)) => *subseconds as i32, diff --git a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs index 3716b0feba3cc..6b58c4a53af17 100644 --- a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs @@ -2466,7 +2466,7 @@ fn check_post_join_filters(rel: &Rel) -> Result<()> { // recursively check JoinRels match check_post_join_filters(join.left.as_ref().unwrap().as_ref()) { Err(e) => Err(e), - Ok(_) => { + Ok(()) => { check_post_join_filters(join.right.as_ref().unwrap().as_ref()) } } diff --git a/test-utils/src/array_gen/string.rs b/test-utils/src/array_gen/string.rs index 896182290ccca..cfc99e2ee7a64 100644 --- a/test-utils/src/array_gen/string.rs +++ b/test-utils/src/array_gen/string.rs @@ -92,7 +92,7 @@ impl StringArrayGenerator { fn random_string(rng: &mut StdRng, max_len: usize) -> String { // pick characters at random (not just ascii) match max_len { - 0 => "".to_string(), + 0 => String::new(), 1 => String::from(rng.random::()), _ => { let len = rng.random_range(1..=max_len);