Skip to content

Commit

Permalink
Fix some clippy errors after updating rust toolchain (#3010)
Browse files Browse the repository at this point in the history
* Fix clippy

* More

* More
  • Loading branch information
viirya authored Nov 3, 2022
1 parent 61cf6f7 commit 01ea8c7
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 82 deletions.
2 changes: 1 addition & 1 deletion arrow-array/src/array/binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ mod tests {
#[test]
#[should_panic(expected = "LargeBinaryArray expects DataType::LargeBinary")]
fn test_binary_array_validation() {
let array = BinaryArray::from_iter_values(&[&[1, 2]]);
let array = BinaryArray::from_iter_values([&[1, 2]]);
let _ = LargeBinaryArray::from(array.into_data());
}

Expand Down
6 changes: 3 additions & 3 deletions arrow-schema/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ impl Field {
/// within `self` contained within this field (including `self`)
pub(crate) fn fields(&self) -> Vec<&Field> {
let mut collected_fields = vec![self];
collected_fields.append(&mut self._fields(&self.data_type));
collected_fields.append(&mut Field::_fields(&self.data_type));

collected_fields
}

fn _fields<'a>(&'a self, dt: &'a DataType) -> Vec<&Field> {
fn _fields(dt: &DataType) -> Vec<&Field> {
match dt {
DataType::Struct(fields) | DataType::Union(fields, _, _) => {
fields.iter().flat_map(|f| f.fields()).collect()
Expand All @@ -214,7 +214,7 @@ impl Field {
| DataType::LargeList(field)
| DataType::FixedSizeList(field, _)
| DataType::Map(field, _) => field.fields(),
DataType::Dictionary(_, value_field) => self._fields(value_field.as_ref()),
DataType::Dictionary(_, value_field) => Field::_fields(value_field.as_ref()),
_ => vec![],
}
}
Expand Down
4 changes: 2 additions & 2 deletions arrow/benches/lexsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ fn add_benchmark(c: &mut Criterion) {
];

for case in cases {
do_bench(c, *case, 4096);
do_bench(c, *case, 4096 * 8);
do_bench(c, case, 4096);
do_bench(c, case, 4096 * 8);
}
}

Expand Down
28 changes: 8 additions & 20 deletions arrow/src/compute/kernels/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,45 +174,33 @@ mod tests {
let median = input[input.len() / 2];
assert_eq!(
9,
partition_point(
0,
input.len(),
&(|i: usize| input[i].cmp(&median) != Ordering::Greater)
)
partition_point(0, input.len(), |i: usize| input[i].cmp(&median)
!= Ordering::Greater)
);
}
{
let search = input[9];
assert_eq!(
12,
partition_point(
9,
input.len(),
&(|i: usize| input[i].cmp(&search) != Ordering::Greater)
)
partition_point(9, input.len(), |i: usize| input[i].cmp(&search)
!= Ordering::Greater)
);
}
{
let search = input[0];
assert_eq!(
3,
partition_point(
0,
9,
&(|i: usize| input[i].cmp(&search) != Ordering::Greater)
)
partition_point(0, 9, |i: usize| input[i].cmp(&search)
!= Ordering::Greater)
);
}
let input = &[1, 2, 2, 2, 2, 2, 2, 2, 9];
{
let search = input[5];
assert_eq!(
8,
partition_point(
5,
9,
&(|i: usize| input[i].cmp(&search) != Ordering::Greater)
)
partition_point(5, 9, |i: usize| input[i].cmp(&search)
!= Ordering::Greater)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/csv/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ mod tests {
let actual = result.unwrap_err().to_string();

assert!(
actual.contains(&expected),
actual.contains(expected),
"actual: '{}', expected: '{}'",
actual,
expected
Expand Down
6 changes: 1 addition & 5 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,7 @@ impl FFI_ArrowArray {
// If the layout has a null buffer by Arrow spec.
// Note that even the array doesn't have a null buffer because it has
// no null value, we still need to count 1 here to follow the spec.
if data_layout.can_contain_null_mask {
1
} else {
0
}
usize::from(data_layout.can_contain_null_mask)
}
} as i64;

Expand Down
5 changes: 2 additions & 3 deletions arrow/src/ipc/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ pub(crate) fn build_field<'a>(
};

let fb_field_name = fbb.create_string(field.name().as_str());
let field_type = get_fb_field_type(field.data_type(), field.is_nullable(), fbb);
let field_type = get_fb_field_type(field.data_type(), fbb);

let fb_dictionary = if let Dictionary(index_type, _) = field.data_type() {
Some(get_fb_dictionary(
Expand Down Expand Up @@ -477,7 +477,6 @@ pub(crate) fn build_field<'a>(
/// Get the IPC type of a data type
pub(crate) fn get_fb_field_type<'a>(
data_type: &DataType,
is_nullable: bool,
fbb: &mut FlatBufferBuilder<'a>,
) -> FBFieldType<'a> {
// some IPC implementations expect an empty list for child data, instead of a null value.
Expand Down Expand Up @@ -717,7 +716,7 @@ pub(crate) fn get_fb_field_type<'a>(
// In this library, the dictionary "type" is a logical construct. Here we
// pass through to the value type, as we've already captured the index
// type in the DictionaryEncoding metadata in the parent field
get_fb_field_type(value_type, is_nullable, fbb)
get_fb_field_type(value_type, fbb)
}
Decimal128(precision, scale) => {
let mut builder = ipc::DecimalBuilder::new(fbb);
Expand Down
6 changes: 3 additions & 3 deletions arrow/src/json/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ impl Decoder {
fn build_boolean_array(&self, rows: &[Value], col_name: &str) -> Result<ArrayRef> {
let mut builder = BooleanBuilder::with_capacity(rows.len());
for row in rows {
if let Some(value) = row.get(&col_name) {
if let Some(value) = row.get(col_name) {
if let Some(boolean) = value.as_bool() {
builder.append_value(boolean);
} else {
Expand Down Expand Up @@ -993,7 +993,7 @@ impl Decoder {
Ok(Arc::new(
rows.iter()
.map(|row| {
row.get(&col_name).and_then(|value| {
row.get(col_name).and_then(|value| {
if value.is_i64() {
value.as_i64().and_then(num::cast::cast)
} else if value.is_u64() {
Expand Down Expand Up @@ -1496,7 +1496,7 @@ impl Decoder {
let mut builder: StringDictionaryBuilder<T> =
self.build_string_dictionary_builder(rows.len());
for row in rows {
if let Some(value) = row.get(&col_name) {
if let Some(value) = row.get(col_name) {
if let Some(str_v) = value.as_str() {
builder.append(str_v).map(drop)?
} else {
Expand Down
4 changes: 2 additions & 2 deletions arrow/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> {
));
}

if strides != None {
if strides.is_some() {
return Err(ArrowError::InvalidArgumentError(
"expected None strides for tensor with no shape".to_string(),
));
}

if names != None {
if names.is_some() {
return Err(ArrowError::InvalidArgumentError(
"expected None names for tensor with no shape".to_string(),
));
Expand Down
6 changes: 3 additions & 3 deletions arrow/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {

let mut header = Vec::new();
for field in schema.fields() {
header.push(Cell::new(&field.name()));
header.push(Cell::new(field.name()));
}
table.set_header(header);

Expand Down Expand Up @@ -317,9 +317,9 @@ mod tests {

let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 3);

builder.append_value(&[1, 2, 3]).unwrap();
builder.append_value([1, 2, 3]).unwrap();
builder.append_null();
builder.append_value(&[7, 8, 9]).unwrap();
builder.append_value([7, 8, 9]).unwrap();

let array = Arc::new(builder.finish());

Expand Down
56 changes: 28 additions & 28 deletions arrow/tests/array_equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ fn create_list_array<U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(data: T) -> ArrayDa

#[test]
fn test_list_equal() {
let a = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let b = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let a = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let b = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
test_equal(&a, &b, true);

let b = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 7])]);
let b = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 7])]);
test_equal(&a, &b, false);
}

Expand Down Expand Up @@ -448,11 +448,11 @@ fn test_empty_offsets_list_equal() {
// Test the case where null_count > 0
#[test]
fn test_list_null() {
let a = create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
let b = create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
let a = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
test_equal(&a, &b, true);

let b = create_list_array(&[
let b = create_list_array([
Some(&[1, 2]),
None,
Some(&[5, 6]),
Expand All @@ -462,7 +462,7 @@ fn test_list_null() {
]);
test_equal(&a, &b, false);

let b = create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]);
let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]);
test_equal(&a, &b, false);

// a list where the nullness of values is determined by the list's bitmap
Expand Down Expand Up @@ -506,8 +506,8 @@ fn test_list_null() {
// Test the case where offset != 0
#[test]
fn test_list_offsets() {
let a = create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
let b = create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]);
let a = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]);
let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]);

let a_slice = a.slice(0, 3);
let b_slice = b.slice(0, 3);
Expand Down Expand Up @@ -539,40 +539,40 @@ fn create_fixed_size_binary_array<U: AsRef<[u8]>, T: AsRef<[Option<U>]>>(

#[test]
fn test_fixed_size_binary_equal() {
let a = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world")]);
let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world")]);
let a = create_fixed_size_binary_array([Some(b"hello"), Some(b"world")]);
let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"world")]);
test_equal(&a, &b, true);

let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"arrow")]);
let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"arrow")]);
test_equal(&a, &b, false);
}

// Test the case where null_count > 0
#[test]
fn test_fixed_size_binary_null() {
let a = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"world")]);
let b = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"world")]);
let a = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"world")]);
let b = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"world")]);
test_equal(&a, &b, true);

let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world"), None]);
let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"world"), None]);
test_equal(&a, &b, false);

let b = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"arrow")]);
let b = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"arrow")]);
test_equal(&a, &b, false);
}

#[test]
fn test_fixed_size_binary_offsets() {
// Test the case where offset != 0
let a = create_fixed_size_binary_array(&[
let a = create_fixed_size_binary_array([
Some(b"hello"),
None,
None,
Some(b"world"),
None,
None,
]);
let b = create_fixed_size_binary_array(&[
let b = create_fixed_size_binary_array([
Some(b"hello"),
None,
None,
Expand Down Expand Up @@ -706,26 +706,26 @@ fn create_fixed_size_list_array<U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(

#[test]
fn test_fixed_size_list_equal() {
let a = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let b = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let a = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
let b = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]);
test_equal(&a, &b, true);

let b = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 7])]);
let b = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 7])]);
test_equal(&a, &b, false);
}

// Test the case where null_count > 0
#[test]
fn test_fixed_list_null() {
let a = create_fixed_size_list_array(&[
let a = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
None,
Some(&[4, 5, 6]),
None,
None,
]);
let b = create_fixed_size_list_array(&[
let b = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
None,
Expand All @@ -735,7 +735,7 @@ fn test_fixed_list_null() {
]);
test_equal(&a, &b, true);

let b = create_fixed_size_list_array(&[
let b = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
Some(&[7, 8, 9]),
Expand All @@ -745,7 +745,7 @@ fn test_fixed_list_null() {
]);
test_equal(&a, &b, false);

let b = create_fixed_size_list_array(&[
let b = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
None,
Expand All @@ -755,7 +755,7 @@ fn test_fixed_list_null() {
]);
test_equal(&a, &b, false);

let b = create_fixed_size_list_array(&[None, Some(&[4, 5, 6]), None, None]);
let b = create_fixed_size_list_array([None, Some(&[4, 5, 6]), None, None]);

test_equal(&a.slice(2, 4), &b, true);
test_equal(&a.slice(3, 3), &b.slice(1, 3), true);
Expand All @@ -764,15 +764,15 @@ fn test_fixed_list_null() {
#[test]
fn test_fixed_list_offsets() {
// Test the case where offset != 0
let a = create_fixed_size_list_array(&[
let a = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
None,
Some(&[4, 5, 6]),
None,
None,
]);
let b = create_fixed_size_list_array(&[
let b = create_fixed_size_list_array([
Some(&[1, 2, 3]),
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion parquet/src/bin/parquet-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() {
)
} else {
let path = Path::new(&filename);
let file = File::open(&path).expect("Unable to open file");
let file = File::open(path).expect("Unable to open file");
Box::new(SerializedFileReader::new(file).expect("Failed to create reader"))
};

Expand Down
Loading

0 comments on commit 01ea8c7

Please sign in to comment.