diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rs index 3e16b045f465a..5fad7433a57fe 100644 --- a/datafusion/common/src/error.rs +++ b/datafusion/common/src/error.rs @@ -541,6 +541,7 @@ mod test { } #[test] + #[allow(clippy::unnecessary_literal_unwrap)] fn test_make_error_parse_input() { let res: Result<(), DataFusionError> = plan_err!("Err"); let res = res.unwrap_err(); diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs index dc76fdbf8b2b4..b30af1fd1f92e 100644 --- a/datafusion/common/src/scalar.rs +++ b/datafusion/common/src/scalar.rs @@ -3405,7 +3405,7 @@ mod tests { ScalarValue::Decimal128(Some(3), 10, 2), ]; // convert the vec to decimal array and check the result - let array = ScalarValue::iter_to_array(decimal_vec.into_iter()).unwrap(); + let array = ScalarValue::iter_to_array(decimal_vec).unwrap(); assert_eq!(3, array.len()); assert_eq!(DataType::Decimal128(10, 2), array.data_type().clone()); @@ -3415,7 +3415,7 @@ mod tests { ScalarValue::Decimal128(Some(3), 10, 2), ScalarValue::Decimal128(None, 10, 2), ]; - let array = ScalarValue::iter_to_array(decimal_vec.into_iter()).unwrap(); + let array = ScalarValue::iter_to_array(decimal_vec).unwrap(); assert_eq!(4, array.len()); assert_eq!(DataType::Decimal128(10, 2), array.data_type().clone()); @@ -3578,6 +3578,8 @@ mod tests { } #[test] + // despite clippy claiming they are useless, the code doesn't compile otherwise. + #[allow(clippy::useless_vec)] fn scalar_iter_to_array_boolean() { check_scalar_iter!(Boolean, BooleanArray, vec![Some(true), None, Some(false)]); check_scalar_iter!(Float32, Float32Array, vec![Some(1.9), None, Some(-2.1)]); @@ -3640,7 +3642,7 @@ mod tests { fn scalar_iter_to_array_empty() { let scalars = vec![] as Vec; - let result = ScalarValue::iter_to_array(scalars.into_iter()).unwrap_err(); + let result = ScalarValue::iter_to_array(scalars).unwrap_err(); assert!( result .to_string() @@ -3658,13 +3660,13 @@ mod tests { ScalarValue::Dictionary(Box::new(key_type), Box::new(value)) } - let scalars = vec![ + let scalars = [ make_val(Some("Foo".into())), make_val(None), make_val(Some("Bar".into())), ]; - let array = ScalarValue::iter_to_array(scalars.into_iter()).unwrap(); + let array = ScalarValue::iter_to_array(scalars).unwrap(); let array = as_dictionary_array::(&array).unwrap(); let values_array = as_string_array(array.values()).unwrap(); @@ -3686,9 +3688,9 @@ mod tests { fn scalar_iter_to_array_mismatched_types() { use ScalarValue::*; // If the scalar values are not all the correct type, error here - let scalars: Vec = vec![Boolean(Some(true)), Int32(Some(5))]; + let scalars = [Boolean(Some(true)), Int32(Some(5))]; - let result = ScalarValue::iter_to_array(scalars.into_iter()).unwrap_err(); + let result = ScalarValue::iter_to_array(scalars).unwrap_err(); assert!(result.to_string().contains("Inconsistent types in ScalarValue::iter_to_array. Expected Boolean, got Int32(5)"), "{}", result); } @@ -3776,21 +3778,21 @@ mod tests { }}; } - let bool_vals = vec![Some(true), None, Some(false)]; - let f32_vals = vec![Some(-1.0), None, Some(1.0)]; + let bool_vals = [Some(true), None, Some(false)]; + let f32_vals = [Some(-1.0), None, Some(1.0)]; let f64_vals = make_typed_vec!(f32_vals, f64); - let i8_vals = vec![Some(-1), None, Some(1)]; + let i8_vals = [Some(-1), None, Some(1)]; let i16_vals = make_typed_vec!(i8_vals, i16); let i32_vals = make_typed_vec!(i8_vals, i32); let i64_vals = make_typed_vec!(i8_vals, i64); - let u8_vals = vec![Some(0), None, Some(1)]; + let u8_vals = [Some(0), None, Some(1)]; let u16_vals = make_typed_vec!(u8_vals, u16); let u32_vals = make_typed_vec!(u8_vals, u32); let u64_vals = make_typed_vec!(u8_vals, u64); - let str_vals = vec![Some("foo"), None, Some("bar")]; + let str_vals = [Some("foo"), None, Some("bar")]; /// Test each value in `scalar` with the corresponding element /// at `array`. Assumes each element is unique (aka not equal diff --git a/datafusion/core/benches/data_utils/mod.rs b/datafusion/core/benches/data_utils/mod.rs index 9169c3dda48ed..64c0e4b100a14 100644 --- a/datafusion/core/benches/data_utils/mod.rs +++ b/datafusion/core/benches/data_utils/mod.rs @@ -107,7 +107,7 @@ fn create_record_batch( ) -> RecordBatch { // the 4 here is the number of different keys. // a higher number increase sparseness - let vs = vec![0, 1, 2, 3]; + let vs = [0, 1, 2, 3]; let keys: Vec = (0..batch_size) .map( // use random numbers to avoid spurious compiler optimizations wrt to branching diff --git a/datafusion/core/benches/sort.rs b/datafusion/core/benches/sort.rs index 4045702d6308e..fbb94d66db581 100644 --- a/datafusion/core/benches/sort.rs +++ b/datafusion/core/benches/sort.rs @@ -329,8 +329,8 @@ fn utf8_tuple_streams(sorted: bool) -> PartitionedBatches { let mut tuples: Vec<_> = gen .utf8_low_cardinality_values() .into_iter() - .zip(gen.utf8_low_cardinality_values().into_iter()) - .zip(gen.utf8_high_cardinality_values().into_iter()) + .zip(gen.utf8_low_cardinality_values()) + .zip(gen.utf8_high_cardinality_values()) .collect(); if sorted { @@ -362,9 +362,9 @@ fn mixed_tuple_streams(sorted: bool) -> PartitionedBatches { let mut tuples: Vec<_> = gen .i64_values() .into_iter() - .zip(gen.utf8_low_cardinality_values().into_iter()) - .zip(gen.utf8_low_cardinality_values().into_iter()) - .zip(gen.i64_values().into_iter()) + .zip(gen.utf8_low_cardinality_values()) + .zip(gen.utf8_low_cardinality_values()) + .zip(gen.i64_values()) .collect(); if sorted { diff --git a/datafusion/core/src/catalog/schema.rs b/datafusion/core/src/catalog/schema.rs index cd6e29b5f38b2..1bb2df914ab25 100644 --- a/datafusion/core/src/catalog/schema.rs +++ b/datafusion/core/src/catalog/schema.rs @@ -194,7 +194,7 @@ mod tests { let actual = df.collect().await.unwrap(); - let expected = vec![ + let expected = [ "+----+----------+", "| id | bool_col |", "+----+----------+", diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs index 29b3caff89b66..92a061ce596ab 100644 --- a/datafusion/core/src/dataframe.rs +++ b/datafusion/core/src/dataframe.rs @@ -1330,7 +1330,7 @@ mod tests { let df_results = df.collect().await?; assert_batches_sorted_eq!( - vec!["+------+", "| f.c1 |", "+------+", "| 1 |", "| 10 |", "+------+",], + ["+------+", "| f.c1 |", "+------+", "| 1 |", "| 10 |", "+------+"], &df_results ); @@ -1354,8 +1354,7 @@ mod tests { let df: Vec = df.aggregate(group_expr, aggr_expr)?.collect().await?; assert_batches_sorted_eq!( - vec![ - "+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+", + ["+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+", "| c1 | MIN(aggregate_test_100.c12) | MAX(aggregate_test_100.c12) | AVG(aggregate_test_100.c12) | SUM(aggregate_test_100.c12) | COUNT(aggregate_test_100.c12) | COUNT(DISTINCT aggregate_test_100.c12) |", "+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+", "| a | 0.02182578039211991 | 0.9800193410444061 | 0.48754517466109415 | 10.238448667882977 | 21 | 21 |", @@ -1363,8 +1362,7 @@ mod tests { "| c | 0.0494924465469434 | 0.991517828651004 | 0.6600456536439784 | 13.860958726523545 | 21 | 21 |", "| d | 0.061029375346466685 | 0.9748360509016578 | 0.48855379387549824 | 8.793968289758968 | 18 | 18 |", "| e | 0.01479305307777301 | 0.9965400387585364 | 0.48600669271341534 | 10.206140546981722 | 21 | 21 |", - "+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+", - ], + "+----+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-------------------------------+----------------------------------------+"], &df ); @@ -1403,8 +1401,7 @@ mod tests { #[rustfmt::skip] assert_batches_sorted_eq!( - vec![ - "+----+", + ["+----+", "| c1 |", "+----+", "| a |", @@ -1412,8 +1409,7 @@ mod tests { "| c |", "| d |", "| e |", - "+----+", - ], + "+----+"], &df_results ); @@ -1636,7 +1632,7 @@ mod tests { let table_results = &table.aggregate(group_expr, aggr_expr)?.collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+----+-----------------------------+", "| c1 | SUM(aggregate_test_100.c12) |", "+----+-----------------------------+", @@ -1645,14 +1641,14 @@ mod tests { "| c | 13.860958726523545 |", "| d | 8.793968289758968 |", "| e | 10.206140546981722 |", - "+----+-----------------------------+", + "+----+-----------------------------+" ], &df_results ); // the results are the same as the results from the view, modulo the leaf table name assert_batches_sorted_eq!( - vec![ + [ "+----+---------------------+", "| c1 | SUM(test_table.c12) |", "+----+---------------------+", @@ -1661,7 +1657,7 @@ mod tests { "| c | 13.860958726523545 |", "| d | 8.793968289758968 |", "| e | 10.206140546981722 |", - "+----+---------------------+", + "+----+---------------------+" ], table_results ); @@ -1719,7 +1715,7 @@ mod tests { let df_results = df.clone().collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+----+----+-----+-----+", "| c1 | c2 | c3 | sum |", "+----+----+-----+-----+", @@ -1729,7 +1725,7 @@ mod tests { "| a | 3 | 13 | 16 |", "| a | 3 | 14 | 17 |", "| a | 3 | 17 | 20 |", - "+----+----+-----+-----+", + "+----+----+-----+-----+" ], &df_results ); @@ -1742,7 +1738,7 @@ mod tests { .await?; assert_batches_sorted_eq!( - vec![ + [ "+-----+----+-----+-----+", "| c1 | c2 | c3 | sum |", "+-----+----+-----+-----+", @@ -1752,7 +1748,7 @@ mod tests { "| 16 | 3 | 13 | 16 |", "| 17 | 3 | 14 | 17 |", "| 20 | 3 | 17 | 20 |", - "+-----+----+-----+-----+", + "+-----+----+-----+-----+" ], &df_results_overwrite ); @@ -1765,7 +1761,7 @@ mod tests { .await?; assert_batches_sorted_eq!( - vec![ + [ "+----+----+-----+-----+", "| c1 | c2 | c3 | sum |", "+----+----+-----+-----+", @@ -1775,7 +1771,7 @@ mod tests { "| a | 4 | 13 | 16 |", "| a | 4 | 14 | 17 |", "| a | 4 | 17 | 20 |", - "+----+----+-----+-----+", + "+----+----+-----+-----+" ], &df_results_overwrite_self ); @@ -1810,12 +1806,12 @@ mod tests { .await?; assert_batches_sorted_eq!( - vec![ + [ "+-----+-----+----+-------+", "| one | two | c3 | total |", "+-----+-----+----+-------+", "| a | 3 | 13 | 16 |", - "+-----+-----+----+-------+", + "+-----+-----+----+-------+" ], &df_sum_renamed ); @@ -1882,12 +1878,12 @@ mod tests { let df_results = df.clone().collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+----+----+-----+----+----+-----+", "| c1 | c2 | c3 | c1 | c2 | c3 |", "+----+----+-----+----+----+-----+", "| a | 1 | -85 | a | 1 | -85 |", - "+----+----+-----+----+----+-----+", + "+----+----+-----+----+----+-----+" ], &df_results ); @@ -1919,12 +1915,12 @@ mod tests { let df_results = df_renamed.collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+-----+----+-----+----+----+-----+", "| AAA | c2 | c3 | c1 | c2 | c3 |", "+-----+----+-----+----+----+-----+", "| a | 1 | -85 | a | 1 | -85 |", - "+-----+----+-----+----+----+-----+", + "+-----+----+-----+----+----+-----+" ], &df_results ); @@ -1961,12 +1957,12 @@ mod tests { let res = &df_renamed.clone().collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+---------+", "| CoLuMn1 |", "+---------+", "| a |", - "+---------+", + "+---------+" ], res ); @@ -1977,7 +1973,7 @@ mod tests { .await?; assert_batches_sorted_eq!( - vec!["+----+", "| c1 |", "+----+", "| a |", "+----+",], + ["+----+", "| c1 |", "+----+", "| a |", "+----+"], &df_renamed ); @@ -2022,12 +2018,12 @@ mod tests { let df_results = df.clone().collect().await?; df.clone().show().await?; assert_batches_sorted_eq!( - vec![ + [ "+----+----+-----+", "| c2 | c3 | sum |", "+----+----+-----+", "| 2 | 1 | 3 |", - "+----+----+-----+", + "+----+----+-----+" ], &df_results ); @@ -2088,13 +2084,13 @@ mod tests { let df_results = df.collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+------+-------+", "| f.c1 | f.c2 |", "+------+-------+", "| 1 | hello |", "| 10 | hello |", - "+------+-------+", + "+------+-------+" ], &df_results ); @@ -2120,12 +2116,12 @@ mod tests { let df_results = df.collect().await?; let cached_df_results = cached_df.collect().await?; assert_batches_sorted_eq!( - vec![ + [ "+----+----+-----+", "| c2 | c3 | sum |", "+----+----+-----+", "| 2 | 1 | 3 |", - "+----+----+-----+", + "+----+----+-----+" ], &cached_df_results ); diff --git a/datafusion/core/src/datasource/file_format/avro.rs b/datafusion/core/src/datasource/file_format/avro.rs index 41f192acb0902..296fb1e66851a 100644 --- a/datafusion/core/src/datasource/file_format/avro.rs +++ b/datafusion/core/src/datasource/file_format/avro.rs @@ -174,8 +174,7 @@ mod tests { let batches = collect(exec, task_ctx).await?; assert_eq!(batches.len(), 1); - let expected = vec![ - "+----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+", + let expected = ["+----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+", "| id | bool_col | tinyint_col | smallint_col | int_col | bigint_col | float_col | double_col | date_string_col | string_col | timestamp_col |", "+----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+", "| 4 | true | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 30332f30312f3039 | 30 | 2009-03-01T00:00:00 |", @@ -186,8 +185,7 @@ mod tests { "| 3 | false | 1 | 1 | 1 | 10 | 1.1 | 10.1 | 30322f30312f3039 | 31 | 2009-02-01T00:01:00 |", "| 0 | true | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 30312f30312f3039 | 30 | 2009-01-01T00:00:00 |", "| 1 | false | 1 | 1 | 1 | 10 | 1.1 | 10.1 | 30312f30312f3039 | 31 | 2009-01-01T00:01:00 |", - "+----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+", - ]; + "+----+----------+-------------+--------------+---------+------------+-----------+------------+------------------+------------+---------------------+"]; crate::assert_batches_eq!(expected, &batches); Ok(()) diff --git a/datafusion/core/src/datasource/file_format/csv.rs b/datafusion/core/src/datasource/file_format/csv.rs index 488caced47bfd..1290625afe2c6 100644 --- a/datafusion/core/src/datasource/file_format/csv.rs +++ b/datafusion/core/src/datasource/file_format/csv.rs @@ -872,15 +872,13 @@ mod tests { .collect() .await?; #[rustfmt::skip] - let expected = vec![ - "+----+------+", + let expected = ["+----+------+", "| c2 | c3 |", "+----+------+", "| 5 | 36 |", "| 5 | -31 |", "| 5 | -101 |", - "+----+------+", - ]; + "+----+------+"]; assert_batches_eq!(expected, &record_batch); Ok(()) } @@ -987,13 +985,11 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "+--------------+", + let expected = ["+--------------+", "| SUM(aggr.c2) |", "+--------------+", "| 285 |", - "+--------------+", - ]; + "+--------------+"]; assert_batches_eq!(expected, &query_result); assert_eq!(n_partitions, actual_partitions); @@ -1026,13 +1022,11 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "+--------------+", + let expected = ["+--------------+", "| SUM(aggr.c3) |", "+--------------+", "| 781 |", - "+--------------+", - ]; + "+--------------+"]; assert_batches_eq!(expected, &query_result); assert_eq!(1, actual_partitions); // Compressed csv won't be scanned in parallel @@ -1064,10 +1058,8 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "++", - "++", - ]; + let expected = ["++", + "++"]; assert_batches_eq!(expected, &query_result); assert_eq!(1, actual_partitions); // Won't get partitioned if all files are empty @@ -1099,10 +1091,8 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "++", - "++", - ]; + let expected = ["++", + "++"]; assert_batches_eq!(expected, &query_result); assert_eq!(n_partitions, actual_partitions); @@ -1145,10 +1135,8 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "++", - "++", - ]; + let expected = ["++", + "++"]; assert_batches_eq!(expected, &query_result); assert_eq!(1, actual_partitions); // Won't get partitioned if all files are empty @@ -1200,13 +1188,11 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "+---------------------+", + let expected = ["+---------------------+", "| SUM(empty.column_1) |", "+---------------------+", "| 10 |", - "+---------------------+", - ]; + "+---------------------+"]; assert_batches_eq!(expected, &query_result); assert_eq!(n_partitions, actual_partitions); // Won't get partitioned if all files are empty @@ -1241,13 +1227,11 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "+-----------------------+", + let expected = ["+-----------------------+", "| SUM(one_col.column_1) |", "+-----------------------+", "| 50 |", - "+-----------------------+", - ]; + "+-----------------------+"]; let file_size = if cfg!(target_os = "windows") { 30 // new line on Win is '\r\n' } else { @@ -1291,13 +1275,11 @@ mod tests { let actual_partitions = count_query_csv_partitions(&ctx, query).await?; #[rustfmt::skip] - let expected = vec![ - "+---------------+", + let expected = ["+---------------+", "| sum_of_5_cols |", "+---------------+", "| 15 |", - "+---------------+", - ]; + "+---------------+"]; assert_batches_eq!(expected, &query_result); assert_eq!(n_partitions, actual_partitions); diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs index e224ad2d6b583..c95fa8d776876 100644 --- a/datafusion/core/src/datasource/listing/table.rs +++ b/datafusion/core/src/datasource/listing/table.rs @@ -1948,7 +1948,7 @@ mod tests { // Execute the physical plan and collect the results let res = collect(plan, session_ctx.task_ctx()).await?; // Insert returns the number of rows written, in our case this would be 6. - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -1963,7 +1963,7 @@ mod tests { let batches = session_ctx.sql("select * from t").await?.collect().await?; // Define the expected result as a vector of strings. - let expected = vec![ + let expected = [ "+---------+", "| column1 |", "+---------+", @@ -1992,7 +1992,7 @@ mod tests { // Again, execute the physical plan and collect the results let res = collect(plan, session_ctx.task_ctx()).await?; // Insert returns the number of rows written, in our case this would be 6. - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2152,7 +2152,7 @@ mod tests { // Execute the physical plan and collect the results let res = collect(plan, session_ctx.task_ctx()).await?; // Insert returns the number of rows written, in our case this would be 6. - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2169,7 +2169,7 @@ mod tests { .await? .collect() .await?; - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2193,7 +2193,7 @@ mod tests { // Again, execute the physical plan and collect the results let res = collect(plan, session_ctx.task_ctx()).await?; // Insert returns the number of rows written, in our case this would be 6. - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2212,7 +2212,7 @@ mod tests { .await?; // Define the expected result after the second append. - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2277,7 +2277,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+-----+-----+---+", "| a | b | c |", "+-----+-----+---+", diff --git a/datafusion/core/src/datasource/physical_plan/avro.rs b/datafusion/core/src/datasource/physical_plan/avro.rs index ecb78f0e3dd2e..3ff8cc4f517e4 100644 --- a/datafusion/core/src/datasource/physical_plan/avro.rs +++ b/datafusion/core/src/datasource/physical_plan/avro.rs @@ -294,7 +294,7 @@ mod tests { .expect("plan iterator empty") .expect("plan iterator returned an error"); - let expected = vec![ + let expected = [ "+----+----------+-------------+", "| id | bool_col | tinyint_col |", "+----+----------+-------------+", @@ -367,7 +367,7 @@ mod tests { .expect("plan iterator empty") .expect("plan iterator returned an error"); - let expected = vec![ + let expected = [ "+----+----------+-------------+-------------+", "| id | bool_col | tinyint_col | missing_col |", "+----+----------+-------------+-------------+", @@ -439,7 +439,7 @@ mod tests { .expect("plan iterator empty") .expect("plan iterator returned an error"); - let expected = vec![ + let expected = [ "+----+----------+------------+-------------+", "| id | bool_col | date | tinyint_col |", "+----+----------+------------+-------------+", diff --git a/datafusion/core/src/datasource/physical_plan/csv.rs b/datafusion/core/src/datasource/physical_plan/csv.rs index 127714a15d1ba..8a9822c8ca976 100644 --- a/datafusion/core/src/datasource/physical_plan/csv.rs +++ b/datafusion/core/src/datasource/physical_plan/csv.rs @@ -715,7 +715,7 @@ mod tests { assert_eq!(100, batch.num_rows()); // slice of the first 5 lines - let expected = vec![ + let expected = [ "+----+-----+------------+", "| c1 | c3 | c5 |", "+----+-----+------------+", @@ -781,7 +781,7 @@ mod tests { assert_eq!(100, batch.num_rows()); // slice of the first 5 lines - let expected = vec![ + let expected = [ "+------------+----+-----+", "| c5 | c1 | c3 |", "+------------+----+-----+", @@ -846,8 +846,7 @@ mod tests { assert_eq!(13, batch.num_columns()); assert_eq!(5, batch.num_rows()); - let expected = vec![ - "+----+----+-----+--------+------------+----------------------+-----+-------+------------+----------------------+-------------+---------------------+--------------------------------+", + let expected = ["+----+----+-----+--------+------------+----------------------+-----+-------+------------+----------------------+-------------+---------------------+--------------------------------+", "| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 | c11 | c12 | c13 |", "+----+----+-----+--------+------------+----------------------+-----+-------+------------+----------------------+-------------+---------------------+--------------------------------+", "| c | 2 | 1 | 18109 | 2033001162 | -6513304855495910254 | 25 | 43062 | 1491205016 | 5863949479783605708 | 0.110830784 | 0.9294097332465232 | 6WfVFBVGJSQb7FhA7E0lBwdvjfZnSW |", @@ -855,8 +854,7 @@ mod tests { "| b | 1 | 29 | -18218 | 994303988 | 5983957848665088916 | 204 | 9489 | 3275293996 | 14857091259186476033 | 0.53840446 | 0.17909035118828576 | AyYVExXK6AR2qUTxNZ7qRHQOVGMLcz |", "| a | 1 | -85 | -15154 | 1171968280 | 1919439543497968449 | 77 | 52286 | 774637006 | 12101411955859039553 | 0.12285209 | 0.6864391962767343 | 0keZ5G8BffGwgF2RwQD59TFzMStxCB |", "| b | 5 | -82 | 22080 | 1824882165 | 7373730676428214987 | 208 | 34331 | 3342719438 | 3330177516592499461 | 0.82634634 | 0.40975383525297016 | Ig1QcuKsjHXkproePdERo2w0mYzIqd |", - "+----+----+-----+--------+------------+----------------------+-----+-------+------------+----------------------+-------------+---------------------+--------------------------------+", - ]; + "+----+----+-----+--------+------------+----------------------+-----+-------+------------+----------------------+-------------+---------------------+--------------------------------+"]; crate::assert_batches_eq!(expected, &[batch]); @@ -977,7 +975,7 @@ mod tests { assert_eq!(100, batch.num_rows()); // slice of the first 5 lines - let expected = vec![ + let expected = [ "+----+------------+", "| c1 | date |", "+----+------------+", @@ -1118,7 +1116,7 @@ mod tests { let result = df.collect().await.unwrap(); - let expected = vec![ + let expected = [ "+---+---+", "| a | b |", "+---+---+", diff --git a/datafusion/core/src/datasource/physical_plan/file_scan_config.rs b/datafusion/core/src/datasource/physical_plan/file_scan_config.rs index c35283e4fe54e..7d4902b7bcb4b 100644 --- a/datafusion/core/src/datasource/physical_plan/file_scan_config.rs +++ b/datafusion/core/src/datasource/physical_plan/file_scan_config.rs @@ -667,7 +667,7 @@ mod tests { ], ) .expect("Projection of partition columns into record batch failed"); - let expected = vec![ + let expected = [ "+---+----+----+------+-----+", "| a | b | c | year | day |", "+---+----+----+------+-----+", @@ -701,7 +701,7 @@ mod tests { ], ) .expect("Projection of partition columns into record batch failed"); - let expected = vec![ + let expected = [ "+---+-----+----+------+-----+", "| a | b | c | year | day |", "+---+-----+----+------+-----+", @@ -737,7 +737,7 @@ mod tests { ], ) .expect("Projection of partition columns into record batch failed"); - let expected = vec![ + let expected = [ "+---+---+---+------+-----+", "| a | b | c | year | day |", "+---+---+---+------+-----+", @@ -765,7 +765,7 @@ mod tests { ], ) .expect("Projection of partition columns into record batch failed"); - let expected = vec![ + let expected = [ "+---+----+----+------+-----+", "| a | b | c | year | day |", "+---+----+----+------+-----+", diff --git a/datafusion/core/src/datasource/physical_plan/parquet.rs b/datafusion/core/src/datasource/physical_plan/parquet.rs index 3ef1d13c26931..d973f13fad0a2 100644 --- a/datafusion/core/src/datasource/physical_plan/parquet.rs +++ b/datafusion/core/src/datasource/physical_plan/parquet.rs @@ -1002,7 +1002,7 @@ mod tests { .round_trip_to_batches(vec![batch1, batch2]) .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+----+----+", "| c1 | c2 | c3 |", "+-----+----+----+", @@ -1037,7 +1037,7 @@ mod tests { .round_trip_to_batches(vec![batch1, batch2]) .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+----+----+", "| c1 | c3 | c2 |", "+-----+----+----+", @@ -1075,7 +1075,7 @@ mod tests { .round_trip_to_batches(vec![batch1, batch2]) .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+----+----+", "| c1 | c3 | c2 |", "+-----+----+----+", @@ -1114,7 +1114,7 @@ mod tests { .round_trip(vec![batch1, batch2]) .await; - let expected = vec![ + let expected = [ "+----+----+----+", "| c1 | c3 | c2 |", "+----+----+----+", @@ -1156,7 +1156,7 @@ mod tests { .round_trip_to_batches(vec![batch1, batch2]) .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+-----+", "| c1 | c4 |", "+-----+-----+", @@ -1230,7 +1230,7 @@ mod tests { // a null array, then the pruning predicate (currently) can not be applied. // In a real query where this predicate was pushed down from a filter stage instead of created directly in the `ParquetExec`, // the filter stage would be preserved as a separate execution plan stage so the actual query results would be as expected. - let expected = vec![ + let expected = [ "+-----+----+", "| c1 | c2 |", "+-----+----+", @@ -1267,7 +1267,7 @@ mod tests { .round_trip(vec![batch1, batch2]) .await; - let expected = vec![ + let expected = [ "+----+----+", "| c1 | c2 |", "+----+----+", @@ -1374,7 +1374,7 @@ mod tests { .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+----+", "| c1 | c2 |", "+-----+----+", @@ -1405,7 +1405,7 @@ mod tests { .await .unwrap(); - let expected = vec![ + let expected = [ "+-----+----+", "| c1 | c2 |", "+-----+----+", @@ -1651,7 +1651,7 @@ mod tests { let mut results = parquet_exec.execute(0, task_ctx)?; let batch = results.next().await.unwrap()?; assert_eq!(batch.schema().as_ref(), &expected_schema); - let expected = vec![ + let expected = [ "+----+----------+-------------+-------+-----+", "| id | bool_col | tinyint_col | month | day |", "+----+----------+-------------+-------+-----+", @@ -1742,14 +1742,12 @@ mod tests { // assert the batches and some metrics #[rustfmt::skip] - let expected = vec![ - "+-----+", + let expected = ["+-----+", "| int |", "+-----+", "| 4 |", "| 5 |", - "+-----+", - ]; + "+-----+"]; assert_batches_sorted_eq!(expected, &rt.batches.unwrap()); assert_eq!(get_value(&metrics, "page_index_rows_filtered"), 4); assert!( @@ -1786,7 +1784,7 @@ mod tests { let metrics = rt.parquet_exec.metrics().unwrap(); // assert the batches and some metrics - let expected = vec![ + let expected = [ "+-----+", "| c1 |", "+-----+", "| Foo |", "| zzz |", "+-----+", ]; assert_batches_sorted_eq!(expected, &rt.batches.unwrap()); diff --git a/datafusion/core/src/datasource/view.rs b/datafusion/core/src/datasource/view.rs index 391e4b93c4e57..210acad18c930 100644 --- a/datafusion/core/src/datasource/view.rs +++ b/datafusion/core/src/datasource/view.rs @@ -175,7 +175,7 @@ mod tests { .collect() .await?; - let expected = vec!["+---+", "| b |", "+---+", "| 2 |", "+---+"]; + let expected = ["+---+", "| b |", "+---+", "| 2 |", "+---+"]; assert_batches_eq!(expected, &results); @@ -221,7 +221,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------+---------+---------+", "| column1 | column2 | column3 |", "+---------+---------+---------+", @@ -254,7 +254,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------------+", "| column1_alias |", "+---------------+", @@ -287,7 +287,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------------+---------------+", "| column2_alias | column1_alias |", "+---------------+---------------+", @@ -325,7 +325,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------+", "| column1 |", "+---------+", @@ -363,7 +363,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------+", "| column1 |", "+---------+", @@ -403,7 +403,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------+---------+---------+", "| column2 | column1 | column3 |", "+---------+---------+---------+", @@ -558,7 +558,7 @@ mod tests { .collect() .await?; - let expected = vec![ + let expected = [ "+---------+", "| column1 |", "+---------+", diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs index 8fcc3583fbc93..bcbfb515708bc 100644 --- a/datafusion/core/src/execution/context.rs +++ b/datafusion/core/src/execution/context.rs @@ -2339,7 +2339,7 @@ mod tests { plan_and_collect(&ctx, "SELECT @@version, @name, @integer + 1 FROM dual") .await?; - let expected = vec![ + let expected = [ "+----------------------+------------------------+---------------------+", "| @@version | @name | @integer + Int64(1) |", "+----------------------+------------------------+---------------------+", @@ -2407,7 +2407,7 @@ mod tests { // Can call it if you put quotes let result = plan_and_collect(&ctx, "SELECT \"MY_FUNC\"(i) FROM t").await?; - let expected = vec![ + let expected = [ "+--------------+", "| MY_FUNC(t.i) |", "+--------------+", @@ -2448,7 +2448,7 @@ mod tests { // Can call it if you put quotes let result = plan_and_collect(&ctx, "SELECT \"MY_AVG\"(i) FROM t").await?; - let expected = vec![ + let expected = [ "+-------------+", "| MY_AVG(t.i) |", "+-------------+", @@ -2481,7 +2481,7 @@ mod tests { plan_and_collect(&ctx, "SELECT SUM(c1), SUM(c2), COUNT(*) FROM test").await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+----------+", "| SUM(test.c1) | SUM(test.c2) | COUNT(*) |", "+--------------+--------------+----------+", @@ -2629,7 +2629,7 @@ mod tests { .await .unwrap(); - let expected = vec![ + let expected = [ "+-------+", "| count |", "+-------+", @@ -2671,7 +2671,7 @@ mod tests { ) .await?; - let expected = vec![ + let expected = [ "+-----+-------+", "| cat | total |", "+-----+-------+", diff --git a/datafusion/core/src/physical_optimizer/dist_enforcement.rs b/datafusion/core/src/physical_optimizer/dist_enforcement.rs index cb98e69d7afca..e8a2786dc11e4 100644 --- a/datafusion/core/src/physical_optimizer/dist_enforcement.rs +++ b/datafusion/core/src/physical_optimizer/dist_enforcement.rs @@ -847,7 +847,7 @@ fn ensure_distribution( // Add RepartitionExec to guarantee output partitioning let new_children: Result>> = children .into_iter() - .zip(required_input_distributions.into_iter()) + .zip(required_input_distributions) .map(|(child, required)| { if child .output_partitioning() @@ -903,7 +903,7 @@ impl PlanWithKeyRequirements { assert_eq!(plan_children.len(), self.request_key_ordering.len()); plan_children .into_iter() - .zip(self.request_key_ordering.clone().into_iter()) + .zip(self.request_key_ordering.clone()) .map(|(child, required)| { let from_parent = required.unwrap_or_default(); let length = child.children().len(); diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs index efb1304319cb3..2987ec6d6552a 100644 --- a/datafusion/core/src/physical_optimizer/pruning.rs +++ b/datafusion/core/src/physical_optimizer/pruning.rs @@ -1211,7 +1211,7 @@ mod tests { let batch = build_statistics_record_batch(&statistics, &required_columns).unwrap(); - let expected = vec![ + let expected = [ "+--------+--------+--------+--------+", "| s1_min | s2_max | s3_max | s3_min |", "+--------+--------+--------+--------+", @@ -1250,7 +1250,7 @@ mod tests { let batch = build_statistics_record_batch(&statistics, &required_columns).unwrap(); - let expected = vec![ + let expected = [ "+-------------------------------+", "| s1_min |", "+-------------------------------+", @@ -1296,7 +1296,7 @@ mod tests { let batch = build_statistics_record_batch(&statistics, &required_columns).unwrap(); - let expected = vec![ + let expected = [ "+--------+", "| s1_min |", "+--------+", diff --git a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs index af2c752499736..231fbf4074b1b 100644 --- a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs +++ b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs @@ -362,19 +362,15 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -440,21 +436,17 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -473,23 +465,19 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -510,25 +498,21 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " CoalesceBatchesExec: target_batch_size=8192", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " CoalesceBatchesExec: target_batch_size=8192", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -546,22 +530,18 @@ mod tests { let physical_plan: Arc = coalesce_partitions_exec(coalesce_batches_exec); - let expected_input = vec![ - "CoalescePartitionsExec", + let expected_input = ["CoalescePartitionsExec", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "CoalescePartitionsExec", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["CoalescePartitionsExec", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -581,25 +561,21 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " CoalesceBatchesExec: target_batch_size=8192", " FilterExec: c@2 > 3", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -620,20 +596,16 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr_default("c", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [c@2 ASC]", + let expected_input = ["SortPreservingMergeExec: [c@2 ASC]", " SortExec: expr=[c@2 ASC]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [c@2 ASC]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [c@2 ASC]", " SortExec: expr=[c@2 ASC]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -649,19 +621,15 @@ mod tests { let physical_plan = sort_exec(vec![sort_expr("a", &schema)], coalesce_partitions, false); - let expected_input = vec![ - "SortExec: expr=[a@0 ASC NULLS LAST]", + let expected_input = ["SortExec: expr=[a@0 ASC NULLS LAST]", " CoalescePartitionsExec", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan); Ok(()) } @@ -782,19 +750,15 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("a", &schema)], sort); - let expected_input = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + let expected_input = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortExec: expr=[a@0 ASC NULLS LAST]", " RepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC NULLS LAST]", + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC NULLS LAST]", " SortPreservingRepartitionExec: partitioning=Hash([c1@0], 8), input_partitions=8", " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", - " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], output_ordering=[a@0 ASC NULLS LAST], has_header=true", - ]; + " CsvExec: file_groups={1 group: [[file_path]]}, projection=[a, c, d], output_ordering=[a@0 ASC NULLS LAST], has_header=true"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } diff --git a/datafusion/core/src/physical_optimizer/sort_enforcement.rs b/datafusion/core/src/physical_optimizer/sort_enforcement.rs index 644aea1f38128..261bec7232961 100644 --- a/datafusion/core/src/physical_optimizer/sort_enforcement.rs +++ b/datafusion/core/src/physical_optimizer/sort_enforcement.rs @@ -1439,12 +1439,12 @@ mod tests { let input = sort_exec(vec![sort_expr("non_nullable_col", &schema)], source); let physical_plan = sort_exec(vec![sort_expr("nullable_col", &schema)], input); - let expected_input = vec![ + let expected_input = [ "SortExec: expr=[nullable_col@0 ASC]", " SortExec: expr=[non_nullable_col@1 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1493,24 +1493,20 @@ mod tests { let physical_plan = bounded_window_exec("non_nullable_col", sort_exprs, filter); - let expected_input = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + let expected_input = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " FilterExec: NOT non_nullable_col@1", " SortExec: expr=[non_nullable_col@1 ASC NULLS LAST]", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " CoalesceBatchesExec: target_batch_size=128", " SortExec: expr=[non_nullable_col@1 DESC]", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; - let expected_optimized = vec![ - "WindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: CurrentRow, end_bound: Following(NULL) }]", + let expected_optimized = ["WindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: CurrentRow, end_bound: Following(NULL) }]", " FilterExec: NOT non_nullable_col@1", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " CoalesceBatchesExec: target_batch_size=128", " SortExec: expr=[non_nullable_col@1 DESC]", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -1524,11 +1520,11 @@ mod tests { let physical_plan = sort_preserving_merge_exec(sort_exprs, source); - let expected_input = vec![ + let expected_input = [ "SortPreservingMergeExec: [nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1547,14 +1543,14 @@ mod tests { let sort_exprs = vec![sort_expr("nullable_col", &schema)]; let sort = sort_exec(sort_exprs.clone(), spm); let physical_plan = sort_preserving_merge_exec(sort_exprs, sort); - let expected_input = vec![ + let expected_input = [ "SortPreservingMergeExec: [nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " SortPreservingMergeExec: [nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1581,7 +1577,7 @@ mod tests { let sort3 = sort_exec(sort_exprs, spm2); let physical_plan = repartition_exec(repartition_exec(sort3)); - let expected_input = vec![ + let expected_input = [ "RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", " SortExec: expr=[nullable_col@0 ASC]", @@ -1592,7 +1588,7 @@ mod tests { " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", " MemoryExec: partitions=1, partition_sizes=[0]", @@ -1625,7 +1621,7 @@ mod tests { // When removing a `SortPreservingMergeExec`, make sure that partitioning // requirements are not violated. In some cases, we may need to replace // it with a `CoalescePartitionsExec` instead of directly removing it. - let expected_input = vec![ + let expected_input = [ "AggregateExec: mode=Final, gby=[], aggr=[]", " SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", @@ -1635,7 +1631,7 @@ mod tests { " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "AggregateExec: mode=Final, gby=[], aggr=[]", " CoalescePartitionsExec", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", @@ -1676,8 +1672,7 @@ mod tests { // When removing a `SortPreservingMergeExec`, make sure that partitioning // requirements are not violated. In some cases, we may need to replace // it with a `CoalescePartitionsExec` instead of directly removing it. - let expected_input = vec![ - "SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_input = ["SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " FilterExec: NOT non_nullable_col@1", " SortPreservingMergeExec: [non_nullable_col@1 ASC]", " SortExec: expr=[non_nullable_col@1 ASC]", @@ -1685,19 +1680,16 @@ mod tests { " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", " MemoryExec: partitions=1, partition_sizes=[0]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " FilterExec: NOT non_nullable_col@1", " UnionExec", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", " MemoryExec: partitions=1, partition_sizes=[0]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -1717,18 +1709,14 @@ mod tests { let join = hash_join_exec(left_input, right_input, on, None, &JoinType::Inner)?; let physical_plan = sort_exec(vec![sort_expr("a", &join.schema())], join); - let expected_input = vec![ - "SortExec: expr=[a@2 ASC]", + let expected_input = ["SortExec: expr=[a@2 ASC]", " HashJoinExec: mode=Partitioned, join_type=Inner, on=[(col_a@0, c@2)]", " MemoryExec: partitions=1, partition_sizes=[0]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC]"]; - let expected_optimized = vec![ - "HashJoinExec: mode=Partitioned, join_type=Inner, on=[(col_a@0, c@2)]", + let expected_optimized = ["HashJoinExec: mode=Partitioned, join_type=Inner, on=[(col_a@0, c@2)]", " MemoryExec: partitions=1, partition_sizes=[0]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -1748,13 +1736,13 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_expr("nullable_col", &schema)], input2); - let expected_input = vec![ + let expected_input = [ "SortPreservingMergeExec: [nullable_col@0 ASC]", " SortPreservingMergeExec: [non_nullable_col@1 ASC]", " SortPreservingMergeExec: [non_nullable_col@1 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1781,20 +1769,17 @@ mod tests { let repartition = repartition_exec(union); let physical_plan = sort_preserving_merge_exec(sort_exprs, repartition); - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=2", " UnionExec", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " GlobalLimitExec: skip=0, fetch=100", " LocalLimitExec: fetch=100", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; // We should keep the bottom `SortExec`. - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=2", " UnionExec", @@ -1802,8 +1787,7 @@ mod tests { " GlobalLimitExec: skip=0, fetch=100", " LocalLimitExec: fetch=100", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -1818,12 +1802,12 @@ mod tests { ]; let sort = sort_exec(vec![sort_exprs[0].clone()], source); let physical_plan = sort_preserving_merge_exec(sort_exprs, sort); - let expected_input = vec![ + let expected_input = [ "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1844,13 +1828,13 @@ mod tests { let physical_plan = sort_preserving_merge_exec(vec![sort_exprs[1].clone()], sort2); - let expected_input = vec![ + let expected_input = [ "SortPreservingMergeExec: [non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; - let expected_optimized = vec![ + let expected_optimized = [ "SortExec: expr=[non_nullable_col@1 ASC]", " MemoryExec: partitions=1, partition_sizes=[0]", ]; @@ -1936,22 +1920,18 @@ mod tests { // Input is an invalid plan. In this case rule should add required sorting in appropriate places. // First ParquetExec has output ordering(nullable_col@0 ASC). However, it doesn't satisfy the // required ordering of SortPreservingMergeExec. - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " UnionExec", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -1978,25 +1958,21 @@ mod tests { // First input to the union is not Sorted (SortExec is finer than required ordering by the SortPreservingMergeExec above). // Second input to the union is already Sorted (matches with the required ordering by the SortPreservingMergeExec above). // Third input to the union is not Sorted (SortExec is matches required ordering by the SortPreservingMergeExec above). - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; // should adjust sorting in the first input of the union such that it is not unnecessarily fine - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2023,25 +1999,21 @@ mod tests { // Should modify the plan to ensure that all three inputs to the // `UnionExec` satisfy the ordering, OR add a single sort after // the `UnionExec` (both of which are equally good for this example). - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2076,22 +2048,18 @@ mod tests { // The `UnionExec` doesn't preserve any of the inputs ordering in the // example below. However, we should be able to change the unnecessarily // fine `SortExec`s below with required `SortExec`s that are absolutely necessary. - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 DESC NULLS LAST]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2122,28 +2090,24 @@ mod tests { // At the same time, this ordering requirement is unnecessarily fine. // The final plan should be valid AND the ordering of the third child // shouldn't be finer than necessary. - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; // Should adjust the requirement in the third input of the union so // that it is not unnecessarily fine. - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2165,23 +2129,19 @@ mod tests { let physical_plan = sort_preserving_merge_exec(sort_exprs3, union); // Union has unnecessarily fine ordering below it. We should be able to replace them with absolutely necessary ordering. - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; // Union preserves the inputs ordering and we should not change any of the SortExecs under UnionExec - let expected_output = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_output = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_output, physical_plan, true); Ok(()) } @@ -2220,20 +2180,16 @@ mod tests { // The `UnionExec` doesn't preserve any of the inputs ordering in the // example below. - let expected_input = vec![ - "UnionExec", + let expected_input = ["UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[nullable_col@0 DESC NULLS LAST,non_nullable_col@1 DESC NULLS LAST]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; // Since `UnionExec` doesn't preserve ordering in the plan above. // We shouldn't keep SortExecs in the plan. - let expected_optimized = vec![ - "UnionExec", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", + let expected_optimized = ["UnionExec", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2269,22 +2225,18 @@ mod tests { // During the removal of `SortExec`s, it should be able to remove the // corresponding SortExecs together. Also, the inputs of these `SortExec`s // are not necessarily the same to be able to remove them. - let expected_input = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + let expected_input = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " SortPreservingMergeExec: [nullable_col@0 DESC NULLS LAST]", " UnionExec", " SortExec: expr=[nullable_col@0 DESC NULLS LAST]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC, non_nullable_col@1 ASC]", " SortExec: expr=[nullable_col@0 DESC NULLS LAST]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", - ]; - let expected_optimized = vec![ - "WindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: CurrentRow, end_bound: Following(NULL) }]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]"]; + let expected_optimized = ["WindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: CurrentRow, end_bound: Following(NULL) }]", " SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC, non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2309,22 +2261,18 @@ mod tests { // The `WindowAggExec` can get its required sorting from the leaf nodes directly. // The unnecessary SortExecs should be removed - let expected_input = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + let expected_input = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", - ]; - let expected_optimized = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]"]; + let expected_optimized = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col], output_ordering=[nullable_col@0 ASC]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2360,26 +2308,22 @@ mod tests { let physical_plan = sort_preserving_merge_exec(sort_exprs3, union); // Should not change the unnecessarily fine `SortExec`s because there is `LimitExec` - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " GlobalLimitExec: skip=0, fetch=100", " LocalLimitExec: fetch=100", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 DESC NULLS LAST]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " UnionExec", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " GlobalLimitExec: skip=0, fetch=100", " LocalLimitExec: fetch=100", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 DESC NULLS LAST]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2421,12 +2365,10 @@ mod tests { let join_plan2 = format!( " SortMergeJoin: join_type={join_type}, on=[(nullable_col@0, col_a@0)]" ); - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC,non_nullable_col@1 ASC]", join_plan2.as_str(), " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; let expected_optimized = match join_type { JoinType::Inner | JoinType::Left @@ -2500,12 +2442,10 @@ mod tests { let join_plan2 = format!( " SortMergeJoin: join_type={join_type}, on=[(nullable_col@0, col_a@0)]" ); - let expected_input = vec![ - spm_plan, + let expected_input = [spm_plan, join_plan2.as_str(), " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; let expected_optimized = match join_type { JoinType::Inner | JoinType::Right | JoinType::RightAnti => { // can push down the sort requirements and save 1 SortExec @@ -2557,22 +2497,18 @@ mod tests { ]; let physical_plan = sort_preserving_merge_exec(sort_exprs1, join.clone()); - let expected_input = vec![ - "SortPreservingMergeExec: [col_b@3 ASC,col_a@2 ASC]", + let expected_input = ["SortPreservingMergeExec: [col_b@3 ASC,col_a@2 ASC]", " SortMergeJoin: join_type=Inner, on=[(nullable_col@0, col_a@0)]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; // can not push down the sort requirements, need to add SortExec - let expected_optimized = vec![ - "SortExec: expr=[col_b@3 ASC,col_a@2 ASC]", + let expected_optimized = ["SortExec: expr=[col_b@3 ASC,col_a@2 ASC]", " SortMergeJoin: join_type=Inner, on=[(nullable_col@0, col_a@0)]", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[col_a@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); // order by (nullable_col, col_b, col_a) @@ -2583,22 +2519,18 @@ mod tests { ]; let physical_plan = sort_preserving_merge_exec(sort_exprs2, join); - let expected_input = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC,col_b@3 ASC,col_a@2 ASC]", + let expected_input = ["SortPreservingMergeExec: [nullable_col@0 ASC,col_b@3 ASC,col_a@2 ASC]", " SortMergeJoin: join_type=Inner, on=[(nullable_col@0, col_a@0)]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; // can not push down the sort requirements, need to add SortExec - let expected_optimized = vec![ - "SortExec: expr=[nullable_col@0 ASC,col_b@3 ASC,col_a@2 ASC]", + let expected_optimized = ["SortExec: expr=[nullable_col@0 ASC,col_b@3 ASC,col_a@2 ASC]", " SortMergeJoin: join_type=Inner, on=[(nullable_col@0, col_a@0)]", " SortExec: expr=[nullable_col@0 ASC]", " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", " SortExec: expr=[col_a@0 ASC]", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[col_a, col_b]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) @@ -2624,21 +2556,17 @@ mod tests { let physical_plan = bounded_window_exec("non_nullable_col", sort_exprs1, window_agg2); - let expected_input = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + let expected_input = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " SortExec: expr=[nullable_col@0 ASC]", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; - let expected_optimized = vec![ - "BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", + let expected_optimized = ["BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " BoundedWindowAggExec: wdw=[count: Ok(Field { name: \"count\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(NULL), end_bound: CurrentRow }], mode=[Sorted]", " SortExec: expr=[nullable_col@0 ASC,non_nullable_col@1 ASC]", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; + " MemoryExec: partitions=1, partition_sizes=[0]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2663,20 +2591,16 @@ mod tests { // CoalescePartitionsExec and SortExec are not directly consecutive. In this case // we should be able to parallelize Sorting also (given that executors in between don't require) // single partition. - let expected_input = vec![ - "SortExec: expr=[nullable_col@0 ASC]", + let expected_input = ["SortExec: expr=[nullable_col@0 ASC]", " FilterExec: NOT non_nullable_col@1", " CoalescePartitionsExec", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [nullable_col@0 ASC]", + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; + let expected_optimized = ["SortPreservingMergeExec: [nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " FilterExec: NOT non_nullable_col@1", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]", - ]; + " ParquetExec: file_groups={1 group: [[x]]}, projection=[nullable_col, non_nullable_col]"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2745,16 +2669,14 @@ mod tests { let physical_plan = sort.clone(); // Sort Parallelize rule should end Coalesce + Sort linkage when Sort is Global Sort // Also input plan is not valid as it is. We need to add SortExec before SortPreservingMergeExec. - let expected_input = vec![ - "SortExec: expr=[nullable_col@0 ASC]", + let expected_input = ["SortExec: expr=[nullable_col@0 ASC]", " SortPreservingMergeExec: [nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", " CoalescePartitionsExec", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " MemoryExec: partitions=1, partition_sizes=[0]", - ]; - let expected_optimized = vec![ + " MemoryExec: partitions=1, partition_sizes=[0]"]; + let expected_optimized = [ "SortPreservingMergeExec: [nullable_col@0 ASC]", " SortExec: expr=[nullable_col@0 ASC]", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", @@ -2777,20 +2699,16 @@ mod tests { let coalesce_partitions = coalesce_partitions_exec(repartition_hash); let physical_plan = sort_exec(vec![sort_expr("a", &schema)], coalesce_partitions); - let expected_input = vec![ - "SortExec: expr=[a@0 ASC]", + let expected_input = ["SortExec: expr=[a@0 ASC]", " CoalescePartitionsExec", " RepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], has_header=false", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC]", + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], has_header=false"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC]", " SortExec: expr=[a@0 ASC]", " RepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], has_header=false", - ]; + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], output_ordering=[a@0 ASC], has_header=false"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2808,19 +2726,15 @@ mod tests { let coalesce_partitions = coalesce_partitions_exec(repartition_hash); let physical_plan = sort_exec(vec![sort_expr("a", &schema)], coalesce_partitions); - let expected_input = vec![ - "SortExec: expr=[a@0 ASC]", + let expected_input = ["SortExec: expr=[a@0 ASC]", " CoalescePartitionsExec", " RepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC]", + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC]", " SortPreservingRepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false", - ]; + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false"]; assert_optimized!(expected_input, expected_optimized, physical_plan, true); Ok(()) } @@ -2838,19 +2752,15 @@ mod tests { let coalesce_partitions = coalesce_partitions_exec(repartition_hash); let physical_plan = sort_exec(vec![sort_expr("a", &schema)], coalesce_partitions); - let expected_input = vec![ - "SortExec: expr=[a@0 ASC]", + let expected_input = ["SortExec: expr=[a@0 ASC]", " CoalescePartitionsExec", " RepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false", - ]; - let expected_optimized = vec![ - "SortPreservingMergeExec: [a@0 ASC]", + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false"]; + let expected_optimized = ["SortPreservingMergeExec: [a@0 ASC]", " SortPreservingRepartitionExec: partitioning=Hash([c@2], 10), input_partitions=10", " RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=1", - " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false", - ]; + " CsvExec: file_groups={1 group: [[x]]}, projection=[a, b, c, d, e], infinite_source=true, output_ordering=[a@0 ASC], has_header=false"]; assert_optimized!(expected_input, expected_optimized, physical_plan, false); Ok(()) } diff --git a/datafusion/core/src/physical_plan/aggregates/mod.rs b/datafusion/core/src/physical_plan/aggregates/mod.rs index 8338da8ed6777..78ef5e37b239d 100644 --- a/datafusion/core/src/physical_plan/aggregates/mod.rs +++ b/datafusion/core/src/physical_plan/aggregates/mod.rs @@ -591,7 +591,7 @@ impl AggregateExec { // Reset ordering requirement to `None` if aggregator is not order-sensitive order_by_expr = aggr_expr .iter() - .zip(order_by_expr.into_iter()) + .zip(order_by_expr) .map(|(aggr_expr, fn_reqs)| { // If the aggregation function is order-sensitive and we are // performing a "first stage" calculation, keep the ordering @@ -1535,7 +1535,7 @@ mod tests { let result = common::collect(partial_aggregate.execute(0, task_ctx.clone())?).await?; - let expected = vec![ + let expected = [ "+---+---------------+-------------+", "| a | AVG(b)[count] | AVG(b)[sum] |", "+---+---------------+-------------+", @@ -1997,7 +1997,7 @@ mod tests { let result = crate::physical_plan::collect(aggregate_final, task_ctx).await?; if is_first_acc { - let expected = vec![ + let expected = [ "+---+----------------+", "| a | FIRST_VALUE(b) |", "+---+----------------+", @@ -2008,7 +2008,7 @@ mod tests { ]; assert_batches_eq!(expected, &result); } else { - let expected = vec![ + let expected = [ "+---+---------------+", "| a | LAST_VALUE(b) |", "+---+---------------+", diff --git a/datafusion/core/src/physical_plan/filter.rs b/datafusion/core/src/physical_plan/filter.rs index 084b0b15d102e..779fa16c7a541 100644 --- a/datafusion/core/src/physical_plan/filter.rs +++ b/datafusion/core/src/physical_plan/filter.rs @@ -754,7 +754,7 @@ mod tests { // total_byte_size after ceil => 532.0... => 533 assert_eq!(statistics.num_rows, Some(134)); assert_eq!(statistics.total_byte_size, Some(533)); - let exp_col_stats = Some(vec![ + let exp_col_stats = vec![ ColumnStatistics { min_value: Some(ScalarValue::Int32(Some(4))), max_value: Some(ScalarValue::Int32(Some(53))), @@ -770,9 +770,8 @@ mod tests { max_value: Some(ScalarValue::Float32(Some(1075.0))), ..Default::default() }, - ]); + ]; let _ = exp_col_stats - .unwrap() .into_iter() .zip(statistics.column_statistics.unwrap()) .map(|(expected, actual)| { diff --git a/datafusion/core/src/physical_plan/joins/cross_join.rs b/datafusion/core/src/physical_plan/joins/cross_join.rs index 6d74a069b6e8a..256942754350e 100644 --- a/datafusion/core/src/physical_plan/joins/cross_join.rs +++ b/datafusion/core/src/physical_plan/joins/cross_join.rs @@ -632,7 +632,7 @@ mod tests { let (columns, batches) = join_collect(left, right, task_ctx).await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", diff --git a/datafusion/core/src/physical_plan/joins/hash_join.rs b/datafusion/core/src/physical_plan/joins/hash_join.rs index f7d257e324eab..075d371f5199c 100644 --- a/datafusion/core/src/physical_plan/joins/hash_join.rs +++ b/datafusion/core/src/physical_plan/joins/hash_join.rs @@ -1246,7 +1246,7 @@ mod tests { assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1290,7 +1290,7 @@ mod tests { assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1327,7 +1327,7 @@ mod tests { assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1373,7 +1373,7 @@ mod tests { assert_eq!(batches.len(), 1); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1427,7 +1427,7 @@ mod tests { assert_eq!(batches.len(), 1); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1479,7 +1479,7 @@ mod tests { let batches = common::collect(stream).await?; assert_eq!(batches.len(), 1); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1492,7 +1492,7 @@ mod tests { let stream = join.execute(1, task_ctx.clone())?; let batches = common::collect(stream).await?; assert_eq!(batches.len(), 1); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1544,7 +1544,7 @@ mod tests { let stream = join.execute(0, task_ctx).unwrap(); let batches = common::collect(stream).await.unwrap(); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1586,7 +1586,7 @@ mod tests { let stream = join.execute(0, task_ctx).unwrap(); let batches = common::collect(stream).await.unwrap(); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1626,7 +1626,7 @@ mod tests { let stream = join.execute(0, task_ctx).unwrap(); let batches = common::collect(stream).await.unwrap(); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1662,7 +1662,7 @@ mod tests { let stream = join.execute(0, task_ctx).unwrap(); let batches = common::collect(stream).await.unwrap(); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1704,7 +1704,7 @@ mod tests { .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1747,7 +1747,7 @@ mod tests { .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1801,7 +1801,7 @@ mod tests { let batches = common::collect(stream).await?; // ignore the order - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -1861,7 +1861,7 @@ mod tests { let stream = join.execute(0, task_ctx.clone())?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -1889,7 +1889,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -1921,7 +1921,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -1981,7 +1981,7 @@ mod tests { let stream = join.execute(0, task_ctx.clone())?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -2007,7 +2007,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -2039,7 +2039,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+----+", "| a1 | b1 | c1 |", "+----+----+----+", @@ -2097,7 +2097,7 @@ mod tests { let stream = join.execute(0, task_ctx.clone())?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -2129,7 +2129,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -2164,7 +2164,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -2222,7 +2222,7 @@ mod tests { let stream = join.execute(0, task_ctx.clone())?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -2258,7 +2258,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", @@ -2296,7 +2296,7 @@ mod tests { assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -2335,7 +2335,7 @@ mod tests { assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b1", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -2376,7 +2376,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -2480,7 +2480,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+----+", "| a | b | c | a | b | c |", "+---+---+---+----+---+----+", @@ -2544,7 +2544,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+---+", "| a | b | c | a | b | c |", "+---+---+---+----+---+---+", @@ -2584,7 +2584,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+---+", "| a | b | c | a | b | c |", "+---+---+---+----+---+---+", @@ -2627,7 +2627,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+---+", "| a | b | c | a | b | c |", "+---+---+---+----+---+---+", @@ -2669,7 +2669,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+---+", "| a | b | c | a | b | c |", "+---+---+---+----+---+---+", @@ -2716,7 +2716,7 @@ mod tests { let stream = join.execute(0, task_ctx)?; let batches = common::collect(stream).await?; - let expected = vec![ + let expected = [ "+------------+---+------------+---+", "| date | n | date | n |", "+------------+---+------------+---+", diff --git a/datafusion/core/src/physical_plan/joins/nested_loop_join.rs b/datafusion/core/src/physical_plan/joins/nested_loop_join.rs index 74a26fbff6368..618dd66e69a09 100644 --- a/datafusion/core/src/physical_plan/joins/nested_loop_join.rs +++ b/datafusion/core/src/physical_plan/joins/nested_loop_join.rs @@ -893,7 +893,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -922,7 +922,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+-----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+-----+----+----+----+", @@ -953,7 +953,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+----+----+-----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+-----+", @@ -984,7 +984,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+-----+----+----+-----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+-----+----+----+-----+", @@ -1017,7 +1017,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1"]); - let expected = vec![ + let expected = [ "+----+----+----+", "| a1 | b1 | c1 |", "+----+----+----+", @@ -1046,7 +1046,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a1", "b1", "c1"]); - let expected = vec![ + let expected = [ "+----+----+-----+", "| a1 | b1 | c1 |", "+----+----+-----+", @@ -1076,7 +1076,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+----+", "| a2 | b2 | c2 |", "+----+----+----+", @@ -1105,7 +1105,7 @@ mod tests { ) .await?; assert_eq!(columns, vec!["a2", "b2", "c2"]); - let expected = vec![ + let expected = [ "+----+----+-----+", "| a2 | b2 | c2 |", "+----+----+-----+", diff --git a/datafusion/core/src/physical_plan/joins/sort_merge_join.rs b/datafusion/core/src/physical_plan/joins/sort_merge_join.rs index 1735e2d3eb716..3de98f5452c57 100644 --- a/datafusion/core/src/physical_plan/joins/sort_merge_join.rs +++ b/datafusion/core/src/physical_plan/joins/sort_merge_join.rs @@ -1591,7 +1591,7 @@ mod tests { let (_, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1629,7 +1629,7 @@ mod tests { ]; let (_columns, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1667,7 +1667,7 @@ mod tests { ]; let (_columns, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1706,7 +1706,7 @@ mod tests { ]; let (_, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1757,7 +1757,7 @@ mod tests { true, ) .await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1797,7 +1797,7 @@ mod tests { let (_, batches) = join_collect_batch_size_equals_two(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b2 | c1 | a1 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1832,7 +1832,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Left).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1864,7 +1864,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Right).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+----+----+----+----+----+----+", @@ -1896,7 +1896,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Full).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -1928,7 +1928,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::LeftAnti).await?; - let expected = vec![ + let expected = [ "+----+----+----+", "| a1 | b1 | c1 |", "+----+----+----+", @@ -1959,7 +1959,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::LeftSemi).await?; - let expected = vec![ + let expected = [ "+----+----+----+", "| a1 | b1 | c1 |", "+----+----+----+", @@ -1992,7 +1992,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ + let expected = [ "+---+---+---+----+---+----+", "| a | b | c | a | b | c |", "+---+---+---+----+---+----+", @@ -2025,15 +2025,13 @@ mod tests { let (_, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ - "+------------+------------+------------+------------+------------+------------+", + let expected = ["+------------+------------+------------+------------+------------+------------+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+------------+------------+------------+------------+------------+------------+", "| 1970-01-02 | 2022-04-25 | 1970-01-08 | 1970-01-11 | 2022-04-25 | 1970-03-12 |", "| 1970-01-03 | 2022-04-26 | 1970-01-09 | 1970-01-21 | 2022-04-26 | 1970-03-22 |", "| 1970-01-04 | 2022-04-26 | 1970-01-10 | 1970-01-21 | 2022-04-26 | 1970-03-22 |", - "+------------+------------+------------+------------+------------+------------+", - ]; + "+------------+------------+------------+------------+------------+------------+"]; // The output order is important as SMJ preserves sortedness assert_batches_eq!(expected, &batches); Ok(()) @@ -2059,15 +2057,13 @@ mod tests { let (_, batches) = join_collect(left, right, on, JoinType::Inner).await?; - let expected = vec![ - "+-------------------------+---------------------+-------------------------+-------------------------+---------------------+-------------------------+", + let expected = ["+-------------------------+---------------------+-------------------------+-------------------------+---------------------+-------------------------+", "| a1 | b1 | c1 | a2 | b1 | c2 |", "+-------------------------+---------------------+-------------------------+-------------------------+---------------------+-------------------------+", "| 1970-01-01T00:00:00.001 | 2022-04-23T08:44:01 | 1970-01-01T00:00:00.007 | 1970-01-01T00:00:00.010 | 2022-04-23T08:44:01 | 1970-01-01T00:00:00.070 |", "| 1970-01-01T00:00:00.002 | 2022-04-25T16:17:21 | 1970-01-01T00:00:00.008 | 1970-01-01T00:00:00.030 | 2022-04-25T16:17:21 | 1970-01-01T00:00:00.090 |", "| 1970-01-01T00:00:00.003 | 2022-04-25T16:17:21 | 1970-01-01T00:00:00.009 | 1970-01-01T00:00:00.030 | 2022-04-25T16:17:21 | 1970-01-01T00:00:00.090 |", - "+-------------------------+---------------------+-------------------------+-------------------------+---------------------+-------------------------+", - ]; + "+-------------------------+---------------------+-------------------------+-------------------------+---------------------+-------------------------+"]; // The output order is important as SMJ preserves sortedness assert_batches_eq!(expected, &batches); Ok(()) @@ -2091,7 +2087,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Left).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", @@ -2127,7 +2123,7 @@ mod tests { )]; let (_, batches) = join_collect(left, right, on, JoinType::Right).await?; - let expected = vec![ + let expected = [ "+----+----+----+----+----+----+", "| a1 | b1 | c1 | a2 | b2 | c2 |", "+----+----+----+----+----+----+", diff --git a/datafusion/core/src/physical_plan/joins/utils.rs b/datafusion/core/src/physical_plan/joins/utils.rs index 3842d7d7ea196..bd3de1acbf0fd 100644 --- a/datafusion/core/src/physical_plan/joins/utils.rs +++ b/datafusion/core/src/physical_plan/joins/utils.rs @@ -881,7 +881,7 @@ fn estimate_join_cardinality( // filter selectivity analysis first. column_statistics: all_left_col_stats .into_iter() - .chain(all_right_col_stats.into_iter()) + .chain(all_right_col_stats) .collect(), }) } diff --git a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs index 006133eb4830c..27c1f79db5bc3 100644 --- a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs +++ b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs @@ -910,7 +910,7 @@ mod tests { let merge = Arc::new(SortPreservingMergeExec::new(sort, Arc::new(exec))); let collected = collect(merge.clone(), task_ctx).await.unwrap(); - let expected = vec![ + let expected = [ "+----+---+", "| a | b |", "+----+---+", diff --git a/datafusion/core/src/physical_plan/windows/bounded_window_agg_exec.rs b/datafusion/core/src/physical_plan/windows/bounded_window_agg_exec.rs index 2b4df9e9e4d3a..92e66783dc578 100644 --- a/datafusion/core/src/physical_plan/windows/bounded_window_agg_exec.rs +++ b/datafusion/core/src/physical_plan/windows/bounded_window_agg_exec.rs @@ -950,7 +950,7 @@ impl BoundedWindowAggStream { .columns() .iter() .map(|elem| elem.slice(0, n_out)) - .chain(window_expr_out.into_iter()) + .chain(window_expr_out) .collect::>(); let n_generated = columns_to_show[0].len(); self.prune_state(n_generated)?; diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs index d0759d3b8d05e..ffb9039b2a642 100644 --- a/datafusion/core/src/physical_planner.rs +++ b/datafusion/core/src/physical_planner.rs @@ -779,7 +779,7 @@ impl DefaultPhysicalPlanner { }) .collect::>>()?; - let (aggregates, filters, order_bys) : (Vec<_>, Vec<_>, Vec<_>) = multiunzip(agg_filter.into_iter()); + let (aggregates, filters, order_bys) : (Vec<_>, Vec<_>, Vec<_>) = multiunzip(agg_filter); let initial_aggr = Arc::new(AggregateExec::try_new( AggregateMode::Partial, @@ -2690,7 +2690,7 @@ mod tests { let plan = plan(&logical_plan).await.unwrap(); - let expected_graph = r###" + let expected_graph = r#" // Begin DataFusion GraphViz Plan, // display it online here: https://dreampuf.github.io/GraphvizOnline @@ -2700,7 +2700,7 @@ digraph { 1 -> 2 [arrowhead=none, arrowtail=normal, dir=back] } // End DataFusion GraphViz Plan -"###; +"#; let generated_graph = format!("{}", displayable(&*plan).graphviz()); diff --git a/datafusion/core/src/test_util/mod.rs b/datafusion/core/src/test_util/mod.rs index 5b47c711fb64c..ab29cecbb8eaa 100644 --- a/datafusion/core/src/test_util/mod.rs +++ b/datafusion/core/src/test_util/mod.rs @@ -157,9 +157,7 @@ pub fn scan_empty_with_partitions( /// Get the schema for the aggregate_test_* csv files pub fn aggr_test_schema() -> SchemaRef { let mut f1 = Field::new("c1", DataType::Utf8, false); - f1.set_metadata(HashMap::from_iter( - vec![("testing".into(), "test".into())].into_iter(), - )); + f1.set_metadata(HashMap::from_iter(vec![("testing".into(), "test".into())])); let schema = Schema::new(vec![ f1, Field::new("c2", DataType::UInt32, false), diff --git a/datafusion/core/tests/dataframe/dataframe_functions.rs b/datafusion/core/tests/dataframe/dataframe_functions.rs index fb10caf1b07d6..9677003ec226f 100644 --- a/datafusion/core/tests/dataframe/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe/dataframe_functions.rs @@ -80,7 +80,7 @@ macro_rules! assert_fn_batches { async fn test_fn_ascii() -> Result<()> { let expr = ascii(col("a")); - let expected = vec![ + let expected = [ "+---------------+", "| ascii(test.a) |", "+---------------+", @@ -97,7 +97,7 @@ async fn test_fn_ascii() -> Result<()> { async fn test_fn_bit_length() -> Result<()> { let expr = bit_length(col("a")); - let expected = vec![ + let expected = [ "+--------------------+", "| bit_length(test.a) |", "+--------------------+", @@ -116,7 +116,7 @@ async fn test_fn_bit_length() -> Result<()> { async fn test_fn_btrim() -> Result<()> { let expr = btrim(vec![lit(" a b c ")]); - let expected = vec![ + let expected = [ "+-----------------------------------------+", "| btrim(Utf8(\" a b c \")) |", "+-----------------------------------------+", @@ -133,7 +133,7 @@ async fn test_fn_btrim() -> Result<()> { async fn test_fn_btrim_with_chars() -> Result<()> { let expr = btrim(vec![col("a"), lit("ab")]); - let expected = vec![ + let expected = [ "+--------------------------+", "| btrim(test.a,Utf8(\"ab\")) |", "+--------------------------+", @@ -153,7 +153,7 @@ async fn test_fn_btrim_with_chars() -> Result<()> { async fn test_fn_approx_median() -> Result<()> { let expr = approx_median(col("b")); - let expected = vec![ + let expected = [ "+-----------------------+", "| APPROX_MEDIAN(test.b) |", "+-----------------------+", @@ -173,7 +173,7 @@ async fn test_fn_approx_median() -> Result<()> { async fn test_fn_approx_percentile_cont() -> Result<()> { let expr = approx_percentile_cont(col("b"), lit(0.5)); - let expected = vec![ + let expected = [ "+---------------------------------------------+", "| APPROX_PERCENTILE_CONT(test.b,Float64(0.5)) |", "+---------------------------------------------+", @@ -194,7 +194,7 @@ async fn test_fn_approx_percentile_cont() -> Result<()> { async fn test_fn_character_length() -> Result<()> { let expr = character_length(col("a")); - let expected = vec![ + let expected = [ "+--------------------------+", "| character_length(test.a) |", "+--------------------------+", @@ -214,7 +214,7 @@ async fn test_fn_character_length() -> Result<()> { async fn test_fn_chr() -> Result<()> { let expr = chr(lit(128175)); - let expected = vec![ + let expected = [ "+--------------------+", "| chr(Int32(128175)) |", "+--------------------+", @@ -231,7 +231,7 @@ async fn test_fn_chr() -> Result<()> { async fn test_fn_initcap() -> Result<()> { let expr = initcap(col("a")); - let expected = vec![ + let expected = [ "+-----------------+", "| initcap(test.a) |", "+-----------------+", @@ -252,7 +252,7 @@ async fn test_fn_initcap() -> Result<()> { async fn test_fn_left() -> Result<()> { let expr = left(col("a"), lit(3)); - let expected = vec![ + let expected = [ "+-----------------------+", "| left(test.a,Int32(3)) |", "+-----------------------+", @@ -272,7 +272,7 @@ async fn test_fn_left() -> Result<()> { async fn test_fn_lower() -> Result<()> { let expr = lower(col("a")); - let expected = vec![ + let expected = [ "+---------------+", "| lower(test.a) |", "+---------------+", @@ -293,7 +293,7 @@ async fn test_fn_lower() -> Result<()> { async fn test_fn_lpad() -> Result<()> { let expr = lpad(vec![col("a"), lit(10)]); - let expected = vec![ + let expected = [ "+------------------------+", "| lpad(test.a,Int32(10)) |", "+------------------------+", @@ -314,7 +314,7 @@ async fn test_fn_lpad() -> Result<()> { async fn test_fn_lpad_with_string() -> Result<()> { let expr = lpad(vec![col("a"), lit(10), lit("*")]); - let expected = vec![ + let expected = [ "+----------------------------------+", "| lpad(test.a,Int32(10),Utf8(\"*\")) |", "+----------------------------------+", @@ -334,7 +334,7 @@ async fn test_fn_lpad_with_string() -> Result<()> { async fn test_fn_ltrim() -> Result<()> { let expr = ltrim(lit(" a b c ")); - let expected = vec![ + let expected = [ "+-----------------------------------------+", "| ltrim(Utf8(\" a b c \")) |", "+-----------------------------------------+", @@ -351,7 +351,7 @@ async fn test_fn_ltrim() -> Result<()> { async fn test_fn_ltrim_with_columns() -> Result<()> { let expr = ltrim(col("a")); - let expected = vec![ + let expected = [ "+---------------+", "| ltrim(test.a) |", "+---------------+", @@ -372,7 +372,7 @@ async fn test_fn_ltrim_with_columns() -> Result<()> { async fn test_fn_md5() -> Result<()> { let expr = md5(col("a")); - let expected = vec![ + let expected = [ "+----------------------------------+", "| md5(test.a) |", "+----------------------------------+", @@ -393,7 +393,7 @@ async fn test_fn_md5() -> Result<()> { async fn test_fn_regexp_match() -> Result<()> { let expr = regexp_match(vec![col("a"), lit("[a-z]")]); - let expected = vec![ + let expected = [ "+------------------------------------+", "| regexp_match(test.a,Utf8(\"[a-z]\")) |", "+------------------------------------+", @@ -414,7 +414,7 @@ async fn test_fn_regexp_match() -> Result<()> { async fn test_fn_regexp_replace() -> Result<()> { let expr = regexp_replace(vec![col("a"), lit("[a-z]"), lit("x"), lit("g")]); - let expected = vec![ + let expected = [ "+----------------------------------------------------------+", "| regexp_replace(test.a,Utf8(\"[a-z]\"),Utf8(\"x\"),Utf8(\"g\")) |", "+----------------------------------------------------------+", @@ -434,7 +434,7 @@ async fn test_fn_regexp_replace() -> Result<()> { async fn test_fn_replace() -> Result<()> { let expr = replace(col("a"), lit("abc"), lit("x")); - let expected = vec![ + let expected = [ "+---------------------------------------+", "| replace(test.a,Utf8(\"abc\"),Utf8(\"x\")) |", "+---------------------------------------+", @@ -454,7 +454,7 @@ async fn test_fn_replace() -> Result<()> { async fn test_fn_repeat() -> Result<()> { let expr = repeat(col("a"), lit(2)); - let expected = vec![ + let expected = [ "+-------------------------+", "| repeat(test.a,Int32(2)) |", "+-------------------------+", @@ -475,7 +475,7 @@ async fn test_fn_repeat() -> Result<()> { async fn test_fn_reverse() -> Result<()> { let expr = reverse(col("a")); - let expected = vec![ + let expected = [ "+-----------------+", "| reverse(test.a) |", "+-----------------+", @@ -496,7 +496,7 @@ async fn test_fn_reverse() -> Result<()> { async fn test_fn_right() -> Result<()> { let expr = right(col("a"), lit(3)); - let expected = vec![ + let expected = [ "+------------------------+", "| right(test.a,Int32(3)) |", "+------------------------+", @@ -517,7 +517,7 @@ async fn test_fn_right() -> Result<()> { async fn test_fn_rpad() -> Result<()> { let expr = rpad(vec![col("a"), lit(11)]); - let expected = vec![ + let expected = [ "+------------------------+", "| rpad(test.a,Int32(11)) |", "+------------------------+", @@ -538,7 +538,7 @@ async fn test_fn_rpad() -> Result<()> { async fn test_fn_rpad_with_characters() -> Result<()> { let expr = rpad(vec![col("a"), lit(11), lit("x")]); - let expected = vec![ + let expected = [ "+----------------------------------+", "| rpad(test.a,Int32(11),Utf8(\"x\")) |", "+----------------------------------+", @@ -559,7 +559,7 @@ async fn test_fn_rpad_with_characters() -> Result<()> { async fn test_fn_sha224() -> Result<()> { let expr = sha224(col("a")); - let expected = vec![ + let expected = [ "+----------------------------------------------------------+", "| sha224(test.a) |", "+----------------------------------------------------------+", @@ -579,7 +579,7 @@ async fn test_fn_sha224() -> Result<()> { async fn test_fn_split_part() -> Result<()> { let expr = split_part(col("a"), lit("b"), lit(1)); - let expected = vec![ + let expected = [ "+---------------------------------------+", "| split_part(test.a,Utf8(\"b\"),Int32(1)) |", "+---------------------------------------+", @@ -598,7 +598,7 @@ async fn test_fn_split_part() -> Result<()> { async fn test_fn_starts_with() -> Result<()> { let expr = starts_with(col("a"), lit("abc")); - let expected = vec![ + let expected = [ "+---------------------------------+", "| starts_with(test.a,Utf8(\"abc\")) |", "+---------------------------------+", @@ -619,7 +619,7 @@ async fn test_fn_starts_with() -> Result<()> { async fn test_fn_strpos() -> Result<()> { let expr = strpos(col("a"), lit("f")); - let expected = vec![ + let expected = [ "+--------------------------+", "| strpos(test.a,Utf8(\"f\")) |", "+--------------------------+", @@ -639,7 +639,7 @@ async fn test_fn_strpos() -> Result<()> { async fn test_fn_substr() -> Result<()> { let expr = substr(col("a"), lit(2)); - let expected = vec![ + let expected = [ "+-------------------------+", "| substr(test.a,Int32(2)) |", "+-------------------------+", @@ -657,7 +657,7 @@ async fn test_fn_substr() -> Result<()> { #[tokio::test] async fn test_cast() -> Result<()> { let expr = cast(col("b"), DataType::Float64); - let expected = vec![ + let expected = [ "+--------+", "| test.b |", "+--------+", @@ -677,7 +677,7 @@ async fn test_cast() -> Result<()> { async fn test_fn_to_hex() -> Result<()> { let expr = to_hex(col("b")); - let expected = vec![ + let expected = [ "+----------------+", "| to_hex(test.b) |", "+----------------+", @@ -697,7 +697,7 @@ async fn test_fn_to_hex() -> Result<()> { async fn test_fn_translate() -> Result<()> { let expr = translate(col("a"), lit("bc"), lit("xx")); - let expected = vec![ + let expected = [ "+-----------------------------------------+", "| translate(test.a,Utf8(\"bc\"),Utf8(\"xx\")) |", "+-----------------------------------------+", @@ -716,7 +716,7 @@ async fn test_fn_translate() -> Result<()> { async fn test_fn_upper() -> Result<()> { let expr = upper(col("a")); - let expected = vec![ + let expected = [ "+---------------+", "| upper(test.a) |", "+---------------+", diff --git a/datafusion/core/tests/dataframe/mod.rs b/datafusion/core/tests/dataframe/mod.rs index 73cba35d70d40..bda6e5d929197 100644 --- a/datafusion/core/tests/dataframe/mod.rs +++ b/datafusion/core/tests/dataframe/mod.rs @@ -287,8 +287,7 @@ async fn describe() -> Result<()> { .await?; #[rustfmt::skip] - let expected = vec![ - "+------------+-------------------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----------------+------------+-------------------------+--------------------+-------------------+", + let expected = ["+------------+-------------------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----------------+------------+-------------------------+--------------------+-------------------+", "| describe | id | bool_col | tinyint_col | smallint_col | int_col | bigint_col | float_col | double_col | date_string_col | string_col | timestamp_col | year | month |", "+------------+-------------------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----------------+------------+-------------------------+--------------------+-------------------+", "| count | 7300.0 | 7300 | 7300.0 | 7300.0 | 7300.0 | 7300.0 | 7300.0 | 7300.0 | 7300 | 7300 | 7300 | 7300.0 | 7300.0 |", @@ -298,8 +297,7 @@ async fn describe() -> Result<()> { "| min | 0.0 | null | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 01/01/09 | 0 | 2008-12-31T23:00:00 | 2009.0 | 1.0 |", "| max | 7299.0 | null | 9.0 | 9.0 | 9.0 | 90.0 | 9.899999618530273 | 90.89999999999999 | 12/31/10 | 9 | 2010-12-31T04:09:13.860 | 2010.0 | 12.0 |", "| median | 3649.0 | null | 4.0 | 4.0 | 4.0 | 45.0 | 4.949999809265137 | 45.45 | null | null | null | 2009.0 | 7.0 |", - "+------------+-------------------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----------------+------------+-------------------------+--------------------+-------------------+", - ]; + "+------------+-------------------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----------------+------------+-------------------------+--------------------+-------------------+"]; assert_batches_eq!(expected, &describe_record_batch); //add test case for only boolean boolean/binary column @@ -311,8 +309,7 @@ async fn describe() -> Result<()> { .collect() .await?; #[rustfmt::skip] - let expected = vec![ - "+------------+------+------+", + let expected = ["+------------+------+------+", "| describe | a | b |", "+------------+------+------+", "| count | 1 | 1 |", @@ -322,8 +319,7 @@ async fn describe() -> Result<()> { "| min | a | null |", "| max | a | null |", "| median | null | null |", - "+------------+------+------+", - ]; + "+------------+------+------+"]; assert_batches_eq!(expected, &result); Ok(()) @@ -406,16 +402,14 @@ async fn sort_on_unprojected_columns() -> Result<()> { let results = df.collect().await.unwrap(); #[rustfmt::skip] - let expected = vec![ - "+-----+", + let expected = ["+-----+", "| a |", "+-----+", "| 100 |", "| 10 |", "| 10 |", "| 1 |", - "+-----+", - ]; + "+-----+"]; assert_batches_eq!(expected, &results); Ok(()) @@ -452,15 +446,13 @@ async fn sort_on_distinct_columns() -> Result<()> { let results = df.collect().await.unwrap(); #[rustfmt::skip] - let expected = vec![ - "+-----+", + let expected = ["+-----+", "| a |", "+-----+", "| 100 |", "| 10 |", "| 1 |", - "+-----+", - ]; + "+-----+"]; assert_batches_eq!(expected, &results); Ok(()) } @@ -594,14 +586,12 @@ async fn filter_with_alias_overwrite() -> Result<()> { let results = df.collect().await.unwrap(); #[rustfmt::skip] - let expected = vec![ - "+------+", + let expected = ["+------+", "| a |", "+------+", "| true |", "| true |", - "+------+", - ]; + "+------+"]; assert_batches_eq!(expected, &results); Ok(()) @@ -629,16 +619,14 @@ async fn select_with_alias_overwrite() -> Result<()> { let results = df.collect().await?; #[rustfmt::skip] - let expected = vec![ - "+-------+", + let expected = ["+-------+", "| a |", "+-------+", "| false |", "| true |", "| true |", "| false |", - "+-------+", - ]; + "+-------+"]; assert_batches_eq!(expected, &results); Ok(()) @@ -946,22 +934,20 @@ async fn unnest_columns() -> Result<()> { const NUM_ROWS: usize = 4; let df = table_with_nested_types(NUM_ROWS).await?; let results = df.collect().await?; - let expected = vec![ - "+----------+------------------------------------------------+--------------------+", + let expected = ["+----------+------------------------------------------------+--------------------+", "| shape_id | points | tags |", "+----------+------------------------------------------------+--------------------+", "| 1 | [{x: -3, y: -4}, {x: -3, y: 6}, {x: 2, y: -2}] | [tag1] |", "| 2 | | [tag1, tag2] |", "| 3 | [{x: -9, y: 2}, {x: -10, y: -4}] | |", "| 4 | [{x: -3, y: 5}, {x: 2, y: -1}] | [tag1, tag2, tag3] |", - "+----------+------------------------------------------------+--------------------+", - ]; + "+----------+------------------------------------------------+--------------------+"]; assert_batches_sorted_eq!(expected, &results); // Unnest tags let df = table_with_nested_types(NUM_ROWS).await?; let results = df.unnest_column("tags")?.collect().await?; - let expected = vec![ + let expected = [ "+----------+------------------------------------------------+------+", "| shape_id | points | tags |", "+----------+------------------------------------------------+------+", @@ -984,7 +970,7 @@ async fn unnest_columns() -> Result<()> { // Unnest points let df = table_with_nested_types(NUM_ROWS).await?; let results = df.unnest_column("points")?.collect().await?; - let expected = vec![ + let expected = [ "+----------+-----------------+--------------------+", "| shape_id | points | tags |", "+----------+-----------------+--------------------+", @@ -1049,7 +1035,7 @@ async fn unnest_columns() -> Result<()> { async fn unnest_column_nulls() -> Result<()> { let df = table_with_lists_and_nulls().await?; let results = df.clone().collect().await?; - let expected = vec![ + let expected = [ "+--------+----+", "| list | id |", "+--------+----+", @@ -1069,7 +1055,7 @@ async fn unnest_column_nulls() -> Result<()> { .unnest_column_with_options("list", options)? .collect() .await?; - let expected = vec![ + let expected = [ "+------+----+", "| list | id |", "+------+----+", @@ -1086,7 +1072,7 @@ async fn unnest_column_nulls() -> Result<()> { .unnest_column_with_options("list", options)? .collect() .await?; - let expected = vec![ + let expected = [ "+------+----+", "| list | id |", "+------+----+", @@ -1109,7 +1095,7 @@ async fn unnest_fixed_list() -> Result<()> { let df = ctx.table("shapes").await?; let results = df.clone().collect().await?; - let expected = vec![ + let expected = [ "+----------+----------------+", "| shape_id | tags |", "+----------+----------------+", @@ -1159,7 +1145,7 @@ async fn unnest_fixed_list_drop_nulls() -> Result<()> { let df = ctx.table("shapes").await?; let results = df.clone().collect().await?; - let expected = vec![ + let expected = [ "+----------+----------------+", "| shape_id | tags |", "+----------+----------------+", @@ -1179,7 +1165,7 @@ async fn unnest_fixed_list_drop_nulls() -> Result<()> { .unnest_column_with_options("tags", options)? .collect() .await?; - let expected = vec![ + let expected = [ "+----------+-------+", "| shape_id | tags |", "+----------+-------+", @@ -1226,7 +1212,7 @@ async fn unnest_fixed_list_nonull() -> Result<()> { let df = ctx.table("shapes").await?; let results = df.clone().collect().await?; - let expected = vec![ + let expected = [ "+----------+----------------+", "| shape_id | tags |", "+----------+----------------+", @@ -1274,7 +1260,7 @@ async fn unnest_aggregate_columns() -> Result<()> { let df = table_with_nested_types(NUM_ROWS).await?; let results = df.select_columns(&["tags"])?.collect().await?; - let expected = vec![ + let expected = [ r#"+--------------------+"#, r#"| tags |"#, r#"+--------------------+"#, @@ -1293,7 +1279,7 @@ async fn unnest_aggregate_columns() -> Result<()> { .aggregate(vec![], vec![count(col("tags"))])? .collect() .await?; - let expected = vec![ + let expected = [ r#"+--------------------+"#, r#"| COUNT(shapes.tags) |"#, r#"+--------------------+"#, @@ -1353,7 +1339,7 @@ async fn unnest_array_agg() -> Result<()> { )? .collect() .await?; - let expected = vec![ + let expected = [ "+----------+--------------+", "| shape_id | tag_id |", "+----------+--------------+", @@ -1658,7 +1644,7 @@ async fn test_array_agg() -> Result<()> { let results = df.collect().await?; - let expected = vec![ + let expected = [ "+-------------------------------------+", "| ARRAY_AGG(test.a) |", "+-------------------------------------+", diff --git a/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs b/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs index bdca1f90687d9..a0e9a50a22aee 100644 --- a/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs +++ b/datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs @@ -211,7 +211,7 @@ pub(crate) fn make_staggered_batches( let input1 = Int64Array::from_iter_values(input123.clone().into_iter().map(|k| k.0)); let input2 = Int64Array::from_iter_values(input123.clone().into_iter().map(|k| k.1)); let input3 = Int64Array::from_iter_values(input123.clone().into_iter().map(|k| k.2)); - let input4 = Int64Array::from_iter_values(input4.into_iter()); + let input4 = Int64Array::from_iter_values(input4); // split into several record batches let mut remainder = RecordBatch::try_from_iter(vec![ diff --git a/datafusion/core/tests/fuzz_cases/join_fuzz.rs b/datafusion/core/tests/fuzz_cases/join_fuzz.rs index 48e3da1886782..9b741440ff136 100644 --- a/datafusion/core/tests/fuzz_cases/join_fuzz.rs +++ b/datafusion/core/tests/fuzz_cases/join_fuzz.rs @@ -195,8 +195,8 @@ fn make_staggered_batches(len: usize) -> Vec { input12.sort_unstable(); let input1 = Int32Array::from_iter_values(input12.clone().into_iter().map(|k| k.0)); let input2 = Int32Array::from_iter_values(input12.clone().into_iter().map(|k| k.1)); - let input3 = Int32Array::from_iter_values(input3.into_iter()); - let input4 = Int32Array::from_iter_values(input4.into_iter()); + let input3 = Int32Array::from_iter_values(input3); + let input4 = Int32Array::from_iter_values(input4); // split into several record batches let batch = RecordBatch::try_from_iter(vec![ diff --git a/datafusion/core/tests/fuzz_cases/window_fuzz.rs b/datafusion/core/tests/fuzz_cases/window_fuzz.rs index 1d9c4a9d0259b..3d103ee70ee8e 100644 --- a/datafusion/core/tests/fuzz_cases/window_fuzz.rs +++ b/datafusion/core/tests/fuzz_cases/window_fuzz.rs @@ -550,7 +550,7 @@ fn make_staggered_batches( let input1 = Int32Array::from_iter_values(input123.iter().map(|k| k.0)); let input2 = Int32Array::from_iter_values(input123.iter().map(|k| k.1)); let input3 = Int32Array::from_iter_values(input123.iter().map(|k| k.2)); - let input4 = Int32Array::from_iter_values(input4.into_iter()); + let input4 = Int32Array::from_iter_values(input4); // split into several record batches let mut remainder = RecordBatch::try_from_iter(vec![ diff --git a/datafusion/core/tests/parquet/custom_reader.rs b/datafusion/core/tests/parquet/custom_reader.rs index 7d73b4a618818..75ff56a26508e 100644 --- a/datafusion/core/tests/parquet/custom_reader.rs +++ b/datafusion/core/tests/parquet/custom_reader.rs @@ -96,7 +96,7 @@ async fn route_data_access_ops_to_parquet_file_reader_factory() { let task_ctx = session_ctx.task_ctx(); let read = collect(Arc::new(parquet_exec), task_ctx).await.unwrap(); - let expected = vec![ + let expected = [ "+-----+----+----+", "| c1 | c2 | c3 |", "+-----+----+----+", diff --git a/datafusion/core/tests/parquet/schema_coercion.rs b/datafusion/core/tests/parquet/schema_coercion.rs index 4d028c6f1b31d..f7dace9930917 100644 --- a/datafusion/core/tests/parquet/schema_coercion.rs +++ b/datafusion/core/tests/parquet/schema_coercion.rs @@ -78,7 +78,7 @@ async fn multi_parquet_coercion() { let task_ctx = session_ctx.task_ctx(); let read = collect(Arc::new(parquet_exec), task_ctx).await.unwrap(); - let expected = vec![ + let expected = [ "+-------+----+------+", "| c1 | c2 | c3 |", "+-------+----+------+", @@ -142,7 +142,7 @@ async fn multi_parquet_coercion_projection() { let task_ctx = session_ctx.task_ctx(); let read = collect(Arc::new(parquet_exec), task_ctx).await.unwrap(); - let expected = vec![ + let expected = [ "+----+-------+------+", "| c2 | c1 | c3 |", "+----+-------+------+", diff --git a/datafusion/core/tests/path_partition.rs b/datafusion/core/tests/path_partition.rs index d4aa6c7e82fd6..183752b340018 100644 --- a/datafusion/core/tests/path_partition.rs +++ b/datafusion/core/tests/path_partition.rs @@ -81,7 +81,7 @@ async fn parquet_distinct_partition_col() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+------+-------+-----+", "| year | month | day |", "+------+-------+-----+", @@ -217,7 +217,7 @@ async fn csv_filter_with_file_col() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+----+----+", "| c1 | c2 |", "+----+----+", @@ -253,7 +253,7 @@ async fn csv_filter_with_file_nonstring_col() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+----+----+------------+", "| c1 | c2 | date |", "+----+----+------------+", @@ -289,7 +289,7 @@ async fn csv_projection_on_partition() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+----+------------+", "| c1 | date |", "+----+------------+", @@ -326,7 +326,7 @@ async fn csv_grouping_by_partition() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+------------+----------+----------------------+", "| date | COUNT(*) | COUNT(DISTINCT t.c1) |", "+------------+----------+----------------------+", @@ -366,7 +366,7 @@ async fn parquet_multiple_partitions() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+----+-----+", "| id | day |", "+----+-----+", @@ -412,7 +412,7 @@ async fn parquet_multiple_nonstring_partitions() -> Result<()> { .collect() .await?; - let expected = vec![ + let expected = [ "+----+-----+", "| id | day |", "+----+-----+", diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rs index 251063e396b60..5d42936232b59 100644 --- a/datafusion/core/tests/sql/aggregates.rs +++ b/datafusion/core/tests/sql/aggregates.rs @@ -75,7 +75,7 @@ async fn aggregate() -> Result<()> { let results = execute_with_partition("SELECT SUM(c1), SUM(c2) FROM test", 4).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+", "| SUM(test.c1) | SUM(test.c2) |", "+--------------+--------------+", @@ -97,7 +97,7 @@ async fn aggregate_empty() -> Result<()> { assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+", "| SUM(test.c1) | SUM(test.c2) |", "+--------------+--------------+", @@ -114,7 +114,7 @@ async fn aggregate_avg() -> Result<()> { let results = execute_with_partition("SELECT AVG(c1), AVG(c2) FROM test", 4).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+", "| AVG(test.c1) | AVG(test.c2) |", "+--------------+--------------+", @@ -131,7 +131,7 @@ async fn aggregate_max() -> Result<()> { let results = execute_with_partition("SELECT MAX(c1), MAX(c2) FROM test", 4).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+", "| MAX(test.c1) | MAX(test.c2) |", "+--------------+--------------+", @@ -148,7 +148,7 @@ async fn aggregate_min() -> Result<()> { let results = execute_with_partition("SELECT MIN(c1), MIN(c2) FROM test", 4).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+--------------+--------------+", "| MIN(test.c1) | MIN(test.c2) |", "+--------------+--------------+", @@ -165,7 +165,7 @@ async fn aggregate_grouped() -> Result<()> { let results = execute_with_partition("SELECT c1, SUM(c2) FROM test GROUP BY c1", 4).await?; - let expected = vec![ + let expected = [ "+----+--------------+", "| c1 | SUM(test.c2) |", "+----+--------------+", @@ -185,7 +185,7 @@ async fn aggregate_grouped_avg() -> Result<()> { let results = execute_with_partition("SELECT c1, AVG(c2) FROM test GROUP BY c1", 4).await?; - let expected = vec![ + let expected = [ "+----+--------------+", "| c1 | AVG(test.c2) |", "+----+--------------+", @@ -208,7 +208,7 @@ async fn aggregate_grouped_empty() -> Result<()> { ) .await?; - let expected = vec![ + let expected = [ "+----+--------------+", "| c1 | AVG(test.c2) |", "+----+--------------+", @@ -224,7 +224,7 @@ async fn aggregate_grouped_max() -> Result<()> { let results = execute_with_partition("SELECT c1, MAX(c2) FROM test GROUP BY c1", 4).await?; - let expected = vec![ + let expected = [ "+----+--------------+", "| c1 | MAX(test.c2) |", "+----+--------------+", @@ -244,7 +244,7 @@ async fn aggregate_grouped_min() -> Result<()> { let results = execute_with_partition("SELECT c1, MIN(c2) FROM test GROUP BY c1", 4).await?; - let expected = vec![ + let expected = [ "+----+--------------+", "| c1 | MIN(test.c2) |", "+----+--------------+", @@ -271,7 +271,7 @@ async fn aggregate_min_max_w_custom_window_frames() -> Result<()> { ORDER BY C9 LIMIT 5"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+---------------------+--------------------+", "| min1 | max1 |", "+---------------------+--------------------+", @@ -298,7 +298,7 @@ async fn aggregate_min_max_w_custom_window_frames_unbounded_start() -> Result<() ORDER BY C9 LIMIT 5"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+---------------------+--------------------+", "| min1 | max1 |", "+---------------------+--------------------+", @@ -322,13 +322,11 @@ async fn aggregate_avg_add() -> Result<()> { .await?; assert_eq!(results.len(), 1); - let expected = vec![ - "+--------------+-------------------------+-------------------------+-------------------------+", + let expected = ["+--------------+-------------------------+-------------------------+-------------------------+", "| AVG(test.c1) | AVG(test.c1) + Int64(1) | AVG(test.c1) + Int64(2) | Int64(1) + AVG(test.c1) |", "+--------------+-------------------------+-------------------------+-------------------------+", "| 1.5 | 2.5 | 3.5 | 2.5 |", - "+--------------+-------------------------+-------------------------+-------------------------+", - ]; + "+--------------+-------------------------+-------------------------+-------------------------+"]; assert_batches_sorted_eq!(expected, &results); Ok(()) @@ -340,7 +338,7 @@ async fn case_sensitive_identifiers_aggregates() { ctx.register_table("t", table_with_sequence(1, 1).unwrap()) .unwrap(); - let expected = vec![ + let expected = [ "+----------+", "| MAX(t.i) |", "+----------+", @@ -379,7 +377,7 @@ async fn count_basic() -> Result<()> { execute_with_partition("SELECT COUNT(c1), COUNT(c2) FROM test", 1).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+----------------+----------------+", "| COUNT(test.c1) | COUNT(test.c2) |", "+----------------+----------------+", @@ -396,7 +394,7 @@ async fn count_partitioned() -> Result<()> { execute_with_partition("SELECT COUNT(c1), COUNT(c2) FROM test", 4).await?; assert_eq!(results.len(), 1); - let expected = vec![ + let expected = [ "+----------------+----------------+", "| COUNT(test.c1) | COUNT(test.c2) |", "+----------------+----------------+", @@ -412,7 +410,7 @@ async fn count_aggregated() -> Result<()> { let results = execute_with_partition("SELECT c1, COUNT(c2) FROM test GROUP BY c1", 4).await?; - let expected = vec![ + let expected = [ "+----+----------------+", "| c1 | COUNT(test.c2) |", "+----+----------------+", @@ -531,7 +529,7 @@ async fn count_multi_expr() -> Result<()> { let sql = "SELECT count(c1, c2) FROM test"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+------------------------+", "| COUNT(test.c1,test.c2) |", "+------------------------+", @@ -582,7 +580,7 @@ async fn count_multi_expr_group_by() -> Result<()> { let sql = "SELECT c3, count(c1, c2) FROM test group by c3"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----+------------------------+", "| c3 | COUNT(test.c1,test.c2) |", "+----+------------------------+", @@ -739,15 +737,13 @@ async fn count_distinct_integers_aggregated_single_partition() -> Result<()> { let results = run_count_distinct_integers_aggregated_scenario(partitions).await?; - let expected = vec![ - "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", + let expected = ["+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", "| c_group | COUNT(test.c_uint64) | COUNT(DISTINCT test.c_int8) | COUNT(DISTINCT test.c_int16) | COUNT(DISTINCT test.c_int32) | COUNT(DISTINCT test.c_int64) | COUNT(DISTINCT test.c_uint8) | COUNT(DISTINCT test.c_uint16) | COUNT(DISTINCT test.c_uint32) | COUNT(DISTINCT test.c_uint64) |", "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", "| a | 3 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |", "| b | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |", "| c | 3 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |", - "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", - ]; + "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+"]; assert_batches_sorted_eq!(expected, &results); Ok(()) @@ -765,15 +761,13 @@ async fn count_distinct_integers_aggregated_multiple_partitions() -> Result<()> let results = run_count_distinct_integers_aggregated_scenario(partitions).await?; - let expected = vec![ - "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", + let expected = ["+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", "| c_group | COUNT(test.c_uint64) | COUNT(DISTINCT test.c_int8) | COUNT(DISTINCT test.c_int16) | COUNT(DISTINCT test.c_int32) | COUNT(DISTINCT test.c_int64) | COUNT(DISTINCT test.c_uint8) | COUNT(DISTINCT test.c_uint16) | COUNT(DISTINCT test.c_uint32) | COUNT(DISTINCT test.c_uint64) |", "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", "| a | 5 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |", "| b | 5 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 |", "| c | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |", - "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+", - ]; + "+---------+----------------------+-----------------------------+------------------------------+------------------------------+------------------------------+------------------------------+-------------------------------+-------------------------------+-------------------------------+"]; assert_batches_sorted_eq!(expected, &results); Ok(()) @@ -817,8 +811,7 @@ async fn test_accumulator_row_accumulator() -> Result<()> { LIMIT 5"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----+----+--------------------------------+-----------+--------------------------------+------------+--------------------+--------------------------------+------+--------------+", + let expected = ["+----+----+--------------------------------+-----------+--------------------------------+------------+--------------------+--------------------------------+------+--------------+", "| c1 | c2 | min1 | min2 | max1 | max2 | avg1 | min3 | cnt1 | sum1 |", "+----+----+--------------------------------+-----------+--------------------------------+------------+--------------------+--------------------------------+------+--------------+", "| a | 1 | 0keZ5G8BffGwgF2RwQD59TFzMStxCB | 774637006 | waIGbOGl1PM6gnzZ4uuZt4E2yDWRHs | 4015442341 | 2437927011.0 | 0keZ5G8BffGwgF2RwQD59TFzMStxCB | 5 | 6094771121.5 |", @@ -826,8 +819,7 @@ async fn test_accumulator_row_accumulator() -> Result<()> { "| a | 3 | Amn2K87Db5Es3dFQO9cw9cvpAM6h35 | 431948861 | oLZ21P2JEDooxV1pU31cIxQHEeeoLu | 3998790955 | 2225685115.1666665 | Amn2K87Db5Es3dFQO9cw9cvpAM6h35 | 6 | 6676994872.5 |", "| a | 4 | KJFcmTVjdkCMv94wYCtfHMFhzyRsmH | 466439833 | ydkwycaISlYSlEq3TlkS2m15I2pcp8 | 2502326480 | 1655431654.0 | KJFcmTVjdkCMv94wYCtfHMFhzyRsmH | 4 | 3310812222.5 |", "| a | 5 | MeSTAXq8gVxVjbEjgkvU9YLte0X9uE | 141047417 | QJYm7YRA3YetcBHI5wkMZeLXVmfuNy | 2496054700 | 1216992989.6666667 | MeSTAXq8gVxVjbEjgkvU9YLte0X9uE | 3 | 1825431770.0 |", - "+----+----+--------------------------------+-----------+--------------------------------+------------+--------------------+--------------------------------+------+--------------+", - ]; + "+----+----+--------------------------------+-----------+--------------------------------+------------+--------------------+--------------------------------+------+--------------+"]; assert_batches_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/arrow_files.rs b/datafusion/core/tests/sql/arrow_files.rs index e74294b312904..fc90fe3c34640 100644 --- a/datafusion/core/tests/sql/arrow_files.rs +++ b/datafusion/core/tests/sql/arrow_files.rs @@ -34,7 +34,7 @@ async fn arrow_query() { register_arrow(&mut ctx).await; let sql = "SELECT * FROM arrow_simple"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----+-----+-------+", "| f0 | f1 | f2 |", "+----+-----+-------+", diff --git a/datafusion/core/tests/sql/expr.rs b/datafusion/core/tests/sql/expr.rs index b88a0d8df1287..2cc61b1fdd095 100644 --- a/datafusion/core/tests/sql/expr.rs +++ b/datafusion/core/tests/sql/expr.rs @@ -908,13 +908,11 @@ async fn nested_subquery() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; // the purpose of this test is just to make sure the query produces a valid plan #[rustfmt::skip] - let expected = vec![ - "+-----+", + let expected = ["+-----+", "| cnt |", "+-----+", "| 0 |", - "+-----+" - ]; + "+-----+"]; assert_batches_eq!(expected, &actual); Ok(()) } diff --git a/datafusion/core/tests/sql/group_by.rs b/datafusion/core/tests/sql/group_by.rs index b4a92db3fc371..ebb8fca930cdf 100644 --- a/datafusion/core/tests/sql/group_by.rs +++ b/datafusion/core/tests/sql/group_by.rs @@ -55,7 +55,7 @@ async fn group_by_date_trunc() -> Result<()> { "SELECT date_trunc('week', t1) as week, SUM(c2) FROM test GROUP BY date_trunc('week', t1)", ).await?; - let expected = vec![ + let expected = [ "+---------------------+--------------+", "| week | SUM(test.c2) |", "+---------------------+--------------+", @@ -103,7 +103,7 @@ async fn group_by_dictionary() { .await .expect("ran plan correctly"); - let expected = vec![ + let expected = [ "+------+--------------+", "| dict | COUNT(t.val) |", "+------+--------------+", @@ -120,7 +120,7 @@ async fn group_by_dictionary() { .await .expect("ran plan correctly"); - let expected = vec![ + let expected = [ "+-----+---------------+", "| val | COUNT(t.dict) |", "+-----+---------------+", @@ -139,7 +139,7 @@ async fn group_by_dictionary() { .await .expect("ran plan correctly"); - let expected = vec![ + let expected = [ "+-------+------------------------+", "| t.val | COUNT(DISTINCT t.dict) |", "+-------+------------------------+", diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs index e555a28f41fce..6ba8474ee1546 100644 --- a/datafusion/core/tests/sql/joins.rs +++ b/datafusion/core/tests/sql/joins.rs @@ -25,7 +25,7 @@ use super::*; async fn nestedjoin_with_alias() -> Result<()> { // repro case for https://github.com/apache/arrow-datafusion/issues/2867 let sql = "select * from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;"; - let expected = vec![ + let expected = [ "+---+---+---+---+", "| a | b | a | d |", "+---+---+---+---+", @@ -71,7 +71,7 @@ async fn null_aware_left_anti_join() -> Result<()> { let sql = "SELECT t1_id, t1_name FROM t1 WHERE t1_id NOT IN (SELECT t2_id FROM t2) ORDER BY t1_id"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec!["++", "++"]; + let expected = ["++", "++"]; assert_batches_eq!(expected, &actual); } diff --git a/datafusion/core/tests/sql/limit.rs b/datafusion/core/tests/sql/limit.rs index a4247492b4158..1c8ea4fd3468c 100644 --- a/datafusion/core/tests/sql/limit.rs +++ b/datafusion/core/tests/sql/limit.rs @@ -29,15 +29,13 @@ async fn limit() -> Result<()> { .unwrap(); #[rustfmt::skip] - let expected = vec![ - "+------+", + let expected = ["+------+", "| i |", "+------+", "| 1000 |", "| 999 |", "| 998 |", - "+------+", - ]; + "+------+"]; assert_batches_eq!(expected, &results); @@ -46,15 +44,13 @@ async fn limit() -> Result<()> { .unwrap(); #[rustfmt::skip] - let expected = vec![ - "+---+", + let expected = ["+---+", "| i |", "+---+", "| 1 |", "| 2 |", "| 3 |", - "+---+", - ]; + "+---+"]; assert_batches_eq!(expected, &results); diff --git a/datafusion/core/tests/sql/order.rs b/datafusion/core/tests/sql/order.rs index 3981fbaa4d7ab..d676ac731fd3a 100644 --- a/datafusion/core/tests/sql/order.rs +++ b/datafusion/core/tests/sql/order.rs @@ -48,7 +48,9 @@ async fn sort_with_lots_of_repetition_values() -> Result<()> { async fn create_external_table_with_order() -> Result<()> { let ctx = SessionContext::new(); let sql = "CREATE EXTERNAL TABLE dt (a_id integer, a_str string, a_bool boolean) STORED AS CSV WITH ORDER (a_id ASC) LOCATION 'file://path/to/table';"; - let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = ctx.state().create_logical_plan(sql).await? else { + let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = + ctx.state().create_logical_plan(sql).await? + else { panic!("Wrong command") }; @@ -123,7 +125,7 @@ async fn sort_with_duplicate_sort_exprs() -> Result<()> { "\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n" ); - let expected = vec![ + let expected = [ "+----+------+", "| id | name |", "+----+------+", @@ -154,7 +156,7 @@ async fn sort_with_duplicate_sort_exprs() -> Result<()> { "\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n" ); - let expected = vec![ + let expected = [ "+----+------+", "| id | name |", "+----+------+", @@ -233,7 +235,7 @@ ORDER BY 1, 2; let actual = execute_to_batches(&ctx, sql).await; // in https://github.com/apache/arrow-datafusion/issues/5970 the order of the output was sometimes not right - let expected = vec![ + let expected = [ "+---+---+", "| m | t |", "+---+---+", diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rs index 907a2c9506727..c2844a2b762af 100644 --- a/datafusion/core/tests/sql/parquet.rs +++ b/datafusion/core/tests/sql/parquet.rs @@ -32,7 +32,7 @@ async fn parquet_query() { // so we need an explicit cast let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----+---------------------------+", "| id | alltypes_plain.string_col |", "+----+---------------------------+", @@ -335,7 +335,7 @@ async fn parquet_query_with_max_min() { let sql = "SELECT max(c1) FROM foo"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------+", "| MAX(foo.c1) |", "+-------------+", @@ -347,7 +347,7 @@ async fn parquet_query_with_max_min() { let sql = "SELECT min(c2) FROM foo"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------+", "| MIN(foo.c2) |", "+-------------+", @@ -359,7 +359,7 @@ async fn parquet_query_with_max_min() { let sql = "SELECT max(c3) FROM foo"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------+", "| MAX(foo.c3) |", "+-------------+", @@ -371,7 +371,7 @@ async fn parquet_query_with_max_min() { let sql = "SELECT min(c4) FROM foo"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------+", "| MIN(foo.c4) |", "+-------------+", diff --git a/datafusion/core/tests/sql/parquet_schema.rs b/datafusion/core/tests/sql/parquet_schema.rs index 1d96f2b1ff979..bc1578da2c58a 100644 --- a/datafusion/core/tests/sql/parquet_schema.rs +++ b/datafusion/core/tests/sql/parquet_schema.rs @@ -58,7 +58,7 @@ async fn schema_merge_ignores_metadata_by_default() { write_files(table_dir.as_path(), schemas); // can be any order - let expected = vec![ + let expected = [ "+----+------+", "| id | name |", "+----+------+", @@ -119,7 +119,7 @@ async fn schema_merge_can_preserve_metadata() { write_files(table_dir.as_path(), schemas); // can be any order - let expected = vec![ + let expected = [ "+----+------+", "| id | name |", "+----+------+", diff --git a/datafusion/core/tests/sql/predicates.rs b/datafusion/core/tests/sql/predicates.rs index 498952a808c46..fe735bf6b8282 100644 --- a/datafusion/core/tests/sql/predicates.rs +++ b/datafusion/core/tests/sql/predicates.rs @@ -34,7 +34,7 @@ async fn string_coercion() -> Result<()> { let ctx = SessionContext::new(); ctx.register_batch("t", batch)?; - let expected = vec![ + let expected = [ "+----------------+----------------+", "| vendor_id_utf8 | vendor_id_dict |", "+----------------+----------------+", @@ -175,13 +175,11 @@ where // assert data let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+-----------+-------------------------------+--------------------------+-------------------------------------+", + let expected = ["+-----------+-------------------------------+--------------------------+-------------------------------------+", "| p_partkey | SUM(lineitem.l_extendedprice) | AVG(lineitem.l_discount) | COUNT(DISTINCT partsupp.ps_suppkey) |", "+-----------+-------------------------------+--------------------------+-------------------------------------+", "| 63700 | 13309.60 | 0.100000 | 1 |", - "+-----------+-------------------------------+--------------------------+-------------------------------------+", - ]; + "+-----------+-------------------------------+--------------------------+-------------------------------------+"]; assert_batches_eq!(expected, &results); Ok(()) diff --git a/datafusion/core/tests/sql/projection.rs b/datafusion/core/tests/sql/projection.rs index a90cf1a2c202a..b31cb34f52108 100644 --- a/datafusion/core/tests/sql/projection.rs +++ b/datafusion/core/tests/sql/projection.rs @@ -30,13 +30,11 @@ async fn projection_same_fields() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; #[rustfmt::skip] - let expected = vec![ - "+---+", + let expected = ["+---+", "| a |", "+---+", "| 2 |", - "+---+" - ]; + "+---+"]; assert_batches_eq!(expected, &actual); Ok(()) @@ -52,7 +50,7 @@ async fn projection_type_alias() -> Result<()> { let sql = "SELECT c1 as c3 FROM aggregate_simple ORDER BY c3 LIMIT 2"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+---------+", "| c3 |", "+---------+", @@ -71,7 +69,7 @@ async fn csv_query_group_by_avg_with_projection() -> Result<()> { register_aggregate_csv(&ctx).await?; let sql = "SELECT avg(c12), c1 FROM aggregate_test_100 GROUP BY c1"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-----------------------------+----+", "| AVG(aggregate_test_100.c12) | c1 |", "+-----------------------------+----+", @@ -149,7 +147,7 @@ async fn subquery_alias_case_insensitive() -> Result<()> { let results = partitioned_csv::execute("SELECT V1.c1, v1.C2 FROM (SELECT test.C1, TEST.c2 FROM test) V1 ORDER BY v1.c1, V1.C2 LIMIT 1", partition_count).await?; - let expected = vec![ + let expected = [ "+----+----+", "| c1 | c2 |", "+----+----+", @@ -246,15 +244,13 @@ async fn project_cast_dictionary() { let df = DataFrame::new(ctx.state(), logical_plan); let actual = df.collect().await.unwrap(); - let expected = vec![ - "+----------------------------------------------------------------------------------+", + let expected = ["+----------------------------------------------------------------------------------+", "| CASE WHEN cpu_load_short.host IS NULL THEN Utf8(\"\") ELSE cpu_load_short.host END |", "+----------------------------------------------------------------------------------+", "| host1 |", "| |", "| host2 |", - "+----------------------------------------------------------------------------------+", - ]; + "+----------------------------------------------------------------------------------+"]; assert_batches_eq!(expected, &actual); } @@ -331,7 +327,7 @@ async fn project_column_with_same_name_as_relation() -> Result<()> { let sql = "select a.a from (select 1 as a) as a;"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec!["+---+", "| a |", "+---+", "| 1 |", "+---+"]; + let expected = ["+---+", "| a |", "+---+", "| 1 |", "+---+"]; assert_batches_sorted_eq!(expected, &actual); Ok(()) @@ -344,7 +340,7 @@ async fn project_column_with_filters_that_cant_pushed_down_always_false() -> Res let sql = "select * from (select 1 as a) f where f.a=2;"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec!["++", "++"]; + let expected = ["++", "++"]; assert_batches_sorted_eq!(expected, &actual); Ok(()) @@ -357,7 +353,7 @@ async fn project_column_with_filters_that_cant_pushed_down_always_true() -> Resu let sql = "select * from (select 1 as a) f where f.a=1;"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec!["+---+", "| a |", "+---+", "| 1 |", "+---+"]; + let expected = ["+---+", "| a |", "+---+", "| 1 |", "+---+"]; assert_batches_sorted_eq!(expected, &actual); Ok(()) @@ -370,7 +366,7 @@ async fn project_columns_in_memory_without_propagation() -> Result<()> { let sql = "select column1 as a from (values (1), (2)) f where f.column1 = 2;"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec!["+---+", "| a |", "+---+", "| 2 |", "+---+"]; + let expected = ["+---+", "| a |", "+---+", "| 2 |", "+---+"]; assert_batches_sorted_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/references.rs b/datafusion/core/tests/sql/references.rs index 495d071600ab6..f465e8a2dacc5 100644 --- a/datafusion/core/tests/sql/references.rs +++ b/datafusion/core/tests/sql/references.rs @@ -29,7 +29,7 @@ async fn qualified_table_references() -> Result<()> { ] { let sql = format!("SELECT COUNT(*) FROM {table_ref}"); let actual = execute_to_batches(&ctx, &sql).await; - let expected = vec![ + let expected = [ "+----------+", "| COUNT(*) |", "+----------+", @@ -73,7 +73,7 @@ async fn qualified_table_references_and_fields() -> Result<()> { // however, enclosing it in double quotes is ok let sql = r#"SELECT "f.c1" from test"#; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| f.c1 |", "+--------+", @@ -91,7 +91,7 @@ async fn qualified_table_references_and_fields() -> Result<()> { // check that duplicated table name and column name are ok let sql = r#"SELECT "test.c2" as expr1, test."test.c2" as expr2 from test"#; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------+-------+", "| expr1 | expr2 |", "+-------+-------+", @@ -107,7 +107,7 @@ async fn qualified_table_references_and_fields() -> Result<()> { // this let sql = r#"SELECT "....", "...." as c3 from test order by "....""#; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+------+----+", "| .... | c3 |", "+------+----+", @@ -124,7 +124,7 @@ async fn qualified_table_references_and_fields() -> Result<()> { async fn test_partial_qualified_name() -> Result<()> { let ctx = create_join_context("t1_id", "t2_id", true)?; let sql = "SELECT t1.t1_id, t1_name FROM public.t1"; - let expected = vec![ + let expected = [ "+-------+---------+", "| t1_id | t1_name |", "+-------+---------+", diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rs index 72cd10f1953c3..c05dc31cbe0f6 100644 --- a/datafusion/core/tests/sql/select.rs +++ b/datafusion/core/tests/sql/select.rs @@ -29,7 +29,7 @@ async fn query_get_indexed_field() -> Result<()> { )])); let builder = PrimitiveBuilder::::with_capacity(3); let mut lb = ListBuilder::new(builder); - for int_vec in vec![vec![0, 1, 2], vec![4, 5, 6], vec![7, 8, 9]] { + for int_vec in [[0, 1, 2], [4, 5, 6], [7, 8, 9]] { let builder = lb.values(); for int in int_vec { builder.append_value(int); @@ -45,15 +45,13 @@ async fn query_get_indexed_field() -> Result<()> { let sql = "SELECT some_list[1] as i0 FROM ints LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; #[rustfmt::skip] - let expected = vec![ - "+----+", + let expected = ["+----+", "| i0 |", "+----+", "| 0 |", "| 4 |", "| 7 |", - "+----+", - ]; + "+----+"]; assert_batches_eq!(expected, &actual); Ok(()) } @@ -72,10 +70,10 @@ async fn query_nested_get_indexed_field() -> Result<()> { let builder = PrimitiveBuilder::::with_capacity(3); let nested_lb = ListBuilder::new(builder); let mut lb = ListBuilder::new(nested_lb); - for int_vec_vec in vec![ - vec![vec![0, 1], vec![2, 3], vec![3, 4]], - vec![vec![5, 6], vec![7, 8], vec![9, 10]], - vec![vec![11, 12], vec![13, 14], vec![15, 16]], + for int_vec_vec in [ + [[0, 1], [2, 3], [3, 4]], + [[5, 6], [7, 8], [9, 10]], + [[11, 12], [13, 14], [15, 16]], ] { let nested_builder = lb.values(); for int_vec in int_vec_vec { @@ -95,7 +93,7 @@ async fn query_nested_get_indexed_field() -> Result<()> { // Original column is micros, convert to millis and check timestamp let sql = "SELECT some_list[1] as i0 FROM ints LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------+", "| i0 |", "+----------+", @@ -108,15 +106,13 @@ async fn query_nested_get_indexed_field() -> Result<()> { let sql = "SELECT some_list[1][1] as i0 FROM ints LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; #[rustfmt::skip] - let expected = vec![ - "+----+", + let expected = ["+----+", "| i0 |", "+----+", "| 0 |", "| 5 |", "| 11 |", - "+----+", - ]; + "+----+"]; assert_batches_eq!(expected, &actual); Ok(()) } @@ -136,7 +132,7 @@ async fn query_nested_get_indexed_field_on_struct() -> Result<()> { let builder = PrimitiveBuilder::::with_capacity(3); let nested_lb = ListBuilder::new(builder); let mut sb = StructBuilder::new(struct_fields, vec![Box::new(nested_lb)]); - for int_vec in vec![vec![0, 1, 2, 3], vec![4, 5, 6, 7], vec![8, 9, 10, 11]] { + for int_vec in [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]] { let lb = sb.field_builder::>(0).unwrap(); for int in int_vec { lb.values().append_value(int); @@ -152,7 +148,7 @@ async fn query_nested_get_indexed_field_on_struct() -> Result<()> { // Original column is micros, convert to millis and check timestamp let sql = "SELECT some_struct['bar'] as l0 FROM structs LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------------+", "| l0 |", "+----------------+", @@ -166,7 +162,7 @@ async fn query_nested_get_indexed_field_on_struct() -> Result<()> { // Access to field of struct by CompoundIdentifier let sql = "SELECT some_struct.bar as l0 FROM structs LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------------+", "| l0 |", "+----------------+", @@ -180,15 +176,13 @@ async fn query_nested_get_indexed_field_on_struct() -> Result<()> { let sql = "SELECT some_struct['bar'][1] as i0 FROM structs LIMIT 3"; let actual = execute_to_batches(&ctx, sql).await; #[rustfmt::skip] - let expected = vec![ - "+----+", + let expected = ["+----+", "| i0 |", "+----+", "| 0 |", "| 4 |", "| 8 |", - "+----+", - ]; + "+----+"]; assert_batches_eq!(expected, &actual); Ok(()) } @@ -422,7 +416,7 @@ async fn sort_on_window_null_string() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; // NULLS LAST - let expected = vec![ + let expected = [ "+-------+-----+", "| d1 | rn1 |", "+-------+-----+", @@ -437,7 +431,7 @@ async fn sort_on_window_null_string() -> Result<()> { "SELECT d2, row_number() OVER (partition by d2) as rn1 FROM test ORDER BY d2 asc"; let actual = execute_to_batches(&ctx, sql).await; // NULLS LAST - let expected = vec![ + let expected = [ "+-------+-----+", "| d2 | rn1 |", "+-------+-----+", @@ -453,7 +447,7 @@ async fn sort_on_window_null_string() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; // NULLS FIRST - let expected = vec![ + let expected = [ "+-------+-----+", "| d2 | rn1 |", "+-------+-----+", @@ -578,7 +572,7 @@ async fn boolean_literal() -> Result<()> { execute_with_partition("SELECT c1, c3 FROM test WHERE c1 > 2 AND c3 = true", 4) .await?; - let expected = vec![ + let expected = [ "+----+------+", "| c1 | c3 |", "+----+------+", @@ -611,7 +605,7 @@ async fn unprojected_filter() { let results = df.collect().await.unwrap(); - let expected = vec![ + let expected = [ "+-----------------------+", "| ?table?.i + ?table?.i |", "+-----------------------+", diff --git a/datafusion/core/tests/sql/subqueries.rs b/datafusion/core/tests/sql/subqueries.rs index 7d38b9173caf8..01f8dd684b23c 100644 --- a/datafusion/core/tests/sql/subqueries.rs +++ b/datafusion/core/tests/sql/subqueries.rs @@ -48,7 +48,7 @@ async fn correlated_scalar_subquery_sum_agg_bug() -> Result<()> { // assert data let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| t1_int |", "+--------+", diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 0482f07795ada..611e7c22282ee 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -138,7 +138,7 @@ async fn timestamp_minmax() -> Result<()> { let sql = "SELECT MIN(table_a.ts), MAX(table_b.ts) FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------------------+-----------------------------+", "| MIN(table_a.ts) | MAX(table_b.ts) |", "+-------------------------+-----------------------------+", @@ -516,7 +516,7 @@ async fn group_by_timestamp_millis() -> Result<()> { let sql = "SELECT timestamp, SUM(count) FROM t1 GROUP BY timestamp ORDER BY timestamp ASC"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+---------------------+---------------+", "| timestamp | SUM(t1.count) |", "+---------------------+---------------+", @@ -617,7 +617,7 @@ async fn timestamp_array_add_interval() -> Result<()> { let sql = "SELECT ts, ts - INTERVAL '8' MILLISECONDS FROM table_a"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------------------------+----------------------------------------------+", "| ts | table_a.ts - IntervalMonthDayNano(\"8000000\") |", "+----------------------------+----------------------------------------------+", @@ -630,41 +630,35 @@ async fn timestamp_array_add_interval() -> Result<()> { let sql = "SELECT ts, ts + INTERVAL '1' SECOND FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+-------------------------------------------------+", + let expected = ["+----------------------------+-------------------------------------------------+", "| ts | table_b.ts + IntervalMonthDayNano(\"1000000000\") |", "+----------------------------+-------------------------------------------------+", "| 2020-09-08T13:42:29.190855 | 2020-09-08T13:42:30.190855 |", "| 2020-09-08T12:42:29.190855 | 2020-09-08T12:42:30.190855 |", "| 2020-09-08T11:42:29.190855 | 2020-09-08T11:42:30.190855 |", - "+----------------------------+-------------------------------------------------+", - ]; + "+----------------------------+-------------------------------------------------+"]; assert_batches_eq!(expected, &actual); let sql = "SELECT ts, ts + INTERVAL '2' MONTH FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+---------------------------------------------------------------------+", + let expected = ["+----------------------------+---------------------------------------------------------------------+", "| ts | table_b.ts + IntervalMonthDayNano(\"158456325028528675187087900672\") |", "+----------------------------+---------------------------------------------------------------------+", "| 2020-09-08T13:42:29.190855 | 2020-11-08T13:42:29.190855 |", "| 2020-09-08T12:42:29.190855 | 2020-11-08T12:42:29.190855 |", "| 2020-09-08T11:42:29.190855 | 2020-11-08T11:42:29.190855 |", - "+----------------------------+---------------------------------------------------------------------+", - ]; + "+----------------------------+---------------------------------------------------------------------+"]; assert_batches_eq!(expected, &actual); let sql = "SELECT ts, ts - INTERVAL '16' YEAR FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+----------------------------+-----------------------------------------------------------------------+", + let expected = ["+----------------------------+-----------------------------------------------------------------------+", "| ts | table_b.ts - IntervalMonthDayNano(\"15211807202738752817960438464512\") |", "+----------------------------+-----------------------------------------------------------------------+", "| 2020-09-08T13:42:29.190855 | 2004-09-08T13:42:29.190855 |", "| 2020-09-08T12:42:29.190855 | 2004-09-08T12:42:29.190855 |", "| 2020-09-08T11:42:29.190855 | 2004-09-08T11:42:29.190855 |", - "+----------------------------+-----------------------------------------------------------------------+", - ]; + "+----------------------------+-----------------------------------------------------------------------+"]; assert_batches_eq!(expected, &actual); Ok(()) } @@ -676,7 +670,7 @@ async fn cast_timestamp_before_1970() -> Result<()> { let sql = "select cast('1969-01-01T00:00:00Z' as timestamp);"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+------------------------------+", "| Utf8(\"1969-01-01T00:00:00Z\") |", "+------------------------------+", @@ -688,7 +682,7 @@ async fn cast_timestamp_before_1970() -> Result<()> { let sql = "select cast('1969-01-01T00:00:00.1Z' as timestamp);"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------------------------------+", "| Utf8(\"1969-01-01T00:00:00.1Z\") |", "+--------------------------------+", @@ -708,7 +702,7 @@ async fn test_arrow_typeof() -> Result<()> { let sql = "select arrow_typeof(date_trunc('minute', to_timestamp_seconds(61)));"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------------------------------------------------------------------------+", "| arrow_typeof(date_trunc(Utf8(\"minute\"),to_timestamp_seconds(Int64(61)))) |", "+--------------------------------------------------------------------------+", @@ -719,7 +713,7 @@ async fn test_arrow_typeof() -> Result<()> { let sql = "select arrow_typeof(date_trunc('second', to_timestamp_millis(61)));"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-------------------------------------------------------------------------+", "| arrow_typeof(date_trunc(Utf8(\"second\"),to_timestamp_millis(Int64(61)))) |", "+-------------------------------------------------------------------------+", @@ -730,18 +724,16 @@ async fn test_arrow_typeof() -> Result<()> { let sql = "select arrow_typeof(date_trunc('millisecond', to_timestamp_micros(61)));"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ - "+------------------------------------------------------------------------------+", + let expected = ["+------------------------------------------------------------------------------+", "| arrow_typeof(date_trunc(Utf8(\"millisecond\"),to_timestamp_micros(Int64(61)))) |", "+------------------------------------------------------------------------------+", "| Timestamp(Microsecond, None) |", - "+------------------------------------------------------------------------------+", - ]; + "+------------------------------------------------------------------------------+"]; assert_batches_eq!(expected, &actual); let sql = "select arrow_typeof(date_trunc('microsecond', to_timestamp(61)));"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-----------------------------------------------------------------------+", "| arrow_typeof(date_trunc(Utf8(\"microsecond\"),to_timestamp(Int64(61)))) |", "+-----------------------------------------------------------------------+", @@ -763,7 +755,7 @@ async fn cast_timestamp_to_timestamptz() -> Result<()> { let sql = "SELECT ts::timestamptz, arrow_typeof(ts::timestamptz) FROM table_a;"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-----------------------------+---------------------------------------+", "| table_a.ts | arrow_typeof(table_a.ts) |", "+-----------------------------+---------------------------------------+", @@ -783,7 +775,7 @@ async fn test_cast_to_time() -> Result<()> { let sql = "SELECT 0::TIME"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------+", "| Int64(0) |", "+----------+", @@ -816,7 +808,7 @@ async fn test_cast_to_time_without_time_zone() -> Result<()> { let sql = "SELECT 0::TIME WITHOUT TIME ZONE"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+----------+", "| Int64(0) |", "+----------+", @@ -861,7 +853,7 @@ async fn test_current_date() -> Result<()> { let sql = "select case when current_date() = cast(now() as date) then 'OK' else 'FAIL' end result"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -893,7 +885,7 @@ async fn test_current_time() -> Result<()> { let sql = "select case when current_time() = (now()::bigint % 86400000000000)::time then 'OK' else 'FAIL' end result"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -913,7 +905,7 @@ async fn test_ts_dt_binary_ops() -> Result<()> { "select count(1) result from (select now() as n) a where n = '2000-01-01'::date"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -928,7 +920,7 @@ async fn test_ts_dt_binary_ops() -> Result<()> { "select count(1) result from (select now() as n) a where n >= '2000-01-01'::date"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -942,7 +934,7 @@ async fn test_ts_dt_binary_ops() -> Result<()> { let sql = "select now() = '2000-01-01'::date as result"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -956,7 +948,7 @@ async fn test_ts_dt_binary_ops() -> Result<()> { let sql = "select now() >= '2000-01-01'::date as result"; let results = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+--------+", "| result |", "+--------+", @@ -1034,7 +1026,7 @@ async fn timestamp_sub_with_tz() -> Result<()> { let sql = "SELECT val, ts1 - ts2 AS ts_diff FROM table_a ORDER BY ts2 - ts1"; let actual = execute_to_batches(&ctx, sql).await; - let expected = vec![ + let expected = [ "+-----+-----------------------------------+", "| val | ts_diff |", "+-----+-----------------------------------+", diff --git a/datafusion/core/tests/sql/udf.rs b/datafusion/core/tests/sql/udf.rs index 5aa3ab3bc0a81..97512d0249c46 100644 --- a/datafusion/core/tests/sql/udf.rs +++ b/datafusion/core/tests/sql/udf.rs @@ -92,7 +92,7 @@ async fn scalar_udf() -> Result<()> { let result = DataFrame::new(ctx.state(), plan).collect().await?; - let expected = vec![ + let expected = [ "+-----+-----+-----------------+", "| a | b | my_add(t.a,t.b) |", "+-----+-----+-----------------+", @@ -148,7 +148,7 @@ async fn scalar_udf_zero_params() -> Result<()> { )); let result = plan_and_collect(&ctx, "select get_100() a from t").await?; - let expected = vec![ + let expected = [ "+-----+", // "| a |", // "+-----+", // @@ -156,22 +156,22 @@ async fn scalar_udf_zero_params() -> Result<()> { "| 100 |", // "| 100 |", // "| 100 |", // - "+-----+", // + "+-----+", ]; assert_batches_eq!(expected, &result); let result = plan_and_collect(&ctx, "select get_100() a").await?; - let expected = vec![ + let expected = [ "+-----+", // "| a |", // "+-----+", // "| 100 |", // - "+-----+", // + "+-----+", ]; assert_batches_eq!(expected, &result); let result = plan_and_collect(&ctx, "select get_100() from t where a=999").await?; - let expected = vec![ + let expected = [ "++", // "++", ]; @@ -201,12 +201,12 @@ async fn scalar_udf_override_built_in_scalar_function() -> Result<()> { // Make sure that the UDF is used instead of the built-in function let result = plan_and_collect(&ctx, "select abs(a) a from t").await?; - let expected = vec![ + let expected = [ "+---+", // "| a |", // "+---+", // "| 1 |", // - "+---+", // + "+---+", ]; assert_batches_eq!(expected, &result); Ok(()) @@ -245,7 +245,7 @@ async fn simple_udaf() -> Result<()> { let result = plan_and_collect(&ctx, "SELECT MY_AVG(a) FROM t").await?; - let expected = vec![ + let expected = [ "+-------------+", "| my_avg(t.a) |", "+-------------+", diff --git a/datafusion/core/tests/user_defined/user_defined_aggregates.rs b/datafusion/core/tests/user_defined/user_defined_aggregates.rs index 041d4db4c50db..64547bbdfa36a 100644 --- a/datafusion/core/tests/user_defined/user_defined_aggregates.rs +++ b/datafusion/core/tests/user_defined/user_defined_aggregates.rs @@ -49,7 +49,7 @@ use datafusion_common::{ async fn test_setup() { let TestContext { ctx, test_state: _ } = TestContext::new(); let sql = "SELECT * from t order by time"; - let expected = vec![ + let expected = [ "+-------+----------------------------+", "| value | time |", "+-------+----------------------------+", @@ -69,7 +69,7 @@ async fn test_udaf() { let TestContext { ctx, test_state } = TestContext::new(); assert!(!test_state.update_batch()); let sql = "SELECT time_sum(time) from t"; - let expected = vec![ + let expected = [ "+----------------------------+", "| time_sum(t.time) |", "+----------------------------+", @@ -87,7 +87,7 @@ async fn test_udaf() { async fn test_udaf_as_window() { let TestContext { ctx, test_state } = TestContext::new(); let sql = "SELECT time_sum(time) OVER() as time_sum from t"; - let expected = vec![ + let expected = [ "+----------------------------+", "| time_sum |", "+----------------------------+", @@ -109,7 +109,7 @@ async fn test_udaf_as_window() { async fn test_udaf_as_window_with_frame() { let TestContext { ctx, test_state } = TestContext::new(); let sql = "SELECT time_sum(time) OVER(ORDER BY time ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as time_sum from t"; - let expected = vec![ + let expected = [ "+----------------------------+", "| time_sum |", "+----------------------------+", @@ -144,7 +144,7 @@ async fn test_udaf_as_window_with_frame_without_retract_batch() { async fn test_udaf_returning_struct() { let TestContext { ctx, test_state: _ } = TestContext::new(); let sql = "SELECT first(value, time) from t"; - let expected = vec![ + let expected = [ "+------------------------------------------------+", "| first(t.value,t.time) |", "+------------------------------------------------+", @@ -159,7 +159,7 @@ async fn test_udaf_returning_struct() { async fn test_udaf_returning_struct_subquery() { let TestContext { ctx, test_state: _ } = TestContext::new(); let sql = "select sq.first['value'], sq.first['time'] from (SELECT first(value, time) as first from t) as sq"; - let expected = vec![ + let expected = [ "+-----------------+----------------------------+", "| sq.first[value] | sq.first[time] |", "+-----------------+----------------------------+", diff --git a/datafusion/core/tests/user_defined/user_defined_plan.rs b/datafusion/core/tests/user_defined/user_defined_plan.rs index 57a802804bd2f..21ec20f0d4d61 100644 --- a/datafusion/core/tests/user_defined/user_defined_plan.rs +++ b/datafusion/core/tests/user_defined/user_defined_plan.rs @@ -220,10 +220,8 @@ async fn topk_query() -> Result<()> { async fn topk_plan() -> Result<()> { let mut ctx = setup_table(make_topk_context()).await?; - let mut expected = vec![ - "| logical_plan after topk | TopK: k=3 |", - "| | TableScan: sales projection=[customer_id,revenue] |", - ].join("\n"); + let mut expected = ["| logical_plan after topk | TopK: k=3 |", + "| | TableScan: sales projection=[customer_id,revenue] |"].join("\n"); let explain_query = format!("EXPLAIN VERBOSE {QUERY}"); let actual_output = exec_sql(&mut ctx, &explain_query).await?; diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rs index a7f7d9b6e6917..88015889752ea 100644 --- a/datafusion/expr/src/expr_fn.rs +++ b/datafusion/expr/src/expr_fn.rs @@ -959,7 +959,7 @@ mod test { macro_rules! test_scalar_expr { ($ENUM:ident, $FUNC:ident, $($arg:ident),*) => { - let expected = vec![$(stringify!($arg)),*]; + let expected = [$(stringify!($arg)),*]; let result = $FUNC( $( col(stringify!($arg.to_string())) @@ -977,7 +977,7 @@ mod test { macro_rules! test_nary_scalar_expr { ($ENUM:ident, $FUNC:ident, $($arg:ident),*) => { - let expected = vec![$(stringify!($arg)),*]; + let expected = [$(stringify!($arg)),*]; let result = $FUNC( vec![ $( diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index 3a7c21139b27f..fb91e1bc9dba8 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -665,7 +665,7 @@ impl LogicalPlanBuilder { join_keys .0 .into_iter() - .zip(join_keys.1.into_iter()) + .zip(join_keys.1) .map(|(l, r)| { let l = l.into(); let r = r.into(); @@ -742,7 +742,7 @@ impl LogicalPlanBuilder { let on = left_keys .into_iter() - .zip(right_keys.into_iter()) + .zip(right_keys) .map(|(l, r)| (Expr::Column(l), Expr::Column(r))) .collect(); let join_schema = @@ -777,7 +777,7 @@ impl LogicalPlanBuilder { .map(|c| Self::normalize(&right, c)) .collect::>()?; - let on: Vec<(_, _)> = left_keys.into_iter().zip(right_keys.into_iter()).collect(); + let on: Vec<(_, _)> = left_keys.into_iter().zip(right_keys).collect(); let join_schema = build_join_schema(self.plan.schema(), right.schema(), &join_type)?; let mut join_on: Vec<(Expr, Expr)> = vec![]; diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs index bfb4f662d7e7f..ab691c1366a45 100644 --- a/datafusion/expr/src/logical_plan/plan.rs +++ b/datafusion/expr/src/logical_plan/plan.rs @@ -1833,7 +1833,7 @@ impl Join { let on: Vec<(Expr, Expr)> = column_on .0 .into_iter() - .zip(column_on.1.into_iter()) + .zip(column_on.1) .map(|(l, r)| (Expr::Column(l), Expr::Column(r))) .collect(); let join_schema = @@ -1992,7 +1992,7 @@ mod tests { fn test_display_graphviz() -> Result<()> { let plan = display_plan()?; - let expected_graphviz = r###" + let expected_graphviz = r#" // Begin DataFusion GraphViz Plan, // display it online here: https://dreampuf.github.io/GraphvizOnline @@ -2025,7 +2025,7 @@ digraph { } } // End DataFusion GraphViz Plan -"###; +"#; // just test for a few key lines in the output rather than the // whole thing to make test mainteance easier. diff --git a/datafusion/expr/src/partition_evaluator.rs b/datafusion/expr/src/partition_evaluator.rs index c9576dd604030..0a765b30b0736 100644 --- a/datafusion/expr/src/partition_evaluator.rs +++ b/datafusion/expr/src/partition_evaluator.rs @@ -163,7 +163,7 @@ pub trait PartitionEvaluator: Debug + Send { let res = (0..num_rows) .map(|idx| self.evaluate(values, &self.get_range(idx, num_rows)?)) .collect::>>()?; - ScalarValue::iter_to_array(res.into_iter()) + ScalarValue::iter_to_array(res) } else { not_impl_err!("evaluate_all is not implemented by default") } diff --git a/datafusion/expr/src/type_coercion/other.rs b/datafusion/expr/src/type_coercion/other.rs index c53054e82112f..634558094ae79 100644 --- a/datafusion/expr/src/type_coercion/other.rs +++ b/datafusion/expr/src/type_coercion/other.rs @@ -28,9 +28,8 @@ pub fn get_coerce_type_for_list( ) -> Option { list_types .iter() - .fold(Some(expr_type.clone()), |left, right_type| match left { - None => None, - Some(left_type) => comparison_coercion(&left_type, right_type), + .try_fold(expr_type.clone(), |left_type, right_type| { + comparison_coercion(&left_type, right_type) }) } @@ -47,11 +46,9 @@ pub fn get_coerce_type_for_case_expression( }; when_or_then_types .iter() - .fold(Some(case_or_else_type), |left, right_type| match left { - // failed to find a valid coercion in a previous iteration - None => None, + .try_fold(case_or_else_type, |left_type, right_type| { // TODO: now just use the `equal` coercion rule for case when. If find the issue, and // refactor again. - Some(left_type) => comparison_coercion(&left_type, right_type), + comparison_coercion(&left_type, right_type) }) } diff --git a/datafusion/optimizer/src/common_subexpr_eliminate.rs b/datafusion/optimizer/src/common_subexpr_eliminate.rs index dda1dfd8b2ced..c6b138f8ca36c 100644 --- a/datafusion/optimizer/src/common_subexpr_eliminate.rs +++ b/datafusion/optimizer/src/common_subexpr_eliminate.rs @@ -1225,7 +1225,7 @@ mod test { .map(|field| (field.name(), field.data_type())) .collect(); let formatted_fields_with_datatype = format!("{fields_with_datatypes:#?}"); - let expected = r###"[ + let expected = r#"[ ( "a", UInt64, @@ -1238,7 +1238,7 @@ mod test { "c", UInt64, ), -]"###; +]"#; assert_eq!(expected, formatted_fields_with_datatype); } diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rs index d94c5b5bdb8c1..d5c7641a13c46 100644 --- a/datafusion/optimizer/src/push_down_filter.rs +++ b/datafusion/optimizer/src/push_down_filter.rs @@ -774,7 +774,7 @@ impl OptimizerRule for PushDownFilter { let results = scan .source .supports_filters_pushdown(filter_predicates.as_slice())?; - let zip = filter_predicates.iter().zip(results.into_iter()); + let zip = filter_predicates.iter().zip(results); let new_scan_filters = zip .clone() diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs index 29fd15cc3ba90..c94d5e2e3538f 100644 --- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs +++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs @@ -412,7 +412,9 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> { }) if list.len() == 1 && matches!(list.first(), Some(Expr::ScalarSubquery { .. })) => { - let Expr::ScalarSubquery(subquery) = list.remove(0) else { unreachable!() }; + let Expr::ScalarSubquery(subquery) = list.remove(0) else { + unreachable!() + }; Expr::InSubquery(InSubquery::new(expr, subquery, negated)) } diff --git a/datafusion/optimizer/src/simplify_expressions/regex.rs b/datafusion/optimizer/src/simplify_expressions/regex.rs index 5094623b82c08..b9d9821b43f09 100644 --- a/datafusion/optimizer/src/simplify_expressions/regex.rs +++ b/datafusion/optimizer/src/simplify_expressions/regex.rs @@ -203,7 +203,9 @@ fn anchored_literal_to_expr(v: &[Hir]) -> Option { match v.len() { 2 => Some(lit("")), 3 => { - let HirKind::Literal(l) = v[1].kind() else { return None }; + let HirKind::Literal(l) = v[1].kind() else { + return None; + }; like_str_from_literal(l).map(lit) } _ => None, diff --git a/datafusion/physical-expr/src/aggregate/average.rs b/datafusion/physical-expr/src/aggregate/average.rs index ce8f5874021c4..ccadb2c9b826e 100644 --- a/datafusion/physical-expr/src/aggregate/average.rs +++ b/datafusion/physical-expr/src/aggregate/average.rs @@ -471,7 +471,7 @@ where let array: PrimitiveArray = if nulls.null_count() > 0 { let mut builder = PrimitiveBuilder::::with_capacity(nulls.len()); - let iter = sums.into_iter().zip(counts.into_iter()).zip(nulls.iter()); + let iter = sums.into_iter().zip(counts).zip(nulls.iter()); for ((sum, count), is_valid) in iter { if is_valid { diff --git a/datafusion/physical-expr/src/aggregate/build_in.rs b/datafusion/physical-expr/src/aggregate/build_in.rs index a38dfdcc13d07..6568457bc234a 100644 --- a/datafusion/physical-expr/src/aggregate/build_in.rs +++ b/datafusion/physical-expr/src/aggregate/build_in.rs @@ -1287,7 +1287,7 @@ mod tests { // try cast if need input_exprs .iter() - .zip(coerced_types.into_iter()) + .zip(coerced_types) .map(|(expr, coerced_type)| try_cast(expr.clone(), schema, coerced_type)) .collect::>>() } diff --git a/datafusion/physical-expr/src/expressions/binary.rs b/datafusion/physical-expr/src/expressions/binary.rs index 2729d5e56d096..2a217d4bfd5d6 100644 --- a/datafusion/physical-expr/src/expressions/binary.rs +++ b/datafusion/physical-expr/src/expressions/binary.rs @@ -1063,7 +1063,7 @@ mod tests { let result = lt.evaluate(&batch)?.into_array(batch.num_rows()); assert_eq!(result.len(), 5); - let expected = vec![false, false, true, true, true]; + let expected = [false, false, true, true, true]; let result = as_boolean_array(&result).expect("failed to downcast to BooleanArray"); for (i, &expected_item) in expected.iter().enumerate().take(5) { @@ -1107,7 +1107,7 @@ mod tests { let result = expr.evaluate(&batch)?.into_array(batch.num_rows()); assert_eq!(result.len(), 5); - let expected = vec![true, true, false, true, false]; + let expected = [true, true, false, true, false]; let result = as_boolean_array(&result).expect("failed to downcast to BooleanArray"); for (i, &expected_item) in expected.iter().enumerate().take(5) { @@ -1182,7 +1182,7 @@ mod tests { Operator::Plus, Int32Array, DataType::Int32, - vec![2i32, 4i32], + [2i32, 4i32], ); test_coercion!( Int32Array, @@ -1194,7 +1194,7 @@ mod tests { Operator::Plus, Int32Array, DataType::Int32, - vec![2i32], + [2i32], ); test_coercion!( Float32Array, @@ -1206,7 +1206,7 @@ mod tests { Operator::Plus, Float32Array, DataType::Float32, - vec![2f32], + [2f32], ); test_coercion!( Float32Array, @@ -1218,7 +1218,7 @@ mod tests { Operator::Multiply, Float32Array, DataType::Float32, - vec![2f32], + [2f32], ); test_coercion!( StringArray, @@ -1230,7 +1230,7 @@ mod tests { Operator::Eq, BooleanArray, DataType::Boolean, - vec![true, true], + [true, true], ); test_coercion!( StringArray, @@ -1242,7 +1242,7 @@ mod tests { Operator::Lt, BooleanArray, DataType::Boolean, - vec![true, false], + [true, false], ); test_coercion!( StringArray, @@ -1254,7 +1254,7 @@ mod tests { Operator::Eq, BooleanArray, DataType::Boolean, - vec![true, true], + [true, true], ); test_coercion!( StringArray, @@ -1266,7 +1266,7 @@ mod tests { Operator::Lt, BooleanArray, DataType::Boolean, - vec![true, false], + [true, false], ); test_coercion!( StringArray, @@ -1278,7 +1278,7 @@ mod tests { Operator::RegexMatch, BooleanArray, DataType::Boolean, - vec![true, false, true, false, false], + [true, false, true, false, false], ); test_coercion!( StringArray, @@ -1290,7 +1290,7 @@ mod tests { Operator::RegexIMatch, BooleanArray, DataType::Boolean, - vec![true, true, true, true, false], + [true, true, true, true, false], ); test_coercion!( StringArray, @@ -1302,7 +1302,7 @@ mod tests { Operator::RegexNotMatch, BooleanArray, DataType::Boolean, - vec![false, true, false, true, true], + [false, true, false, true, true], ); test_coercion!( StringArray, @@ -1314,7 +1314,7 @@ mod tests { Operator::RegexNotIMatch, BooleanArray, DataType::Boolean, - vec![false, false, false, false, true], + [false, false, false, false, true], ); test_coercion!( LargeStringArray, @@ -1326,7 +1326,7 @@ mod tests { Operator::RegexMatch, BooleanArray, DataType::Boolean, - vec![true, false, true, false, false], + [true, false, true, false, false], ); test_coercion!( LargeStringArray, @@ -1338,7 +1338,7 @@ mod tests { Operator::RegexIMatch, BooleanArray, DataType::Boolean, - vec![true, true, true, true, false], + [true, true, true, true, false], ); test_coercion!( LargeStringArray, @@ -1350,7 +1350,7 @@ mod tests { Operator::RegexNotMatch, BooleanArray, DataType::Boolean, - vec![false, true, false, true, true], + [false, true, false, true, true], ); test_coercion!( LargeStringArray, @@ -1362,7 +1362,7 @@ mod tests { Operator::RegexNotIMatch, BooleanArray, DataType::Boolean, - vec![false, false, false, false, true], + [false, false, false, false, true], ); test_coercion!( Int16Array, @@ -1374,7 +1374,7 @@ mod tests { Operator::BitwiseAnd, Int64Array, DataType::Int64, - vec![0i64, 0i64, 1i64], + [0i64, 0i64, 1i64], ); test_coercion!( UInt16Array, @@ -1386,7 +1386,7 @@ mod tests { Operator::BitwiseAnd, UInt64Array, DataType::UInt64, - vec![0u64, 0u64, 1u64], + [0u64, 0u64, 1u64], ); test_coercion!( Int16Array, @@ -1398,7 +1398,7 @@ mod tests { Operator::BitwiseOr, Int64Array, DataType::Int64, - vec![11i64, 6i64, 7i64], + [11i64, 6i64, 7i64], ); test_coercion!( UInt16Array, @@ -1410,7 +1410,7 @@ mod tests { Operator::BitwiseOr, UInt64Array, DataType::UInt64, - vec![11u64, 6u64, 7u64], + [11u64, 6u64, 7u64], ); test_coercion!( Int16Array, @@ -1422,7 +1422,7 @@ mod tests { Operator::BitwiseXor, Int64Array, DataType::Int64, - vec![9i64, 4i64, 6i64], + [9i64, 4i64, 6i64], ); test_coercion!( UInt16Array, @@ -1434,7 +1434,7 @@ mod tests { Operator::BitwiseXor, UInt64Array, DataType::UInt64, - vec![9u64, 4u64, 6u64], + [9u64, 4u64, 6u64], ); test_coercion!( Int16Array, @@ -1446,7 +1446,7 @@ mod tests { Operator::BitwiseShiftRight, Int64Array, DataType::Int64, - vec![1i64, 3i64, 2i64], + [1i64, 3i64, 2i64], ); test_coercion!( UInt16Array, @@ -1458,7 +1458,7 @@ mod tests { Operator::BitwiseShiftRight, UInt64Array, DataType::UInt64, - vec![1u64, 3u64, 2u64], + [1u64, 3u64, 2u64], ); test_coercion!( Int16Array, @@ -1470,7 +1470,7 @@ mod tests { Operator::BitwiseShiftLeft, Int64Array, DataType::Int64, - vec![32i64, 12288i64, 512i64], + [32i64, 12288i64, 512i64], ); test_coercion!( UInt16Array, @@ -1482,7 +1482,7 @@ mod tests { Operator::BitwiseShiftLeft, UInt64Array, DataType::UInt64, - vec![32u64, 12288u64, 512u64], + [32u64, 12288u64, 512u64], ); Ok(()) } @@ -2804,14 +2804,14 @@ mod tests { /// Returns (schema, BooleanArray) with [true, NULL, false] fn scalar_bool_test_array() -> (SchemaRef, ArrayRef) { let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]); - let a: BooleanArray = vec![Some(true), None, Some(false)].iter().collect(); + let a: BooleanArray = [Some(true), None, Some(false)].iter().collect(); (Arc::new(schema), Arc::new(a)) } #[test] fn eq_op_bool() { let (schema, a, b) = bool_test_arrays(); - let expected = vec![ + let expected = [ Some(true), None, Some(false), diff --git a/datafusion/physical-expr/src/expressions/case.rs b/datafusion/physical-expr/src/expressions/case.rs index 4e37dc4960743..11552b6b46adf 100644 --- a/datafusion/physical-expr/src/expressions/case.rs +++ b/datafusion/physical-expr/src/expressions/case.rs @@ -1008,11 +1008,10 @@ mod tests { }; thens_type .iter() - .fold(Some(else_type), |left, right_type| match left { - None => None, + .try_fold(else_type, |left_type, right_type| { // TODO: now just use the `equal` coercion rule for case when. If find the issue, and // refactor again. - Some(left_type) => comparison_coercion(&left_type, right_type), + comparison_coercion(&left_type, right_type) }) } } diff --git a/datafusion/physical-expr/src/expressions/cast.rs b/datafusion/physical-expr/src/expressions/cast.rs index cd70c6e2745c9..9390089063a0e 100644 --- a/datafusion/physical-expr/src/expressions/cast.rs +++ b/datafusion/physical-expr/src/expressions/cast.rs @@ -353,13 +353,13 @@ mod tests { DataType::Decimal128(10, 3), Decimal128Array, DataType::Decimal128(20, 6), - vec![ + [ Some(1_234_000), Some(2_222_000), Some(3_000), Some(4_000_000), Some(5_000_000), - None, + None ], None ); @@ -374,7 +374,7 @@ mod tests { DataType::Decimal128(10, 3), Decimal128Array, DataType::Decimal128(10, 2), - vec![Some(123), Some(222), Some(0), Some(400), Some(500), None,], + [Some(123), Some(222), Some(0), Some(400), Some(500), None], None ); @@ -395,13 +395,13 @@ mod tests { DataType::Decimal128(10, 0), Int8Array, DataType::Int8, - vec![ + [ Some(1_i8), Some(2_i8), Some(3_i8), Some(4_i8), Some(5_i8), - None, + None ], None ); @@ -417,13 +417,13 @@ mod tests { DataType::Decimal128(10, 0), Int16Array, DataType::Int16, - vec![ + [ Some(1_i16), Some(2_i16), Some(3_i16), Some(4_i16), Some(5_i16), - None, + None ], None ); @@ -439,13 +439,13 @@ mod tests { DataType::Decimal128(10, 0), Int32Array, DataType::Int32, - vec![ + [ Some(1_i32), Some(2_i32), Some(3_i32), Some(4_i32), Some(5_i32), - None, + None ], None ); @@ -460,13 +460,13 @@ mod tests { DataType::Decimal128(10, 0), Int64Array, DataType::Int64, - vec![ + [ Some(1_i64), Some(2_i64), Some(3_i64), Some(4_i64), Some(5_i64), - None, + None ], None ); @@ -490,13 +490,13 @@ mod tests { DataType::Decimal128(10, 3), Float32Array, DataType::Float32, - vec![ + [ Some(1.234_f32), Some(2.222_f32), Some(0.003_f32), Some(4.0_f32), Some(5.0_f32), - None, + None ], None ); @@ -511,13 +511,13 @@ mod tests { DataType::Decimal128(20, 6), Float64Array, DataType::Float64, - vec![ + [ Some(0.001234_f64), Some(0.002222_f64), Some(0.000003_f64), Some(0.004_f64), Some(0.005_f64), - None, + None ], None ); @@ -533,7 +533,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(3, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),], + [Some(1), Some(2), Some(3), Some(4), Some(5)], None ); @@ -544,7 +544,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(5, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),], + [Some(1), Some(2), Some(3), Some(4), Some(5)], None ); @@ -555,7 +555,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(10, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),], + [Some(1), Some(2), Some(3), Some(4), Some(5)], None ); @@ -566,7 +566,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(20, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),], + [Some(1), Some(2), Some(3), Some(4), Some(5)], None ); @@ -577,7 +577,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(20, 2), - vec![Some(100), Some(200), Some(300), Some(400), Some(500),], + [Some(100), Some(200), Some(300), Some(400), Some(500)], None ); @@ -588,7 +588,7 @@ mod tests { vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50], Decimal128Array, DataType::Decimal128(10, 2), - vec![Some(150), Some(250), Some(300), Some(112), Some(550),], + [Some(150), Some(250), Some(300), Some(112), Some(550)], None ); @@ -599,12 +599,12 @@ mod tests { vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50], Decimal128Array, DataType::Decimal128(20, 4), - vec![ + [ Some(15000), Some(25000), Some(30000), Some(11235), - Some(55000), + Some(55000) ], None ); @@ -619,7 +619,7 @@ mod tests { vec![1, 2, 3, 4, 5], UInt32Array, DataType::UInt32, - vec![ + [ Some(1_u32), Some(2_u32), Some(3_u32), @@ -639,7 +639,7 @@ mod tests { vec![1, 2, 3, 4, 5], StringArray, DataType::Utf8, - vec![Some("1"), Some("2"), Some("3"), Some("4"), Some("5")], + [Some("1"), Some("2"), Some("3"), Some("4"), Some("5")], None ); Ok(()) diff --git a/datafusion/physical-expr/src/expressions/in_list.rs b/datafusion/physical-expr/src/expressions/in_list.rs index 8f7515f29af06..de3bf2456a199 100644 --- a/datafusion/physical-expr/src/expressions/in_list.rs +++ b/datafusion/physical-expr/src/expressions/in_list.rs @@ -454,9 +454,8 @@ mod tests { fn get_coerce_type(expr_type: &DataType, list_type: &[DataType]) -> Option { list_type .iter() - .fold(Some(expr_type.clone()), |left, right_type| match left { - None => None, - Some(left_type) => comparison_coercion(&left_type, right_type), + .try_fold(expr_type.clone(), |left_type, right_type| { + comparison_coercion(&left_type, right_type) }) } diff --git a/datafusion/physical-expr/src/expressions/try_cast.rs b/datafusion/physical-expr/src/expressions/try_cast.rs index d95d3ee1415d4..cba026c565134 100644 --- a/datafusion/physical-expr/src/expressions/try_cast.rs +++ b/datafusion/physical-expr/src/expressions/try_cast.rs @@ -269,13 +269,13 @@ mod tests { DataType::Decimal128(10, 3), Decimal128Array, DataType::Decimal128(20, 6), - vec![ + [ Some(1_234_000), Some(2_222_000), Some(3_000), Some(4_000_000), Some(5_000_000), - None, + None ] ); @@ -285,7 +285,7 @@ mod tests { DataType::Decimal128(10, 3), Decimal128Array, DataType::Decimal128(10, 2), - vec![Some(123), Some(222), Some(0), Some(400), Some(500), None,] + [Some(123), Some(222), Some(0), Some(400), Some(500), None] ); Ok(()) @@ -303,13 +303,13 @@ mod tests { DataType::Decimal128(10, 0), Int8Array, DataType::Int8, - vec![ + [ Some(1_i8), Some(2_i8), Some(3_i8), Some(4_i8), Some(5_i8), - None, + None ] ); @@ -320,13 +320,13 @@ mod tests { DataType::Decimal128(10, 0), Int16Array, DataType::Int16, - vec![ + [ Some(1_i16), Some(2_i16), Some(3_i16), Some(4_i16), Some(5_i16), - None, + None ] ); @@ -337,13 +337,13 @@ mod tests { DataType::Decimal128(10, 0), Int32Array, DataType::Int32, - vec![ + [ Some(1_i32), Some(2_i32), Some(3_i32), Some(4_i32), Some(5_i32), - None, + None ] ); @@ -354,13 +354,13 @@ mod tests { DataType::Decimal128(10, 0), Int64Array, DataType::Int64, - vec![ + [ Some(1_i64), Some(2_i64), Some(3_i64), Some(4_i64), Some(5_i64), - None, + None ] ); @@ -372,13 +372,13 @@ mod tests { DataType::Decimal128(10, 3), Float32Array, DataType::Float32, - vec![ + [ Some(1.234_f32), Some(2.222_f32), Some(0.003_f32), Some(4.0_f32), Some(5.0_f32), - None, + None ] ); // decimal to float64 @@ -388,13 +388,13 @@ mod tests { DataType::Decimal128(20, 6), Float64Array, DataType::Float64, - vec![ + [ Some(0.001234_f64), Some(0.002222_f64), Some(0.000003_f64), Some(0.004_f64), Some(0.005_f64), - None, + None ] ); @@ -410,7 +410,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(3, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),] + [Some(1), Some(2), Some(3), Some(4), Some(5)] ); // int16 @@ -420,7 +420,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(5, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),] + [Some(1), Some(2), Some(3), Some(4), Some(5)] ); // int32 @@ -430,7 +430,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(10, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),] + [Some(1), Some(2), Some(3), Some(4), Some(5)] ); // int64 @@ -440,7 +440,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(20, 0), - vec![Some(1), Some(2), Some(3), Some(4), Some(5),] + [Some(1), Some(2), Some(3), Some(4), Some(5)] ); // int64 to different scale @@ -450,7 +450,7 @@ mod tests { vec![1, 2, 3, 4, 5], Decimal128Array, DataType::Decimal128(20, 2), - vec![Some(100), Some(200), Some(300), Some(400), Some(500),] + [Some(100), Some(200), Some(300), Some(400), Some(500)] ); // float32 @@ -460,7 +460,7 @@ mod tests { vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50], Decimal128Array, DataType::Decimal128(10, 2), - vec![Some(150), Some(250), Some(300), Some(112), Some(550),] + [Some(150), Some(250), Some(300), Some(112), Some(550)] ); // float64 @@ -470,12 +470,12 @@ mod tests { vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50], Decimal128Array, DataType::Decimal128(20, 4), - vec![ + [ Some(15000), Some(25000), Some(30000), Some(11235), - Some(55000), + Some(55000) ] ); Ok(()) @@ -489,7 +489,7 @@ mod tests { vec![1, 2, 3, 4, 5], UInt32Array, DataType::UInt32, - vec![ + [ Some(1_u32), Some(2_u32), Some(3_u32), @@ -508,7 +508,7 @@ mod tests { vec![1, 2, 3, 4, 5], StringArray, DataType::Utf8, - vec![Some("1"), Some("2"), Some("3"), Some("4"), Some("5")] + [Some("1"), Some("2"), Some("3"), Some("4"), Some("5")] ); Ok(()) } @@ -521,7 +521,7 @@ mod tests { vec!["a", "2", "3", "b", "5"], Int32Array, DataType::Int32, - vec![None, Some(2), Some(3), None, Some(5)] + [None, Some(2), Some(3), None, Some(5)] ); Ok(()) } diff --git a/datafusion/physical-expr/src/hash_utils.rs b/datafusion/physical-expr/src/hash_utils.rs index 59651c5cc903a..227caaf4aab4d 100644 --- a/datafusion/physical-expr/src/hash_utils.rs +++ b/datafusion/physical-expr/src/hash_utils.rs @@ -412,7 +412,7 @@ mod tests { // Tests actual values of hashes, which are different if forcing collisions #[cfg(not(feature = "force_hash_collisions"))] fn create_hashes_for_dict_arrays() { - let strings = vec![Some("foo"), None, Some("bar"), Some("foo"), None]; + let strings = [Some("foo"), None, Some("bar"), Some("foo"), None]; let string_array = Arc::new(strings.iter().cloned().collect::()); let dict_array = Arc::new( @@ -456,8 +456,8 @@ mod tests { // Tests actual values of hashes, which are different if forcing collisions #[cfg(not(feature = "force_hash_collisions"))] fn create_multi_column_hash_for_dict_arrays() { - let strings1 = vec![Some("foo"), None, Some("bar")]; - let strings2 = vec![Some("blarg"), Some("blah"), None]; + let strings1 = [Some("foo"), None, Some("bar")]; + let strings2 = [Some("blarg"), Some("blah"), None]; let string_array = Arc::new(strings1.iter().cloned().collect::()); let dict_array = Arc::new( diff --git a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs index 7a74e59b7c916..659a47da1504d 100644 --- a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs +++ b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs @@ -1445,7 +1445,7 @@ mod tests { ScalarValue::new_one(&DataType::Int8)?, ]; - zeros.into_iter().zip(ones.into_iter()).for_each(|(z, o)| { + zeros.into_iter().zip(ones).for_each(|(z, o)| { assert_eq!(next_value::(z.clone()), o); assert_eq!(next_value::(o), z); }); @@ -1461,7 +1461,7 @@ mod tests { ScalarValue::Float64(Some(1e-6)), ]; - values.into_iter().zip(eps.into_iter()).for_each(|(v, e)| { + values.into_iter().zip(eps).for_each(|(v, e)| { assert!(next_value::(v.clone()).sub(v.clone()).unwrap().lt(&e)); assert!(v.clone().sub(next_value::(v)).unwrap().lt(&e)); }); @@ -1476,7 +1476,7 @@ mod tests { ScalarValue::Int8(Some(i8::MAX)), ]; - min.into_iter().zip(max.into_iter()).for_each(|(min, max)| { + min.into_iter().zip(max).for_each(|(min, max)| { assert_eq!(next_value::(max.clone()), max); assert_eq!(next_value::(min.clone()), min); }); diff --git a/datafusion/physical-expr/src/window/built_in.rs b/datafusion/physical-expr/src/window/built_in.rs index 2958b21cad923..a00d32e201fbc 100644 --- a/datafusion/physical-expr/src/window/built_in.rs +++ b/datafusion/physical-expr/src/window/built_in.rs @@ -170,7 +170,7 @@ impl WindowExpr for BuiltInWindowExpr { row_wise_results.push(value); last_range = range; } - ScalarValue::iter_to_array(row_wise_results.into_iter()) + ScalarValue::iter_to_array(row_wise_results) } else if evaluator.include_rank() { let columns = self.order_by_columns(batch)?; let sort_partition_points = evaluate_partition_ranges(num_rows, &columns)?; diff --git a/datafusion/physical-expr/src/window/cume_dist.rs b/datafusion/physical-expr/src/window/cume_dist.rs index 49ed2a74dff66..edef77c51c315 100644 --- a/datafusion/physical-expr/src/window/cume_dist.rs +++ b/datafusion/physical-expr/src/window/cume_dist.rs @@ -117,6 +117,7 @@ mod tests { } #[test] + #[allow(clippy::single_range_in_vec_init)] fn test_cume_dist() -> Result<()> { let r = cume_dist("arr".into()); diff --git a/datafusion/physical-expr/src/window/lead_lag.rs b/datafusion/physical-expr/src/window/lead_lag.rs index 887dc4b66dbc6..16700d1eda8b4 100644 --- a/datafusion/physical-expr/src/window/lead_lag.rs +++ b/datafusion/physical-expr/src/window/lead_lag.rs @@ -273,7 +273,7 @@ mod tests { None, None, ), - vec![ + [ Some(-2), Some(3), Some(-4), @@ -295,7 +295,7 @@ mod tests { None, None, ), - vec![ + [ None, Some(1), Some(-2), @@ -317,7 +317,7 @@ mod tests { None, Some(ScalarValue::Int32(Some(100))), ), - vec![ + [ Some(100), Some(1), Some(-2), diff --git a/datafusion/physical-expr/src/window/rank.rs b/datafusion/physical-expr/src/window/rank.rs index e24bfee3c0609..9bc36728f46ef 100644 --- a/datafusion/physical-expr/src/window/rank.rs +++ b/datafusion/physical-expr/src/window/rank.rs @@ -227,6 +227,7 @@ mod tests { test_i32_result(expr, vec![0..2, 2..3, 3..6, 6..7, 7..8], expected) } + #[allow(clippy::single_range_in_vec_init)] fn test_without_rank(expr: &Rank, expected: Vec) -> Result<()> { test_i32_result(expr, vec![0..8], expected) } @@ -275,6 +276,7 @@ mod tests { } #[test] + #[allow(clippy::single_range_in_vec_init)] fn test_percent_rank() -> Result<()> { let r = percent_rank("arr".into()); diff --git a/datafusion/physical-expr/src/window/window_expr.rs b/datafusion/physical-expr/src/window/window_expr.rs index b0ea7d1b015d9..da67bcabee0b7 100644 --- a/datafusion/physical-expr/src/window/window_expr.rs +++ b/datafusion/physical-expr/src/window/window_expr.rs @@ -251,7 +251,7 @@ pub trait AggregateWindowExpr: WindowExpr { let out_type = field.data_type(); Ok(new_empty_array(out_type)) } else { - ScalarValue::iter_to_array(row_wise_results.into_iter()) + ScalarValue::iter_to_array(row_wise_results) } } } diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs index cab8f0f06e65b..5b9d6d87cf75c 100644 --- a/datafusion/sql/src/parser.rs +++ b/datafusion/sql/src/parser.rs @@ -1148,7 +1148,7 @@ mod tests { expect_parse_ok(sql, expected)?; // Ordered Col - let sqls = vec!["CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH ORDER (c1) LOCATION 'foo.csv'", + let sqls = ["CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH ORDER (c1) LOCATION 'foo.csv'", "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH ORDER (c1 NULLS FIRST) LOCATION 'foo.csv'", "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH ORDER (c1 NULLS LAST) LOCATION 'foo.csv'", "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH ORDER (c1 ASC) LOCATION 'foo.csv'", diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs index 3906bc20be7fd..c160388acffb7 100644 --- a/datafusion/sql/src/statement.rs +++ b/datafusion/sql/src/statement.rs @@ -533,10 +533,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { if !table_factor.joins.is_empty() { return not_impl_err!("DELETE FROM only supports single table, got: joins"); } - let TableFactor::Table{name, ..} = table_factor.relation else { + let TableFactor::Table { name, .. } = table_factor.relation else { return not_impl_err!( "DELETE FROM only supports single table, got: {table_factor:?}" - ) + ); }; Ok(name) diff --git a/datafusion/sql/tests/sql_integration.rs b/datafusion/sql/tests/sql_integration.rs index 68d953e822cae..8b4d9686a4f56 100644 --- a/datafusion/sql/tests/sql_integration.rs +++ b/datafusion/sql/tests/sql_integration.rs @@ -197,7 +197,7 @@ fn cast_to_invalid_decimal_type_precision_0() { let sql = "SELECT CAST(10 AS DECIMAL(0))"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Decimal(precision = 0, scale = 0) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"##, + r#"Plan("Decimal(precision = 0, scale = 0) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"#, format!("{err:?}") ); } @@ -210,7 +210,7 @@ fn cast_to_invalid_decimal_type_precision_gt_38() { let sql = "SELECT CAST(10 AS DECIMAL(39))"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Decimal(precision = 39, scale = 0) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"##, + r#"Plan("Decimal(precision = 39, scale = 0) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"#, format!("{err:?}") ); } @@ -223,7 +223,7 @@ fn cast_to_invalid_decimal_type_precision_lt_scale() { let sql = "SELECT CAST(10 AS DECIMAL(5, 10))"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Decimal(precision = 5, scale = 10) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"##, + r#"Plan("Decimal(precision = 5, scale = 10) should satisfy `0 < precision <= 38`, and `scale <= precision`.")"#, format!("{err:?}") ); } @@ -513,7 +513,7 @@ fn select_repeated_column() { let sql = "SELECT age, age FROM person"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"person.age\" at position 0 and \"person.age\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"person.age\" at position 0 and \"person.age\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } @@ -523,7 +523,7 @@ fn select_wildcard_with_repeated_column() { let sql = "SELECT *, age FROM person"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"person.age\" at position 3 and \"person.age\" at position 8 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"person.age\" at position 3 and \"person.age\" at position 8 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } @@ -1252,7 +1252,7 @@ fn select_simple_aggregate_repeated_aggregate() { let sql = "SELECT MIN(age), MIN(age) FROM person"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"MIN(person.age)\" at position 0 and \"MIN(person.age)\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"MIN(person.age)\" at position 0 and \"MIN(person.age)\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } @@ -1293,7 +1293,7 @@ fn select_simple_aggregate_repeated_aggregate_with_repeated_aliases() { let sql = "SELECT MIN(age) AS a, MIN(age) AS a FROM person"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"MIN(person.age) AS a\" at position 0 and \"MIN(person.age) AS a\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"MIN(person.age) AS a\" at position 0 and \"MIN(person.age) AS a\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } @@ -1323,7 +1323,7 @@ fn select_simple_aggregate_with_groupby_with_aliases_repeated() { let sql = "SELECT state AS a, MIN(age) AS a FROM person GROUP BY state"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"person.state AS a\" at position 0 and \"MIN(person.age) AS a\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"person.state AS a\" at position 0 and \"MIN(person.age) AS a\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } @@ -1460,7 +1460,7 @@ fn select_simple_aggregate_with_groupby_aggregate_repeated() { let sql = "SELECT state, MIN(age), MIN(age) FROM person GROUP BY state"; let err = logical_plan(sql).expect_err("query should have failed"); assert_eq!( - r##"Plan("Projections require unique expression names but the expression \"MIN(person.age)\" at position 1 and \"MIN(person.age)\" at position 2 have the same name. Consider aliasing (\"AS\") one of them.")"##, + r#"Plan("Projections require unique expression names but the expression \"MIN(person.age)\" at position 1 and \"MIN(person.age)\" at position 2 have the same name. Consider aliasing (\"AS\") one of them.")"#, format!("{err:?}") ); } diff --git a/datafusion/sqllogictest/src/engines/datafusion_engine/normalize.rs b/datafusion/sqllogictest/src/engines/datafusion_engine/normalize.rs index 85cd6fcd5422f..2ff5d27a183be 100644 --- a/datafusion/sqllogictest/src/engines/datafusion_engine/normalize.rs +++ b/datafusion/sqllogictest/src/engines/datafusion_engine/normalize.rs @@ -107,7 +107,7 @@ fn expand_row(mut row: Vec) -> impl Iterator> { }) .collect(); - Either::Right(once(row).chain(new_lines.into_iter())) + Either::Right(once(row).chain(new_lines)) } else { Either::Left(once(row)) } diff --git a/datafusion/substrait/src/logical_plan/consumer.rs b/datafusion/substrait/src/logical_plan/consumer.rs index 7580322e2069d..32cb1db4c312f 100644 --- a/datafusion/substrait/src/logical_plan/consumer.rs +++ b/datafusion/substrait/src/logical_plan/consumer.rs @@ -542,7 +542,7 @@ pub async fn from_substrait_sorts( let Some(direction) = SortDirection::from_i32(*d) else { return not_impl_err!( "Unsupported Substrait SortDirection value {d}" - ) + ); }; match direction { @@ -1250,27 +1250,21 @@ async fn make_datafusion_like( } let Some(ArgType::Value(expr_substrait)) = &f.arguments[0].arg_type else { - return not_impl_err!( - "Invalid arguments type for `{fn_name}` expr" - ) + return not_impl_err!("Invalid arguments type for `{fn_name}` expr"); }; let expr = from_substrait_rex(expr_substrait, input_schema, extensions) .await? .as_ref() .clone(); let Some(ArgType::Value(pattern_substrait)) = &f.arguments[1].arg_type else { - return not_impl_err!( - "Invalid arguments type for `{fn_name}` expr" - ) + return not_impl_err!("Invalid arguments type for `{fn_name}` expr"); }; let pattern = from_substrait_rex(pattern_substrait, input_schema, extensions) .await? .as_ref() .clone(); let Some(ArgType::Value(escape_char_substrait)) = &f.arguments[2].arg_type else { - return not_impl_err!( - "Invalid arguments type for `{fn_name}` expr" - ) + return not_impl_err!("Invalid arguments type for `{fn_name}` expr"); }; let escape_char_expr = from_substrait_rex(escape_char_substrait, input_schema, extensions) @@ -1280,7 +1274,7 @@ async fn make_datafusion_like( let Expr::Literal(ScalarValue::Utf8(escape_char)) = escape_char_expr else { return Err(DataFusionError::Substrait(format!( "Expect Utf8 literal for escape char, but found {escape_char_expr:?}", - ))) + ))); }; Ok(Arc::new(Expr::Like(Like { diff --git a/datafusion/substrait/src/logical_plan/producer.rs b/datafusion/substrait/src/logical_plan/producer.rs index cf7ab0cc844f7..74a0ba63df83d 100644 --- a/datafusion/substrait/src/logical_plan/producer.rs +++ b/datafusion/substrait/src/logical_plan/producer.rs @@ -1650,7 +1650,10 @@ mod test { println!("Checking round trip of {scalar:?}"); let substrait = to_substrait_literal(&scalar)?; - let Expression { rex_type: Some(RexType::Literal(substrait_literal)) } = substrait else { + let Expression { + rex_type: Some(RexType::Literal(substrait_literal)), + } = substrait + else { panic!("Expected Literal expression, got {substrait:?}"); };