MCPcopy Create free account
hub / github.com/apache/arrow-rs / generic_binary_with_non_zero_offset

Function generic_binary_with_non_zero_offset

arrow-string/src/substring.rs:538–567  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

536 }
537
538 fn generic_binary_with_non_zero_offset<O: OffsetSizeTrait>() {
539 let values = 0_u8..15;
540 let offsets = &[
541 O::zero(),
542 O::from_usize(5).unwrap(),
543 O::from_usize(10).unwrap(),
544 O::from_usize(15).unwrap(),
545 ];
546 // set the first and third element to be valid
547 let bitmap = [0b101_u8];
548
549 let offsets = OffsetBuffer::new(Buffer::from_slice_ref(offsets).into());
550 let values = Buffer::from_iter(values);
551 let nulls = Some(NullBuffer::new(BooleanBuffer::new(
552 Buffer::from(bitmap),
553 0,
554 3,
555 )));
556 // array is `[null, [10, 11, 12, 13, 14]]`
557 let array = GenericBinaryArray::<O>::new(offsets, values, nulls).slice(1, 2);
558 // result is `[null, [11, 12, 13, 14]]`
559 let result = substring(&array, 1, None).unwrap();
560 let result = result
561 .as_any()
562 .downcast_ref::<GenericBinaryArray<O>>()
563 .unwrap();
564 let expected =
565 GenericBinaryArray::<O>::from_opt_vec(vec![None, Some(&[11_u8, 12, 13, 14])]);
566 assert_eq!(result, &expected);
567 }
568
569 #[test]
570 fn binary_with_non_zero_offset() {

Callers

nothing calls this directly

Calls 4

substringFunction · 0.70
from_iterFunction · 0.50
sliceMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected