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

Function struct_encoder_two_fields

arrow-avro/src/writer/encoder.rs:2564–2599  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2562
2563 #[test]
2564 fn struct_encoder_two_fields() {
2565 // Struct { a: Int32, b: Utf8 }
2566 let a = Int32Array::from(vec![1, 2]);
2567 let b = StringArray::from(vec!["x", "y"]);
2568 let fields = Fields::from(vec![
2569 Field::new("a", DataType::Int32, true),
2570 Field::new("b", DataType::Utf8, true),
2571 ]);
2572 let struct_arr = StructArray::new(
2573 fields.clone(),
2574 vec![Arc::new(a) as ArrayRef, Arc::new(b) as ArrayRef],
2575 None,
2576 );
2577 let plan = FieldPlan::Struct {
2578 bindings: vec![
2579 FieldBinding {
2580 arrow_index: 0,
2581 nullability: None,
2582 plan: FieldPlan::Scalar,
2583 },
2584 FieldBinding {
2585 arrow_index: 1,
2586 nullability: None,
2587 plan: FieldPlan::Scalar,
2588 },
2589 ],
2590 };
2591 let got = encode_all(&struct_arr, &plan, None);
2592 // Expected: rows concatenated: a then b
2593 let mut expected = Vec::new();
2594 expected.extend(avro_long_bytes(1)); // a=1
2595 expected.extend(avro_len_prefixed_bytes(b"x")); // b="x"
2596 expected.extend(avro_long_bytes(2)); // a=2
2597 expected.extend(avro_len_prefixed_bytes(b"y")); // b="y"
2598 assert_bytes_eq(&got, &expected);
2599 }
2600
2601 #[test]
2602 fn enum_encoder_dictionary() {

Callers

nothing calls this directly

Calls 6

encode_allFunction · 0.85
avro_long_bytesFunction · 0.85
avro_len_prefixed_bytesFunction · 0.85
assert_bytes_eqFunction · 0.85
cloneMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected