Skip to content

Commit b82ebd2

Browse files
authored
chore: fix cargo clippy in rust 1.86 (#3643)
1 parent 5338238 commit b82ebd2

20 files changed

Lines changed: 48 additions & 46 deletions

File tree

rust/lance-arrow/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ impl BufferExt for arrow_buffer::Buffer {
996996
let mut buf = MutableBuffer::with_capacity(size_bytes);
997997
let to_fill = size_bytes - bytes.len();
998998
buf.extend(bytes);
999-
buf.extend(std::iter::repeat(0_u8).take(to_fill));
999+
buf.extend(std::iter::repeat_n(0_u8, to_fill));
10001000
Self::from(buf)
10011001
}
10021002
}

rust/lance-datafusion/src/planner.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright The Lance Authors
3-
// SPDX-License-Identifier: Apache-2.0
4-
// SPDX-FileCopyrightText: Copyright The Lance Authors
53

64
//! Exec plan planner
75
@@ -790,7 +788,7 @@ impl Planner {
790788
/// TODO: use SqlToRel from Datafusion directly?
791789
fn try_decode_hex_literal(s: &str) -> Option<Vec<u8>> {
792790
let hex_bytes = s.as_bytes();
793-
let mut decoded_bytes = Vec::with_capacity((hex_bytes.len() + 1) / 2);
791+
let mut decoded_bytes = Vec::with_capacity(hex_bytes.len().div_ceil(2));
794792

795793
let start_idx = hex_bytes.len() % 2;
796794
if start_idx > 0 {

rust/lance-datagen/src/generator.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl ArrayGenerator for NullGenerator {
207207
}
208208
} else {
209209
let array_len = array.len();
210-
let num_validity_bytes = (array_len + 7) / 8;
210+
let num_validity_bytes = array_len.div_ceil(8);
211211
let mut null_count = 0;
212212
// Sampling the RNG once per bit is kind of slow so we do this to sample once
213213
// per byte. We only get 8 bits of RNG resolution but that should be good enough.
@@ -618,7 +618,7 @@ impl ArrayGenerator for RandomBooleanGenerator {
618618
length: RowCount,
619619
rng: &mut rand_xoshiro::Xoshiro256PlusPlus,
620620
) -> Result<Arc<dyn arrow_array::Array>, ArrowError> {
621-
let num_bytes = (length.0 + 7) / 8;
621+
let num_bytes = length.0.div_ceil(8);
622622
let mut bytes = vec![0; num_bytes as usize];
623623
rng.fill_bytes(&mut bytes);
624624
let bytes = BooleanBuffer::new(Buffer::from(bytes), 0, length.0 as usize);
@@ -822,9 +822,10 @@ impl ArrayGenerator for RandomBinaryGenerator {
822822
}
823823
let bytes = Buffer::from(bytes);
824824
if self.is_large {
825-
let offsets = OffsetBuffer::from_lengths(
826-
iter::repeat(self.bytes_per_element.0 as usize).take(length.0 as usize),
827-
);
825+
let offsets = OffsetBuffer::from_lengths(iter::repeat_n(
826+
self.bytes_per_element.0 as usize,
827+
length.0 as usize,
828+
));
828829
if self.scale_to_utf8 {
829830
// This is safe because we are only using printable characters
830831
unsafe {
@@ -840,9 +841,10 @@ impl ArrayGenerator for RandomBinaryGenerator {
840841
}
841842
}
842843
} else {
843-
let offsets = OffsetBuffer::from_lengths(
844-
iter::repeat(self.bytes_per_element.0 as usize).take(length.0 as usize),
845-
);
844+
let offsets = OffsetBuffer::from_lengths(iter::repeat_n(
845+
self.bytes_per_element.0 as usize,
846+
length.0 as usize,
847+
));
846848
if self.scale_to_utf8 {
847849
// This is safe because we are only using printable characters
848850
unsafe {
@@ -1047,7 +1049,7 @@ impl<T: ByteArrayType> ArrayGenerator for FixedBinaryGenerator<T> {
10471049
.copied(),
10481050
));
10491051
let offsets =
1050-
OffsetBuffer::from_lengths(iter::repeat(self.value.len()).take(length.0 as usize));
1052+
OffsetBuffer::from_lengths(iter::repeat_n(self.value.len(), length.0 as usize));
10511053
Ok(Arc::new(arrow_array::GenericByteArray::<T>::new(
10521054
offsets, bytes, None,
10531055
)))

rust/lance-encoding/src/data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ fn concat_dict_arrays(arrays: &[ArrayRef]) -> ArrayRef {
12801280
let array_refs = arrays.iter().map(|arr| arr.as_ref()).collect::<Vec<_>>();
12811281
match arrow_select::concat::concat(&array_refs) {
12821282
Ok(array) => array,
1283-
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError { .. }) => {
1283+
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError) => {
12841284
// Slow, but hopefully a corner case. Optimize later
12851285
let upscaled = array_refs
12861286
.iter()
@@ -1293,7 +1293,7 @@ fn concat_dict_arrays(arrays: &[ArrayRef]) -> ArrayRef {
12931293
),
12941294
) {
12951295
Ok(arr) => arr,
1296-
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError { .. }) => {
1296+
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError) => {
12971297
// Technically I think this means the input type was u64 already
12981298
unimplemented!("Dictionary arrays with more than 2^32 unique values")
12991299
}
@@ -1305,7 +1305,7 @@ fn concat_dict_arrays(arrays: &[ArrayRef]) -> ArrayRef {
13051305
// Can still fail if concat pushes over u32 boundary
13061306
match arrow_select::concat::concat(&array_refs) {
13071307
Ok(array) => array,
1308-
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError { .. }) => {
1308+
Err(arrow_schema::ArrowError::DictionaryKeyOverflowError) => {
13091309
unimplemented!("Dictionary arrays with more than 2^32 unique values")
13101310
}
13111311
err => err.unwrap(),

rust/lance-encoding/src/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ pub trait PageScheduler: Send + Sync + std::fmt::Debug {
21842184
/// # Arguments
21852185
///
21862186
/// * `range` - the range of row offsets (relative to start of page) requested
2187-
/// these must be ordered and must not overlap
2187+
/// these must be ordered and must not overlap
21882188
/// * `scheduler` - a scheduler to submit the I/O request to
21892189
/// * `top_level_row` - the row offset of the top level field currently being
21902190
/// scheduled. This can be used to assign priority to I/O requests

rust/lance-encoding/src/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ pub trait ArrayEncodingStrategy: Send + Sync + std::fmt::Debug {
425425
/// width data block. In other words, there is some number of bits per value.
426426
/// In addition, each value should be independently decompressible.
427427
/// - Mini-block compression results in a small block of opaque data for chunks
428-
/// of rows. Each block is somewhere between 0 and 16KiB in size. This is
429-
/// used for narrow data types (both fixed and variable length) where we can
430-
/// fit many values into an 16KiB block.
428+
/// of rows. Each block is somewhere between 0 and 16KiB in size. This is
429+
/// used for narrow data types (both fixed and variable length) where we can
430+
/// fit many values into an 16KiB block.
431431
pub trait CompressionStrategy: Send + Sync + std::fmt::Debug {
432432
/// Create a block compressor for the given data
433433
fn create_block_compressor(

rust/lance-encoding/src/encodings/logical/primitive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl DecodeMiniBlockTask {
364364
// with 0 (valid)
365365
let mut new_levels_vec =
366366
LevelBuffer::with_capacity(dest_offset + (range.end - range.start) as usize);
367-
new_levels_vec.extend(iter::repeat(0).take(dest_offset));
367+
new_levels_vec.extend(iter::repeat_n(0, dest_offset));
368368
*levels = Some(new_levels_vec);
369369
}
370370
levels.as_mut().unwrap().extend(
@@ -376,7 +376,7 @@ impl DecodeMiniBlockTask {
376376
let num_values = (range.end - range.start) as usize;
377377
// This is an all-valid level_buf but we had nulls earlier and so we
378378
// need to materialize it
379-
levels.extend(iter::repeat(0).take(num_values));
379+
levels.extend(iter::repeat_n(0, num_values));
380380
}
381381
}
382382

@@ -3690,7 +3690,7 @@ impl PrimitiveStructuralEncoder {
36903690
// Pad
36913691
let add_padding = |data_buffer: &mut Vec<u8>| {
36923692
let pad = pad_bytes::<MINIBLOCK_ALIGNMENT>(data_buffer.len());
3693-
data_buffer.extend(iter::repeat(FILL_BYTE).take(pad));
3693+
data_buffer.extend(iter::repeat_n(FILL_BYTE, pad));
36943694
};
36953695
add_padding(&mut data_buffer);
36963696

rust/lance-encoding/src/encodings/physical/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl BinaryMiniBlockEncoder {
612612
let this_chunk_size = (num_values_in_this_chunk + 1) * 4
613613
+ (offsets[offsets.len() - 1] - offsets[last_offset_in_orig_idx]) as usize;
614614

615-
let padded_chunk_size = ((this_chunk_size + 3) / 4) * 4;
615+
let padded_chunk_size = this_chunk_size.next_multiple_of(4);
616616

617617
// the bytes are put after the offsets
618618
let this_chunk_bytes_start_offset = (num_values_in_this_chunk + 1) * 4;
@@ -636,7 +636,7 @@ impl BinaryMiniBlockEncoder {
636636
+ (offsets[this_last_offset_in_orig_idx] - offsets[last_offset_in_orig_idx])
637637
as usize;
638638

639-
let padded_chunk_size = ((this_chunk_size + 3) / 4) * 4;
639+
let padded_chunk_size = this_chunk_size.next_multiple_of(4);
640640

641641
// the bytes are put after the offsets
642642
let this_chunk_bytes_start_offset = (num_values_in_this_chunk + 1) * 4;

rust/lance-encoding/src/encodings/physical/bitpack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ enum StartOffset {
530530
/// * `buffer_len` - length buf buffer (in bytes)
531531
/// * `bits_per_value` - number of bits used to represent a single bitpacked value
532532
/// * `buffer_start_bit_offset` - offset of the start of the first value within the
533-
/// buffer's first byte
533+
/// buffer's first byte
534534
/// * `buffer_end_bit_offset` - end bit of the last value within the buffer. Can be
535-
/// `None` if the end of the last value is byte aligned with end of buffer.
535+
/// `None` if the end of the last value is byte aligned with end of buffer.
536536
fn compute_start_offset(
537537
rows_to_skip: u64,
538538
buffer_len: usize,

rust/lance-encoding/src/repdef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl SerializerContext {
735735
.zip(
736736
validity
737737
.iter()
738-
.flat_map(|v| std::iter::repeat(v).take(self.current_multiplier)),
738+
.flat_map(|v| std::iter::repeat_n(v, self.current_multiplier)),
739739
)
740740
.for_each(|(def, valid)| {
741741
if !valid {

0 commit comments

Comments
 (0)