()
| 2986 | |
| 2987 | #[test] |
| 2988 | fn union_encoder_null_string_int() { |
| 2989 | let nulls = NullArray::new(1); |
| 2990 | let strings = StringArray::from(vec!["hello"]); |
| 2991 | let ints = Int32Array::from(vec![10]); |
| 2992 | |
| 2993 | let union_fields = UnionFields::try_new( |
| 2994 | vec![0, 1, 2], |
| 2995 | vec![ |
| 2996 | Field::new("v_null", DataType::Null, true), |
| 2997 | Field::new("v_str", DataType::Utf8, true), |
| 2998 | Field::new("v_int", DataType::Int32, true), |
| 2999 | ], |
| 3000 | ) |
| 3001 | .unwrap(); |
| 3002 | |
| 3003 | let type_ids = Buffer::from_slice_ref([0_i8, 1, 2]); |
| 3004 | // For a null value in a dense union, no value is added to a child array. |
| 3005 | // The offset points to the last value of that type. Since there's only one |
| 3006 | // null, and one of each other type, all offsets are 0. |
| 3007 | let offsets = Buffer::from_slice_ref([0_i32, 0, 0]); |
| 3008 | |
| 3009 | let union_array = UnionArray::try_new( |
| 3010 | union_fields, |
| 3011 | type_ids.into(), |
| 3012 | Some(offsets.into()), |
| 3013 | vec![Arc::new(nulls), Arc::new(strings), Arc::new(ints)], |
| 3014 | ) |
| 3015 | .unwrap(); |
| 3016 | |
| 3017 | let plan = FieldPlan::Union { |
| 3018 | bindings: vec![ |
| 3019 | FieldBinding { |
| 3020 | arrow_index: 0, |
| 3021 | nullability: None, |
| 3022 | plan: FieldPlan::Scalar, |
| 3023 | }, |
| 3024 | FieldBinding { |
| 3025 | arrow_index: 1, |
| 3026 | nullability: None, |
| 3027 | plan: FieldPlan::Scalar, |
| 3028 | }, |
| 3029 | FieldBinding { |
| 3030 | arrow_index: 2, |
| 3031 | nullability: None, |
| 3032 | plan: FieldPlan::Scalar, |
| 3033 | }, |
| 3034 | ], |
| 3035 | }; |
| 3036 | |
| 3037 | let got = encode_all(&union_array, &plan, None); |
| 3038 | |
| 3039 | let mut expected = Vec::new(); |
| 3040 | expected.extend(avro_long_bytes(0)); |
| 3041 | expected.extend(avro_long_bytes(1)); |
| 3042 | expected.extend(avro_len_prefixed_bytes(b"hello")); |
| 3043 | expected.extend(avro_long_bytes(2)); |
| 3044 | expected.extend(avro_long_bytes(10)); |
| 3045 |
nothing calls this directly
no test coverage detected