Apache DataFusion SQL Query Engine
Enable `inefficient_to_string` Clippy lint (#17583)
Piotr Findeisen986cfcde0ee2
diff --git a/Cargo.toml b/Cargo.tomlindex 683325e472..92392a1991 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -223,6 +223,7 @@ used_underscore_binding = "warn"or_fun_call = "warn"unnecessary_lazy_evaluations = "warn"uninlined_format_args = "warn"+inefficient_to_string = "warn"[workspace.lints.rust]unexpected_cfgs = { level = "warn", check-cfg = [diff --git a/datafusion-examples/examples/parquet_embedded_index.rs b/datafusion-examples/examples/parquet_embedded_index.rsindex 5191ae48b3..3cbe189147 100644--- a/datafusion-examples/examples/parquet_embedded_index.rs+++ b/datafusion-examples/examples/parquet_embedded_index.rs@@ -321,7 +321,7 @@ fn write_file_with_index(path: &Path, values: &[&str]) -> Result<()> {// compute the distinct indexlet distinct_index: DistinctIndex =- DistinctIndex::new(values.iter().map(|s| s.to_string()));+ DistinctIndex::new(values.iter().map(|s| (*s).to_string()));let file = File::create(path)?;diff --git a/datafusion/catalog/src/information_schema.rs b/datafusion/catalog/src/information_schema.rsindex fce3b8b207..17dbc31d95 100644--- a/datafusion/catalog/src/information_schema.rs+++ b/datafusion/catalog/src/information_schema.rs@@ -492,7 +492,7 @@ impl SchemaProvider for InformationSchemaProvider {fn table_names(&self) -> Vec<String> {INFORMATION_SCHEMA_TABLES.iter()- .map(|t| t.to_string())+ .map(|t| (*t).to_string()).collect()}diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rsindex 8d0f89b7bd..210f044297 100644--- a/datafusion/common/src/error.rs+++ b/datafusion/common/src/error.rs@@ -455,12 +455,13 @@ impl DataFusionError {/// If backtrace enabled then error has a format "message" [`Self::BACK_TRACE_SEP`] "backtrace"/// The method strips the backtrace and outputs "message"pub fn strip_backtrace(&self) -> String {- self.to_string()+ (*self+ .to_string().split(Self::BACK_TRACE_SEP).collect::<Vec<&str>>().first()- .unwrap_or(&"")- .to_string()+ .unwrap_or(&""))+ .to_string()}/// To enable optional rust backtrace in DataFusion:diff --git a/datafusion/core/src/dataframe/parquet.rs b/datafusion/core/src/dataframe/parquet.rsindex 83bb60184f..735c69af77 100644--- a/datafusion/core/src/dataframe/parquet.rs+++ b/datafusion/core/src/dataframe/parquet.rs@@ -205,7 +205,7 @@ mod tests {&HashMap::from_iter([("datafusion.execution.batch_size", "10")].iter()- .map(|(s1, s2)| (s1.to_string(), s2.to_string())),+ .map(|(s1, s2)| ((*s1).to_string(), (*s2).to_string())),),)?);register_aggregate_csv(&ctx, "aggregate_test_100").await?;diff --git a/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs b/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rsindex 01554c1af7..4e04da26f7 100644--- a/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs+++ b/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs@@ -337,7 +337,7 @@ async fn run_aggregate_test(input1: Vec<RecordBatch>, group_by_columns: Vec<&str];let expr = group_by_columns.iter()- .map(|elem| (col(elem, &schema).unwrap(), elem.to_string()))+ .map(|elem| (col(elem, &schema).unwrap(), (*elem).to_string())).collect::<Vec<_>>();let group_by = PhysicalGroupBy::new_single(expr);diff --git a/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/mod.rs b/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/mod.rsindex 04b764e46a..e7ce557d22 100644--- a/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/mod.rs+++ b/datafusion/core/tests/fuzz_cases/aggregation_fuzzer/mod.rs@@ -77,8 +77,8 @@ pub(crate) fn check_equality_of_batches(if lhs_row != rhs_row {return Err(InconsistentResult {row_idx,- lhs_row: lhs_row.to_string(),- rhs_row: rhs_row.to_string(),+ lhs_row: (*lhs_row).to_string(),+ rhs_row: (*rhs_row).to_string(),});}}diff --git a/datafusion/core/tests/fuzz_cases/equivalence/projection.rs b/datafusion/core/tests/fuzz_cases/equivalence/projection.rsindex f783ab1cc1..69639b3e09 100644--- a/datafusion/core/tests/fuzz_cases/equivalence/projection.rs+++ b/datafusion/core/tests/fuzz_cases/equivalence/projection.rs@@ -73,7 +73,7 @@ fn project_orderings_random() -> Result<()> {for proj_exprs in proj_exprs.iter().combinations(n_req) {let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (Arc::clone(expr), name.to_string()))+ .map(|(expr, name)| (Arc::clone(expr), (*name).to_string())).collect::<Vec<_>>();let (projected_batch, projected_eq) = apply_projection(proj_exprs.clone(),@@ -147,7 +147,7 @@ fn ordering_satisfy_after_projection_random() -> Result<()> {for proj_exprs in proj_exprs.iter().combinations(n_req) {let proj_exprs = proj_exprs.into_iter()- .map(|(expr, name)| (Arc::clone(expr), name.to_string()));+ .map(|(expr, name)| (Arc::clone(expr), (*name).to_string()));let (projected_batch, projected_eq) = apply_projection(proj_exprs.clone(),&table_data_with_properties,diff --git a/datafusion/core/tests/fuzz_cases/sort_fuzz.rs b/datafusion/core/tests/fuzz_cases/sort_fuzz.rsindex 27becaa96f..28d28a6622 100644--- a/datafusion/core/tests/fuzz_cases/sort_fuzz.rs+++ b/datafusion/core/tests/fuzz_cases/sort_fuzz.rs@@ -188,7 +188,7 @@ impl SortTest {}fn with_sort_columns(mut self, sort_columns: Vec<&str>) -> Self {- self.sort_columns = sort_columns.iter().map(|s| s.to_string()).collect();+ self.sort_columns = sort_columns.iter().map(|s| (*s).to_string()).collect();self}diff --git a/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs b/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rsindex 3caab8d4b5..b659d868ce 100644--- a/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs+++ b/datafusion/core/tests/fuzz_cases/topk_filter_pushdown.rs@@ -297,7 +297,7 @@ async fn test_fuzz_topk_filter_pushdown() {order_vec.push(ordering);}None => {- orders.insert(order_column.to_string(), vec![ordering]);+ orders.insert((*order_column).to_string(), vec![ordering]);}}}diff --git a/datafusion/core/tests/fuzz_cases/window_fuzz.rs b/datafusion/core/tests/fuzz_cases/window_fuzz.rsindex a816afe3c3..9da92f7cd4 100644--- a/datafusion/core/tests/fuzz_cases/window_fuzz.rs+++ b/datafusion/core/tests/fuzz_cases/window_fuzz.rs@@ -455,7 +455,7 @@ fn get_random_function(}}- (window_fn.clone(), args, fn_name.to_string())+ (window_fn.clone(), args, (*fn_name).to_string())}fn get_random_window_frame(rng: &mut StdRng, is_linear: bool) -> WindowFrame {diff --git a/datafusion/core/tests/memory_limit/mod.rs b/datafusion/core/tests/memory_limit/mod.rsindex 554c30eb87..7ee85ea1be 100644--- a/datafusion/core/tests/memory_limit/mod.rs+++ b/datafusion/core/tests/memory_limit/mod.rs@@ -806,7 +806,7 @@ impl TestCase {/// Specify an expected plan to reviewpub fn with_expected_plan(mut self, expected_plan: &[&str]) -> Self {- self.expected_plan = expected_plan.iter().map(|s| s.to_string()).collect();+ self.expected_plan = expected_plan.iter().map(|s| (*s).to_string()).collect();self}diff --git a/datafusion/expr/src/expr_rewriter/mod.rs b/datafusion/expr/src/expr_rewriter/mod.rsindex 05a9425452..d9fb9f7219 100644--- a/datafusion/expr/src/expr_rewriter/mod.rs+++ b/datafusion/expr/src/expr_rewriter/mod.rs@@ -477,7 +477,7 @@ mod test {) -> DFSchema {let fields = fields.iter()- .map(|f| Arc::new(Field::new(f.to_string(), DataType::Int8, false)))+ .map(|f| Arc::new(Field::new((*f).to_string(), DataType::Int8, false))).collect::<Vec<_>>();let schema = Arc::new(Schema::new(fields));DFSchema::from_field_specific_qualified_schema(qualifiers, &schema).unwrap()diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rsindex 88d49722a5..511d8c27a5 100644--- a/datafusion/expr/src/logical_plan/builder.rs+++ b/datafusion/expr/src/logical_plan/builder.rs@@ -2482,12 +2482,12 @@ mod tests {return plan_err!("Plan should have returned an DataFusionError::Internal");};- let desc = desc+ let desc = (*desc.split(DataFusionError::BACK_TRACE_SEP).collect::<Vec<&str>>().first()- .unwrap_or(&"")- .to_string();+ .unwrap_or(&""))+ .to_string();assert_snapshot!(desc, @"trying to unnest on invalid data type UInt32");diff --git a/datafusion/functions/benches/to_char.rs b/datafusion/functions/benches/to_char.rsindex f1151b6db2..9599b86772 100644--- a/datafusion/functions/benches/to_char.rs+++ b/datafusion/functions/benches/to_char.rs@@ -79,17 +79,17 @@ const DATETIME_PATTERNS: [&str; 8] = [];fn pick_date_pattern(rng: &mut ThreadRng) -> String {- DATE_PATTERNS+ (*DATE_PATTERNS.choose(rng)- .expect("Empty list of date patterns")- .to_string()+ .expect("Empty list of date patterns"))+ .to_string()}fn pick_date_time_pattern(rng: &mut ThreadRng) -> String {- DATETIME_PATTERNS+ (*DATETIME_PATTERNS.choose(rng)- .expect("Empty list of date time patterns")- .to_string()+ .expect("Empty list of date time patterns"))+ .to_string()}fn pick_date_and_date_time_mixed_pattern(rng: &mut ThreadRng) -> String {diff --git a/datafusion/functions/src/regex/regexpcount.rs b/datafusion/functions/src/regex/regexpcount.rsindex ea16dbad3a..8bad506217 100644--- a/datafusion/functions/src/regex/regexpcount.rs+++ b/datafusion/functions/src/regex/regexpcount.rs@@ -842,9 +842,9 @@ mod tests {values.iter().enumerate().for_each(|(pos, &v)| {// utf8let v_sv = ScalarValue::Utf8(Some(v.to_string()));- let regex_sv = ScalarValue::Utf8(regex.get(pos).map(|s| s.to_string()));+ let regex_sv = ScalarValue::Utf8(regex.get(pos).map(|s| (*s).to_string()));let start_sv = ScalarValue::Int64(Some(start));- let flags_sv = ScalarValue::Utf8(flags.get(pos).map(|f| f.to_string()));+ let flags_sv = ScalarValue::Utf8(flags.get(pos).map(|f| (*f).to_string()));let expected = expected.get(pos).cloned();let re = regexp_count_with_scalar_values(&[v_sv,@@ -861,8 +861,10 @@ mod tests {// largeutf8let v_sv = ScalarValue::LargeUtf8(Some(v.to_string()));- let regex_sv = ScalarValue::LargeUtf8(regex.get(pos).map(|s| s.to_string()));- let flags_sv = ScalarValue::LargeUtf8(flags.get(pos).map(|f| f.to_string()));+ let regex_sv =+ ScalarValue::LargeUtf8(regex.get(pos).map(|s| (*s).to_string()));+ let flags_sv =+ ScalarValue::LargeUtf8(flags.get(pos).map(|f| (*f).to_string()));let re = regexp_count_with_scalar_values(&[v_sv,regex_sv,@@ -878,8 +880,10 @@ mod tests {// utf8viewlet v_sv = ScalarValue::Utf8View(Some(v.to_string()));- let regex_sv = ScalarValue::Utf8View(regex.get(pos).map(|s| s.to_string()));- let flags_sv = ScalarValue::Utf8View(flags.get(pos).map(|f| f.to_string()));+ let regex_sv =+ ScalarValue::Utf8View(regex.get(pos).map(|s| (*s).to_string()));+ let flags_sv =+ ScalarValue::Utf8View(flags.get(pos).map(|f| (*f).to_string()));let re = regexp_count_with_scalar_values(&[v_sv,regex_sv,diff --git a/datafusion/physical-plan/src/execution_plan.rs b/datafusion/physical-plan/src/execution_plan.rsindex e708bbd3ec..a70cd9cb0d 100644--- a/datafusion/physical-plan/src/execution_plan.rs+++ b/datafusion/physical-plan/src/execution_plan.rs@@ -1335,7 +1335,7 @@ pub fn check_not_null_constraints(pub fn get_plan_string(plan: &Arc<dyn ExecutionPlan>) -> Vec<String> {let formatted = displayable(plan.as_ref()).indent(true).to_string();let actual: Vec<&str> = formatted.trim().lines().collect();- actual.iter().map(|elem| elem.to_string()).collect()+ actual.iter().map(|elem| (*elem).to_string()).collect()}/// Indicates the effect an execution plan operator will have on the cardinalitydiff --git a/datafusion/sql/src/utils.rs b/datafusion/sql/src/utils.rsindex c18c70d16e..daee722526 100644--- a/datafusion/sql/src/utils.rs+++ b/datafusion/sql/src/utils.rs@@ -701,7 +701,7 @@ mod tests {),}).collect();- let l_formatted: Vec<String> = l.iter().map(|i| i.to_string()).collect();+ let l_formatted: Vec<String> = l.iter().map(|i| (*i).to_string()).collect();assert_eq!(l_formatted, r_formatted);}diff --git a/datafusion/sql/tests/cases/params.rs b/datafusion/sql/tests/cases/params.rsindex 048c15f93d..b429853fe9 100644--- a/datafusion/sql/tests/cases/params.rs+++ b/datafusion/sql/tests/cases/params.rs@@ -36,7 +36,7 @@ impl ParameterTest<'_> {let expected_types: HashMap<String, Option<DataType>> = self.expected_types.iter()- .map(|(k, v)| (k.to_string(), v.clone()))+ .map(|(k, v)| ((*k).to_string(), v.clone())).collect();assert_eq!(actual_types, expected_types);diff --git a/datafusion/sql/tests/cases/plan_to_sql.rs b/datafusion/sql/tests/cases/plan_to_sql.rsindex 02a4da4267..7aa982dcf3 100644--- a/datafusion/sql/tests/cases/plan_to_sql.rs+++ b/datafusion/sql/tests/cases/plan_to_sql.rs@@ -1304,7 +1304,7 @@ fn test_pretty_roundtrip() -> Result<()> {let expr =sql_to_rel.sql_to_expr(sql_expr, &df_schema, &mut PlannerContext::new())?;let round_trip_sql = unparser.expr_to_sql(&expr)?.to_string();- assert_eq!(pretty.to_string(), round_trip_sql);+ assert_eq!((*pretty).to_string(), round_trip_sql);// verify that the pretty string parses to the same underlying Exprlet pretty_sql_expr = Parser::new(&GenericDialect {})