Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3695

[Rust] Can't validate schema with value when Nullable union has multiple types.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Blocker
    • Resolution: Unresolved
    • None
    • None
    • rust

    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

          Activity

            People

              Unassigned Unassigned
              MarkFarnan Mark Farnan
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m