Details
-
Bug
-
Status: Open
-
Blocker
-
Resolution: Unresolved
-
None
-
None
Description
If a union has more than one 'type' (other than null), to_avro_datum is unable to validate the schema with the value type, and throws a validation error.
Schema:
{ "type": "record", "namespace": "datatypes", "name": "nullunion", "fields": [ {"name": "item", "type": [ "null", "long", "double" ] } ] }
Struct: (This was generated by rsgen-avro)
/// Auto-generated type for unnamed Avro union variants. #[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize)] pub enum UnionLongDouble { Long(i64), Double(f64),} #[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize)] pub struct NullUnion { pub item: Option<UnionLongDouble>,}
#[test] fn test_multivalue_union_tovalue() { let nuschema = r#" { "type": "record", "namespace": "datatypes", "name": "nullunion", "fields": [ {"name": "item", "type": [ "null", "long", "double" ] } ] } "#; let nullunion = NullUnion { item: Some(UnionLongDouble::Long(34)), }; let schema = Schema::parse_str(nuschema).unwrap(); let nu_value = to_value(nullunion).unwrap(); let nu_encoded = to_avro_datum(&schema, nu_value).unwrap(); }
Attachments
Issue Links
- is related to
-
AVRO-3646 Serialization / deserialization for enum with mixed variants (with and without data)
- Open
- links to