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

Function test_enum_decoding

arrow-avro/src/reader/record.rs:3745–3772  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3743
3744 #[test]
3745 fn test_enum_decoding() {
3746 let symbols: Arc<[String]> = vec!["A", "B", "C"].into_iter().map(String::from).collect();
3747 let avro_type = avro_from_codec(Codec::Enum(symbols.clone()));
3748 let mut decoder = Decoder::try_new(&avro_type).unwrap();
3749 let mut data = Vec::new();
3750 data.extend_from_slice(&encode_avro_int(2));
3751 data.extend_from_slice(&encode_avro_int(0));
3752 data.extend_from_slice(&encode_avro_int(1));
3753 let mut cursor = AvroCursor::new(&data);
3754 decoder.decode(&mut cursor).unwrap();
3755 decoder.decode(&mut cursor).unwrap();
3756 decoder.decode(&mut cursor).unwrap();
3757 let array = decoder.flush(None).unwrap();
3758 let dict_array = array
3759 .as_any()
3760 .downcast_ref::<DictionaryArray<Int32Type>>()
3761 .unwrap();
3762 assert_eq!(dict_array.len(), 3);
3763 let values = dict_array
3764 .values()
3765 .as_any()
3766 .downcast_ref::<StringArray>()
3767 .unwrap();
3768 assert_eq!(values.value(0), "A");
3769 assert_eq!(values.value(1), "B");
3770 assert_eq!(values.value(2), "C");
3771 assert_eq!(dict_array.keys().values(), &[2, 0, 1]);
3772 }
3773
3774 #[test]
3775 fn test_enum_decoding_with_nulls() {

Callers

nothing calls this directly

Calls 12

avro_from_codecFunction · 0.85
EnumClass · 0.85
try_newFunction · 0.85
encode_avro_intFunction · 0.85
collectMethod · 0.80
extend_from_sliceMethod · 0.80
into_iterMethod · 0.45
cloneMethod · 0.45
decodeMethod · 0.45
flushMethod · 0.45
as_anyMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected