Skip to content

Commit df730fd

Browse files
authored
Merge branch 'main' into safer-appendvalue-bytes-view
2 parents bfe53a8 + d49f017 commit df730fd

File tree

3 files changed

+206
-68
lines changed

3 files changed

+206
-68
lines changed

arrow-buffer/src/util/bit_chunk_iterator.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ pub struct BitChunks<'a> {
221221
impl<'a> BitChunks<'a> {
222222
/// Create a new [`BitChunks`] from a byte array, and an offset and length in bits
223223
pub fn new(buffer: &'a [u8], offset: usize, len: usize) -> Self {
224-
assert!(ceil(offset + len, 8) <= buffer.len() * 8);
224+
assert!(
225+
ceil(offset + len, 8) <= buffer.len(),
226+
"offset + len out of bounds"
227+
);
225228

226229
let byte_offset = offset / 8;
227230
let bit_offset = offset % 8;
@@ -476,6 +479,57 @@ mod tests {
476479
assert_eq!(0x7F, bitchunks.remainder_bits());
477480
}
478481

482+
#[test]
483+
#[should_panic(expected = "offset + len out of bounds")]
484+
fn test_out_of_bound_should_panic_length_is_more_than_buffer_length() {
485+
const ALLOC_SIZE: usize = 4 * 1024;
486+
let input = vec![0xFF_u8; ALLOC_SIZE];
487+
488+
let buffer: Buffer = Buffer::from_vec(input);
489+
490+
// We are reading more than exists in the buffer
491+
buffer.bit_chunks(0, (ALLOC_SIZE + 1) * 8);
492+
}
493+
494+
#[test]
495+
#[should_panic(expected = "offset + len out of bounds")]
496+
fn test_out_of_bound_should_panic_length_is_more_than_buffer_length_but_not_when_not_using_ceil()
497+
{
498+
const ALLOC_SIZE: usize = 4 * 1024;
499+
let input = vec![0xFF_u8; ALLOC_SIZE];
500+
501+
let buffer: Buffer = Buffer::from_vec(input);
502+
503+
// We are reading more than exists in the buffer
504+
buffer.bit_chunks(0, (ALLOC_SIZE * 8) + 1);
505+
}
506+
507+
#[test]
508+
#[should_panic(expected = "offset + len out of bounds")]
509+
fn test_out_of_bound_should_panic_when_offset_is_not_zero_and_length_is_the_entire_buffer_length()
510+
{
511+
const ALLOC_SIZE: usize = 4 * 1024;
512+
let input = vec![0xFF_u8; ALLOC_SIZE];
513+
514+
let buffer: Buffer = Buffer::from_vec(input);
515+
516+
// We are reading more than exists in the buffer
517+
buffer.bit_chunks(8, ALLOC_SIZE * 8);
518+
}
519+
520+
#[test]
521+
#[should_panic(expected = "offset + len out of bounds")]
522+
fn test_out_of_bound_should_panic_when_offset_is_not_zero_and_length_is_the_entire_buffer_length_with_ceil()
523+
{
524+
const ALLOC_SIZE: usize = 4 * 1024;
525+
let input = vec![0xFF_u8; ALLOC_SIZE];
526+
527+
let buffer: Buffer = Buffer::from_vec(input);
528+
529+
// We are reading more than exists in the buffer
530+
buffer.bit_chunks(1, ALLOC_SIZE * 8);
531+
}
532+
479533
#[test]
480534
#[allow(clippy::assertions_on_constants)]
481535
fn test_unaligned_bit_chunk_iterator() {

parquet-variant-compute/src/variant_array.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl ExtensionType for VariantType {
208208
/// assert_eq!(variant_array.value(0), Variant::from("such wow"));
209209
/// ```
210210
///
211-
#[derive(Clone, Debug)]
211+
#[derive(Debug, Clone, PartialEq)]
212212
pub struct VariantArray {
213213
/// Reference to the underlying StructArray
214214
inner: StructArray,
@@ -741,7 +741,7 @@ impl From<ShreddedVariantFieldArray> for StructArray {
741741
/// (partial shredding).
742742
///
743743
/// [Parquet Variant Shredding Spec]: https://github.com/apache/parquet-format/blob/master/VariantShredding.md#value-shredding
744-
#[derive(Clone, Debug)]
744+
#[derive(Debug, Clone, PartialEq)]
745745
pub struct ShreddingState {
746746
value: Option<BinaryViewArray>,
747747
typed_value: Option<ArrayRef>,
@@ -1467,4 +1467,27 @@ mod test {
14671467
Variant::ShortString(ShortString::try_new("norm").unwrap())
14681468
);
14691469
}
1470+
1471+
#[test]
1472+
fn test_variant_equality() {
1473+
let v_iter = [None, Some(Variant::BooleanFalse), Some(Variant::Null), None];
1474+
let v = VariantArray::from_iter(v_iter.clone());
1475+
1476+
{
1477+
let v_copy = v.clone();
1478+
assert_eq!(v, v_copy);
1479+
}
1480+
1481+
{
1482+
let v_iter_reversed = v_iter.iter().cloned().rev();
1483+
let v_reversed = VariantArray::from_iter(v_iter_reversed);
1484+
1485+
assert_ne!(v, v_reversed);
1486+
}
1487+
1488+
{
1489+
let v_sliced = v.slice(0, 1);
1490+
assert_ne!(v, v_sliced);
1491+
}
1492+
}
14701493
}

0 commit comments

Comments
 (0)