Json 创建scheme.avsc Avro时遇到的问题

Json 创建scheme.avsc Avro时遇到的问题,json,avro,Json,Avro,我在创建avro方案时遇到问题,下面我将介绍我的方案 twitter.avsc: { "type" : "record", "name" : "twitter_schema", "namespace" : "com.miguno.avro", "fields" : [ { "name" : "_id", "type" : "record", "doc" : "Values of the indexes/id tweets"}, { "name" : "nome",

我在创建avro方案时遇到问题,下面我将介绍我的方案

twitter.avsc:

{
  "type" : "record",
  "name" : "twitter_schema",
  "namespace" : "com.miguno.avro",
  "fields" : [
    { "name" : "_id", "type" : "record", "doc" : "Values of the indexes/id tweets"},
    { "name" : "nome","type" : "string","doc" : "Name of the user account on Twitter.com" },
    { "name" : "tweet", "type" : "string","doc" : "The content of the user's Twitter message" },
    { "name" : "datahora", "type" : "string","doc" : "Unix epoch time in seconds"}

    ],
  "doc:" : "A schema for storing Twitter messages"
}
当我尝试将tweet.json转换为.avro时,出现以下错误:

Exception in thread "main" org.apache.avro.SchemaParseException: "record" is not a defined name. The type of the "_id" field must be a defined name or a {"type": ...} expression.
    at org.apache.avro.Schema.parse(Schema.java:1199)
    at org.apache.avro.Schema$Parser.parse(Schema.java:965)
    at org.apache.avro.Schema$Parser.parse(Schema.java:938)
    at org.apache.avro.tool.DataFileWriteTool.run(DataFileWriteTool.java:82)
    at org.apache.avro.tool.Main.run(Main.java:84)
    at org.apache.avro.tool.Main.main(Main.java:73)
下面是我试图转换为.avro的.json文件

tweet.json:

{ "_id" : { "$oid" : "54d148b471eb130b1e8b4567" }, "nome" : "Marco Correia", "tweet" : "Globo repassará R$ 300 milhões /clubes  http://t.co/SQIjscDolU Vão entrar 45 milhões /Flamengo nesse Mês e Março e o clube não tem Grana!Sei", "datahora" : "Tue Feb 03 22:15:54 +0000 2015" }
{ "_id" : { "$oid" : "54d148b471eb130b1e8b4568" }, "nome" : "FLUMINENSE F.C.", "tweet" : "Jornalheiros - Flamengo x Barra Mansa - Transmissão ao vivo (04/02/2015, 22:00, Maracanã) http://t.co/BYQk3swWqf", "datahora" : "Tue Feb 03 22:15:44 +0000 2015" }
{ "_id" : { "$oid" : "54d148b471eb130b1e8b4569" }, "nome" : "VaiRio - O Globo", "tweet" : "Praia do Flamengo tem fluxo bom no sentido Botafogo, na altura da Rua Dois de Dezembro http://t.co/lWe3IEvAp2", "datahora" : "Tue Feb 03 22:15:44 +0000 2015" }
{ "_id" : { "$oid" : "54d148b471eb130b1e8b456a" }, "nome" : "PC Filho ★★★★", "tweet" : "Jornalheiros - Flamengo x Barra Mansa - Transmissão ao vivo (04/02/2015, 22:00, Maracanã) http://t.co/NArNpqy3tz", "datahora" : "Tue Feb 03 22:15:43 +0000 2015" }
{ "_id" : { "$oid" : "54d148b471eb130b1e8b456b" }, "nome" : "ATL Sports Bar", "tweet" : "SCORE ALERT: #Basketball #Livescore @ScoresPro: (-NBB) #Flamengo Bc vs #Minas: 41-30", "datahora" : "Tue Feb 03 22:15:38 +0000 2015" }
{ "_id" : { "$oid" : "54d148b471eb130b1e8b456c" }, "nome" : "FlamengoNews", "tweet" : "The type should be one of the primitives or an user defined avro type(record - This should be defined first and then used).
The avsc should be one of the below:

{
"type": "record",
"name": "twitter_schema",
"namespace": "com.miguno.avro",
"fields": [
    {
        "name": "_id",
        "type": {
            "type": "record",
            "name": "id_schema",
            "namespace": "com.miguno.avro",
            "fields": [
                {
                    "name": "id_name",
                    "type": "string",
                    "doc": "Value of the indexes/id name tweets"
                },
                {
                    "name": "id_value",
                    "type": "string",
                    "doc": "Value of the indexes/id value tweets"
                }
            ],
            "doc:": "A schema for storing Values of the indexes/id tweets"
        },
        "doc": "Values of the indexes/id tweets"
    },
    {
        "name": "nome",
        "type": "string",
        "doc": "Name of the user account on Twitter.com"
    },
    {
        "name": "tweet",
        "type": "string",
        "doc": "The content of the user's Twitter message"
    },
    {
        "name": "datahora",
        "type": "string",
        "doc": "Unix epoch time in seconds"
    }
],
"doc:": "A schema for storing Twitter messages"
}
{u id:{“$oid”:“54d148b471eb130b1e8b4567”},“nome”:“Marco Correia”,“tweet”:“Globo repassaráR$3亿欧元/俱乐部”http://t.co/SQIjscDolU Vão entrar 45 milhões/Flamengo nesse Mès e Março e clube não tem Grana!Sei,“datahora”:“2015年2月3日星期二22:15:54+0000”
{“_id”:{“$oid”:“54d148b471eb130b1e8b4568”},“nome”:“FLUMINENSE F.C.”,“tweet”:“Jornalheiros-Flamengo x Barra Mansa-Transmissão ao vivo”(2015年2月4日,22:00,马拉坎)http://t.co/BYQk3swWqf,“datahora”:“2015年2月3日星期二22:15:44+0000”
{“_id”:{“$oid”:“54d148b471eb130b1e8b4569”},“nome”:“Vario-O Globo”,“tweet”:“Praia do Flamengo tem fluxo bom no sentido Botafogo,na altura da Rua Dois de Dezembro”http://t.co/lWe3IEvAp2,“datahora”:“2015年2月3日星期二22:15:44+0000”
{“_id”:{“$oid”:“54d148b471eb130b1e8b456a”},“nome”:“PC Filho”★★★★", "推特:“Jornalheiros-Flamengo x Barra Mansa-Transmissão ao vivo(2015年2月4日,22:00,马拉坎)http://t.co/NArNpqy3tz,“datahora”:“2015年2月3日星期二22:15:43+0000”
{u id:{“$oid:”54D148B47EB130B1E8B456B“},“nome:”ATL体育酒吧“,”推特“:”得分警报:#Basketball#Livescore@ScoresPro:(-NBB)#弗拉门戈Bc vs#米纳斯:41-30”,“datahora:“周二2月3日22:15:38+0000 2015”}

{“_id”:{“$oid”:“54d148b471eb130b1e8b456c”},“nome”:“FlamengoNews”,“tweet”:“类型应为原语之一或用户定义的avro类型(记录-应先定义,然后使用)。 avsc应为以下类型之一:

{
"type": "record",
"name": "twitter_schema",
"namespace": "com.miguno.avro",
"fields": [
    {
        "name": "_id",
        "type": {
            "type": "array",
            "items": "string"
        },
        "doc": "Values of the indexes/id tweets"
    },
    {
        "name": "nome",
        "type": "string",
        "doc": "Name of the user account on Twitter.com"
    },
    {
        "name": "tweet",
        "type": "string",
        "doc": "The content of the user's Twitter message"
    },
    {
        "name": "datahora",
        "type": "string",
        "doc": "Unix epoch time in seconds"
    }
],
"doc:": "A schema for storing Twitter messages"
}