2017-04-20 31 views
3

我试图用这个Avro的shcemaAvro的模式格式异常 - “记录” 是不使用的Avro工具定义的名称

{ 
    "namespace": "nothing", 
    "name": "myAvroSchema", 
    "type": "record", 
    "fields": [ 
    { 
     "name": "checkInCustomerReference", 
     "type": "string" 
    }, 
    { 
     "name": "customerContacts", 
     "type": "record", 
     "fields": [ 
     { 
      "name": "customerEmail", 
      "type": "array", 
      "items": { 
      "type": "record", 
      "name": "customerEmail_element", 
      "fields": [ 
       { 
       "name": "emailAddress", 
       "type": "string" 
       }, 
       { 
       "name": "typeOfEmail", 
       "type": "string" 
       } 
      ] 
      } 
     }, 
     { 
      "name": "customerPhone", 
      "type": "array", 
      "items": { 
      "type": "record", 
      "name": "customerPhone_element", 
      "fields": [ 
       { 
       "name": "fullContactNumber", 
       "type": "string" 
       }, 
       { 
       "name": "ISDCode", 
       "type": "string" 
       } 
      ] 
      } 
     }, 
     { 
      "name": "DonotAskIndicator", 
      "type": "record", 
      "fields": [ 
      { 
       "name": "donotAskDetails", 
       "type": "string" 
      } 
      ] 
     } 
     ] 
    }, 
    { 
     "name": "somethingElseToCheck", 
     "type": "string" 
    } 
    ] 
} 

要生成和Avro的文件:

avro-tools fromjson --schema-file myAvroSchema.avsc myJson.json > myAvroData.avro 

不过,我收到以下错误消息:在线程“主要” org.apache.avro.SchemaParseException

例外: “记录”是不是去罚款的名字。 “customerContacts” 字段的类型必须是定义的名称或{“type”:...}表达式。

谁能告诉我为什么记录没有被识别为一个定义的名称?

回答

2

类型的 “customerContacts” 字段的必须是一个已定义的名称或{ “类型”:...}表达

隐而不宣看起来像你正确定义你的嵌套记录。我复制了你的模式并出来了,试试看:

{ 
    "type":"record", 
    "name":"myAvroSchema", 
    "namespace":"nothing", 
    "fields":[ 
     { 
      "name":"checkInCustomerReference", 
      "type":"string" 
     }, 
     { 
      "name":"customerContacts", 
      "type":{ 
       "type":"record", 
       "name":"customerContacts", 
       "namespace":"nothing", 
       "fields":[ 
        { 
         "name":"customerEmail", 
         "type":{ 
          "type":"array", 
          "items":{ 
           "type":"record", 
           "name":"customerEmail", 
           "namespace":"nothing", 
           "fields":[ 
            { 
             "name":"emailAddress", 
             "type":"string" 
            }, 
            { 
             "name":"typeOfEmail", 
             "type":"string" 
            } 
           ] 
          } 
         } 
        }, 
        { 
         "name":"customerPhone", 
         "type":{ 
          "type":"array", 
          "items":{ 
           "type":"record", 
           "name":"customerPhone", 
           "namespace":"nothing", 
           "fields":[ 
            { 
             "name":"fullContactNumber", 
             "type":"string" 
            }, 
            { 
             "name":"ISDCode", 
             "type":"string" 
            } 
           ] 
          } 
         } 
        }, 
        { 
         "name":"DonotAskIndicator", 
         "type":{ 
          "type":"record", 
          "name":"donotAskIndicator", 
          "namespace":"nothing", 
          "fields":[ 
           { 
            "name":"donotAskDetails", 
            "type":"string" 
           } 
          ] 
         } 
        } 
       ] 
      } 
     }, 
     { 
      "name":"somethingElseToCheck", 
      "type":"string" 
     } 
    ] 
}