简体   繁体   中英

Processing Multiple AVRO (avsc files) which are in different directory and refer each other using python (fastavro)

I have two avsc files in different directories -

1.  com.company.model.AddressRecord.avsc
2.  com.company.model.Customer.avsc

Here is address file

{
    "type": "record",
    "namespace": "com.company.model",
    "name": "AddressRecord",
    "fields": [
        {
            "name": "streetaddress",
            "type": "string"
        },
        {
            "name": "city",
            "type": "string"
        },
        {
            "name": "state",
            "type": "string"
        },
        {
            "name": "zip",
            "type": "string"
        }
    ]
}

here is customer file which is a parent (top level) schema

{
    "namespace": "com.company.model",
    "type": "record",
    "name": "Customer",
    "fields": [
        {
            "name": "firstname",
            "type": "string"
        },
        {
            "name": "lastname",
            "type": "string"
        },
        {
            "name": "email",
            "type": "string"
        },
        {
            "name": "phone",
            "type": "string"
        },
        {
            "name": "address",
            "type": {
                "type": "array",
                "items": "com.company.model.AddressRecord"
            }
        }
    ]
}

I am able to load the files using fastavro when both files are in same directory

fastavro.schema.load_schema('com.company.model.Customer.avsc')

But it does not work when both avsc files are in different directories. What changes I need to do in the files so that fast avro can load the schema if both avsc files are in different direcotry

The documentation for load_schema says that it only works for files in the same directory. It's not currently possible to do what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM