Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support schemas expressed as array #147

Open
gaborbernat opened this issue Jul 15, 2020 · 0 comments
Open

Support schemas expressed as array #147

gaborbernat opened this issue Jul 15, 2020 · 0 comments
Labels

Comments

@gaborbernat
Copy link

gaborbernat commented Jul 15, 2020

Thanks for the library. The schema specification at https://avro.apache.org/docs/current/spec.html#schemas states:

A Schema is represented in JSON by one of:

A JSON string, naming a defined type.

A JSON object, of the form:
{"type": "typeName" ...attributes...} where typeName is either a primitive or derived type name, as defined below. Attributes not defined in this document are permitted as metadata, but must not affect the format of serialized data.

A JSON array, representing a union of embedded types.

avro-rs does not support JSON array format though as the following small example demonstrates:

use avro_rs::Schema;

fn main() {
    let raw_as_record = r#"
    {
      "type": "record",
      "name": "root",
      "fields": [
        {
          "name": "element",
          "type": [
            "null",
            {
              "type": "record",
              "name": "Magic",
              "fields": [{"name": "value", "type": "long"}]
            }
          ]
        }
      ]
    }
    "#;

    let raw_as_array = r#"
    [
      {
        "type": "record",
        "name": "Magic",
        "fields": [{ "name": "value", "type": "long"}]
      },
      {
        "type": "record",
        "name": "root",
        "fields": [{ "name": "element", "type": [ "null", "Magic"]}]
      }
    ]
    "#;

    let schema = Schema::parse_str(raw_as_record).unwrap();
    println!("{:?}", schema);

    let array_schema = Schema::parse_str(raw_as_array).unwrap();
    println!("{:?}", array_schema);
}
Record { name: Name { name: "root", namespace: None, aliases: None }, doc: None, fields: [RecordField { name: "element", doc: None, default: None, schema: Union(UnionSchema { schemas: [Null, Record { name: Name { name: "Magic", namespace: None, aliases: None }, doc: None, fields: [RecordField { name: "value", doc: None, default: None, schema: Long, order: Ascending, position: 0 }], lookup: {"value": 0} }], variant_index: {Null: 0, Record: 1} }), order: Ascending, position: 0 }], lookup: {"element": 0} }
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseSchemaError("Unknown type: Magic")
@gaborbernat gaborbernat changed the title Support schemas expressed as Support schemas expressed as array union Jul 15, 2020
@gaborbernat gaborbernat changed the title Support schemas expressed as array union Support schemas expressed as array Jul 15, 2020
@poros poros added the bug label Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants