0

我正在研究 avro 模式。当我尝试使用 dotnet Apache.Avro.Tools --version 1.11.0 命令行自动生成 dto 类 (avrogen -s schema.avsc .) 时,我的架构出现了一些解析错误:

Undefined name: record at 'fields[0].type.items.fields[1].type.items.fields[1].type.type'

我的 schema.avsc 是:

{
    "type": "record",
    "name": "MyName",
    "namespace": "MyNameSpace",
    "doc": "My doc",
    "fields": [{
        "name": "load_groupings",
        "type": {
            "type": "array",
            "items": {
                "type": "record",
                "name": "LoadGrouping",
                "doc": "Load grouping: A physical shipment along with its stops\n\n  @field lane_id: the lane ID number this load grouping will run on.\n  @field load_stops: the stops to be executed by this load grouping.\n  @field loads: the loads associated with this load grouping.\n  @field departure_date: the shipment date (date of first origin stop) of this load grouping.",
                "fields": [{
                    "name": "lane_id",
                    "type": "int"
                }, {
                    "name": "load_stops",
                    "type": {
                        "type": "array",
                        "items": {
                            "type": "record",
                            "name": "LoadStop",
                            "doc": "A load stop to be associated with a load.\n\n  @field stop_sequence: the sequence number of this stop among all stops made by the parent load grouping.\n  @field facility_service_id: the facility service id of this stop which includes entity id and type.",
                            "fields": [{
                                "name": "stop_sequence",
                                "type": "int"
                            }, {
                                "name": "facility_service_id",
                                "type": {
                                    "type": "record",
                                    "name": "FacilityServiceID",
                                    "doc": "Facility Service ID\n\n  Service at physical facility.\n\n  @field entity_id: entity id of this facility service\n  @field entity_type: entity type of this facility service. Allowing null values for Small Parcel scenarios\n  (carrier hubs and stations)\n  @field agent_service_type: for facility service with entity_type of agent, the agent_service_type of the\n  entity",
                                    "fields": [{
                                        "name": "entity_id",
                                        "type": "int"
                                    }, {
                                        "name": "entity_type",
                                        "type": ["null", {
                                            "type": "enum",
                                            "name": "EntityType",
                                            "doc": "Entity Type\n\n  SUPPLIER:\n  AGENT:\n  WAREHOUSE:",
                                            "symbols": ["SUPPLIER", "AGENT", "WAREHOUSE"]
                                        }]
                                    }, {
                                        "name": "agent_service_type",
                                        "type": ["null", {
                                            "type": "enum",
                                            "name": "AgentServiceType",
                                            "doc": "Agent Service Type",
                                            "symbols": ["PP", "XD", "DA"]
                                        }]
                                    }],
                                    "logicalType": "referentialkey_check",
                                    "keyspace": "facility_service"
                                }
                            }]
                        }
                    }
                }, {
                    "name": "loads",
                    "type": {
                        "type": "array",
                        "items": {
                            "type": "record",
                            "name": "Load",
                            "doc": "A load to be associated with a load grouping.\n\n  @field origin_stop: the origin stop for this load.\n  @field destination_stop: the destination stop for this load.\n  @field expected_flow: the expected flow on this load.",
                            "fields": [{
                                "name": "origin_stop",
                                "type": "LoadStop"
                            }, {
                                "name": "destination_stop",
                                "type": "LoadStop"
                            }, {
                                "name": "expected_flow",
                                "type": {
                                    "type": "record",
                                    "name": "FourTuple",
                                    "doc": "Four Tuple\n\n  A representation of any 4-tuple record whose entries are named volume, weight, carton, and po.\n\n  @field volume: value of the volume dimension in cubes\n  @field weight: value of the weight dimension in lbs\n  @field carton: value of number of cartons\n  @field po: value of number of purchase orders",
                                    "fields": [{
                                        "name": "volume",
                                        "type": "double"
                                    }, {
                                        "name": "weight",
                                        "type": "double"
                                    }, {
                                        "name": "carton",
                                        "type": "double"
                                    }, {
                                        "name": "po",
                                        "type": "double"
                                    }]
                                }
                            }]
                        }
                    }
                }, {
                    "name": "departure_date",
                    "type": "string"
                }]
            }
        }
    }, {
        "name": "lane_movements",
        "type": {
            "type": "array",
            "items": {
                "type": "record",
                "name": "PlannedLaneMovement",
                "doc": "Lane Movement: A physical shipment along with its stops\n\n  @field lane_id: the lane ID number this load grouping will run on.\n  @field loads: the loads associated with this load grouping.\n  @field ready_date: the shipment date (date of first origin stop) of this lane movement.",
                "fields": [{
                    "name": "lane_id",
                    "type": "int"
                }, {
                    "name": "loads",
                    "type": {
                        "type": "array",
                        "items": {
                            "type": "record",
                            "name": "PlannedLoad",
                            "doc": "A load to be associated with a lane movement.\n\n  @field origin_facility_service_id: the origin facility service for this load.\n  @field destination_facility_service_id: the destination facility service for this load.\n  @field expected_flow: the expected flow on this load.",
                            "fields": [{
                                "name": "origin_facility_service_id",
                                "type": "FacilityServiceID"
                            }, {
                                "name": "destination_facility_service_id",
                                "type": "FacilityServiceID"
                            }, {
                                "name": "expected_flow",
                                "type": "FourTuple"
                            }]
                        }
                    }
                }, {
                    "name": "ready_date",
                    "type": "string"
                }]
            }
        }
    }]
}

我使用 js 编辑器来 console.log :fields[0].type.items.fields[1].type.items.fields[1].type.type 当我console.log(fields[0].type.items.fields[1].type.items.fields[1].type) 显示时它是记录:

{
  type: 'record',
  name: 'FacilityServiceID',
  doc: 'Facility Service ID\n' +
    '\n' +
    '  Service at physical facility.\n' +
    '\n' +
    '  @field entity_id: entity id of this facility service\n' +
    '  @field entity_type: entity type of this facility service. Allowing null values for Small Parcel scenarios\n' +
    '  (carrier hubs and stations)\n' +
    '  @field agent_service_type: for facility service with entity_type of agent, the agent_service_type of the\n' +
    '  entity',
  fields: [
    { name: 'entity_id', type: 'int' },
    { name: 'entity_type', type: [Array] },
    { name: 'agent_service_type', type: [Array] }
  ],
  logicalType: 'referentialkey_check',
  keyspace: 'facility_service'
}

不知道我的架构有什么问题,并且所有代码都使用avro 查看器进行了很好的处理,有人 可以帮我解决这个错误吗?太感谢了!

4

0 回答 0