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

Function test_byte_array_decoder

parquet/src/arrow/array_reader/byte_array.rs:622–674  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

620
621 #[test]
622 fn test_byte_array_decoder() {
623 let (pages, encoded_dictionary) =
624 byte_array_all_encodings(vec!["hello", "world", "a", "b"]);
625
626 let column_desc = utf8_column();
627 let mut decoder = ByteArrayColumnValueDecoder::new(&column_desc);
628
629 decoder
630 .set_dict(encoded_dictionary, 4, Encoding::RLE_DICTIONARY, false)
631 .unwrap();
632
633 for (encoding, page) in pages {
634 let mut output = OffsetBuffer::<i32>::with_capacity(0);
635 decoder.set_data(encoding, page, 4, Some(4)).unwrap();
636
637 assert_eq!(decoder.read(&mut output, 1).unwrap(), 1);
638
639 assert_eq!(output.values.as_slice(), "hello".as_bytes());
640 assert_eq!(output.offsets.as_slice(), &[0, 5]);
641
642 assert_eq!(decoder.read(&mut output, 1).unwrap(), 1);
643 assert_eq!(output.values.as_slice(), "helloworld".as_bytes());
644 assert_eq!(output.offsets.as_slice(), &[0, 5, 10]);
645
646 assert_eq!(decoder.read(&mut output, 2).unwrap(), 2);
647 assert_eq!(output.values.as_slice(), "helloworldab".as_bytes());
648 assert_eq!(output.offsets.as_slice(), &[0, 5, 10, 11, 12]);
649
650 assert_eq!(decoder.read(&mut output, 4).unwrap(), 0);
651
652 let valid = [false, false, true, true, false, true, true, false, false];
653 let valid_buffer = Buffer::from_iter(valid.iter().cloned());
654
655 output.pad_nulls(0, 4, valid.len(), valid_buffer.as_slice());
656 let array = output.into_array(Some(valid_buffer), ArrowType::Utf8);
657 let strings = array.as_any().downcast_ref::<StringArray>().unwrap();
658
659 assert_eq!(
660 strings.iter().collect::<Vec<_>>(),
661 vec![
662 None,
663 None,
664 Some("hello"),
665 Some("world"),
666 None,
667 Some("a"),
668 Some("b"),
669 None,
670 None,
671 ]
672 );
673 }
674 }
675
676 #[test]
677 fn test_byte_array_decoder_skip() {

Callers

nothing calls this directly

Calls 11

byte_array_all_encodingsFunction · 0.85
utf8_columnFunction · 0.85
from_iterFunction · 0.50
set_dictMethod · 0.45
set_dataMethod · 0.45
iterMethod · 0.45
pad_nullsMethod · 0.45
lenMethod · 0.45
as_sliceMethod · 0.45
into_arrayMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected