简体   繁体   English

FastAvro 架构问题

[英]FastAvro Schema Issues

I've almost finished the avro section but I am having one big challenge ahead of me which is the name and namespace.我几乎完成了 avro 部分,但我面临着一个巨大的挑战,那就是名称和命名空间。 I've tried this and no matter what I've done, I've experienced errors, even when referencing documents like: docs.oracle.com/cd/E26161_02/html/GettingStartedGuide/avroschemas.html我已经尝试过了,无论我做了什么,我都遇到了错误,即使在引用以下文档时也是如此:docs.oracle.com/cd/E26161_02/html/GettingStartedGuide/avroschemas.html

My schema header is: https://i.ibb.co/TPH8shF/image.png我的架构 header 是: https://i.ibb.co/TPH8shF/image.png

With the error being: https://i.ibb.co/BCcX6Jd/image.png错误是: https://i.ibb.co/BCcX6Jd/image.png

However, when I add schemas to the namespace (since it's in the schemas folder), this error comes up: https://i.ibb.co/Z62RwN2/image.png但是,当我将架构添加到命名空间时(因为它位于架构文件夹中),出现此错误: https://i.ibb.co/Z62RwN2/image.png

Do any of you know what could be causing this error?你们中有人知道可能导致此错误的原因吗? Thanks!谢谢!

Here's the text version, if you need it:这是文本版本,如果您需要它:

src_data_path = 'data/processed/openflights/routes.jsonl.gz'
parsed_schema = load_schema("routes.avsc")
avro_output_path = results_dir.joinpath('results/routes.avro')
src_data_path = 'routes.jsonl'
with open(src_data_path, 'r') as f:
    avro_reader = json_reader(f, parsed_schema)        
    for record in avro_reader:
        print(record)
{
  "type": "record",
  "name": "routes",
  "namespace": "schemas",
  "fields": [
    {
      "name": "airline",
      "type": {
        "type": "record",
        "name": "Airline",
        "fields": [
          {
            "name": "airline_id",
            "type": "int",
            "default": -1
          },
          {
            "name": "name",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "alias",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "iata",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "icao",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "callsign",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "country",
            "type": "string",
            "default": "NONE"
          },
          {
            "name": "active",
            "type": "boolean",
            "default": false
          }
        ]
      },
      "default": "NONE"
    },
    {
      "name": "src_airport",
      "type": [
        {
          "type": "record",
          "name": "Airport",
          "fields": [
            {
              "name": "airport_id",
              "type": "int",
              "default": -1
            },
            {
              "name": "name",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "city",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "iata",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "icao",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "latitude",
              "type": "double"
            },
            {
              "name": "longitude",
              "type": "double"
            },
            {
              "name": "timezone",
              "type": "double"
            },
            {
              "name": "dst",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "tz_id",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "type",
              "type": "string",
              "default": "NONE"
            },
            {
              "name": "source",
              "type": "string",
              "default": "NONE"
            }
          ]
        },
        "null"
      ],
      "default": "NONE"
    },
    {
      "name": "dst_airport",
      "type": [
        "record",
        "null"
      ],
      "fields": [
      {
       "name": "source",
       "type": "string",
       "default": "NONE"
      }
      ],
      "default": "NONE"
    },
    {
      "name": "codeshare",
      "type": "boolean",
      "default": false
    },
    {
      "name": "stops",
      "type": "int",
      "default": 0
    },
    {
      "name": "equipment",
      "type": {
        "type": "array",
        "items": "string"
      }
    }
  ]
}

In the definition for dst_airport you have the following:dst_airport的定义中,您有以下内容:

    {
      "name": "dst_airport",
      "type": [
        "record",
        "null"
      ],
      "fields": [
      {
       "name": "source",
       "type": "string",
       "default": "NONE"
      }
      ],
      "default": "NONE"
    },

The type of ["record", "null"] doesn't make sense because you haven't defined a named type called "record" (and I'm not sure the specification even allows you to do that. Either way, I'm assuming it should be ["Airport", "null"] . ["record", "null"]type没有意义,因为你没有定义一个名为 "record" 的命名类型(我不确定规范是否允许你这样做。无论哪种方式,我我假设它应该是["Airport", "null"]

Also, the fields here doesn't really make sense.此外,这里的fields并没有真正的意义。 It can't be a union type with fields .它不能是带有fields的联合类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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