Mark Farnan created AVRO-3695:
---------------------------------

             Summary: [Rust] Can't validate schema with value when Nullable 
union has multiple types.
                 Key: AVRO-3695
                 URL: https://issues.apache.org/jira/browse/AVRO-3695
             Project: Apache Avro
          Issue Type: Bug
          Components: rust
            Reporter: Mark Farnan


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: 
 
{code:java}
{ "type": "record", "namespace": "datatypes", "name": "nullunion", "fields": [ 
{"name": "item", "type": [ "null", "long", "double" ] } ] } {code}
 
Struct:  (This was generated by rsgen-avro)

{code:java}
/// 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>,}{code}
 
{code:java}
#[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();
} {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to