Skip to content

Commit

Permalink
Clean up clippy for Rust 1.72 release (#7399)
Browse files Browse the repository at this point in the history
* Clean up clippy for rust 1.72 release

* fix a few stragglers
  • Loading branch information
alamb authored Aug 24, 2023
1 parent 50b1fac commit 3f8c512
Show file tree
Hide file tree
Showing 85 changed files with 696 additions and 903 deletions.
1 change: 1 addition & 0 deletions datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 14 additions & 12 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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());

Expand Down Expand Up @@ -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)]);
Expand Down Expand Up @@ -3640,7 +3642,7 @@ mod tests {
fn scalar_iter_to_array_empty() {
let scalars = vec![] as Vec<ScalarValue>;

let result = ScalarValue::iter_to_array(scalars.into_iter()).unwrap_err();
let result = ScalarValue::iter_to_array(scalars).unwrap_err();
assert!(
result
.to_string()
Expand All @@ -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::<Int32Type>(&array).unwrap();
let values_array = as_string_array(array.values()).unwrap();

Expand All @@ -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<ScalarValue> = 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);
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/benches/data_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = (0..batch_size)
.map(
// use random numbers to avoid spurious compiler optimizations wrt to branching
Expand Down
10 changes: 5 additions & 5 deletions datafusion/core/benches/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/catalog/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod tests {

let actual = df.collect().await.unwrap();

let expected = vec![
let expected = [
"+----+----------+",
"| id | bool_col |",
"+----+----------+",
Expand Down
64 changes: 30 additions & 34 deletions datafusion/core/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -1354,17 +1354,15 @@ mod tests {
let df: Vec<RecordBatch> = 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 |",
"| b | 0.04893135681998029 | 0.9185813970744787 | 0.41040709263815384 | 7.797734760124923 | 19 | 19 |",
"| 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
);

Expand Down Expand Up @@ -1403,17 +1401,15 @@ mod tests {

#[rustfmt::skip]
assert_batches_sorted_eq!(
vec![
"+----+",
["+----+",
"| c1 |",
"+----+",
"| a |",
"| b |",
"| c |",
"| d |",
"| e |",
"+----+",
],
"+----+"],
&df_results
);

Expand Down Expand Up @@ -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) |",
"+----+-----------------------------+",
Expand All @@ -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) |",
"+----+---------------------+",
Expand All @@ -1661,7 +1657,7 @@ mod tests {
"| c | 13.860958726523545 |",
"| d | 8.793968289758968 |",
"| e | 10.206140546981722 |",
"+----+---------------------+",
"+----+---------------------+"
],
table_results
);
Expand Down Expand Up @@ -1719,7 +1715,7 @@ mod tests {
let df_results = df.clone().collect().await?;

assert_batches_sorted_eq!(
vec![
[
"+----+----+-----+-----+",
"| c1 | c2 | c3 | sum |",
"+----+----+-----+-----+",
Expand All @@ -1729,7 +1725,7 @@ mod tests {
"| a | 3 | 13 | 16 |",
"| a | 3 | 14 | 17 |",
"| a | 3 | 17 | 20 |",
"+----+----+-----+-----+",
"+----+----+-----+-----+"
],
&df_results
);
Expand All @@ -1742,7 +1738,7 @@ mod tests {
.await?;

assert_batches_sorted_eq!(
vec![
[
"+-----+----+-----+-----+",
"| c1 | c2 | c3 | sum |",
"+-----+----+-----+-----+",
Expand All @@ -1752,7 +1748,7 @@ mod tests {
"| 16 | 3 | 13 | 16 |",
"| 17 | 3 | 14 | 17 |",
"| 20 | 3 | 17 | 20 |",
"+-----+----+-----+-----+",
"+-----+----+-----+-----+"
],
&df_results_overwrite
);
Expand All @@ -1765,7 +1761,7 @@ mod tests {
.await?;

assert_batches_sorted_eq!(
vec![
[
"+----+----+-----+-----+",
"| c1 | c2 | c3 | sum |",
"+----+----+-----+-----+",
Expand All @@ -1775,7 +1771,7 @@ mod tests {
"| a | 4 | 13 | 16 |",
"| a | 4 | 14 | 17 |",
"| a | 4 | 17 | 20 |",
"+----+----+-----+-----+",
"+----+----+-----+-----+"
],
&df_results_overwrite_self
);
Expand Down Expand Up @@ -1810,12 +1806,12 @@ mod tests {
.await?;

assert_batches_sorted_eq!(
vec![
[
"+-----+-----+----+-------+",
"| one | two | c3 | total |",
"+-----+-----+----+-------+",
"| a | 3 | 13 | 16 |",
"+-----+-----+----+-------+",
"+-----+-----+----+-------+"
],
&df_sum_renamed
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -1961,12 +1957,12 @@ mod tests {
let res = &df_renamed.clone().collect().await?;

assert_batches_sorted_eq!(
vec![
[
"+---------+",
"| CoLuMn1 |",
"+---------+",
"| a |",
"+---------+",
"+---------+"
],
res
);
Expand All @@ -1977,7 +1973,7 @@ mod tests {
.await?;

assert_batches_sorted_eq!(
vec!["+----+", "| c1 |", "+----+", "| a |", "+----+",],
["+----+", "| c1 |", "+----+", "| a |", "+----+"],
&df_renamed
);

Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand All @@ -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
);
Expand Down
Loading

0 comments on commit 3f8c512

Please sign in to comment.