List ApacheAvro架构中的存储列表或集合

List ApacheAvro架构中的存储列表或集合,list,collections,schema,avro,List,Collections,Schema,Avro,我目前正在创建Avro模式来存储twitter数据流。 我的JSON数据源: { 'id': '123456789', 'text': 'bla bla bla...', 'entities': { 'hashtags': [{'text':'hashtag1'},{'text':'hashtag2'}] } } 在Cassandra中,我可以定义集合(集合或列表)来存储hashtags数据。 但是我不知道如何在ApacheAvro中定义这个结构 以下是我的最佳尝试: {"namesp

我目前正在创建Avro模式来存储twitter数据流。 我的JSON数据源:

{
'id': '123456789',
'text': 'bla bla bla...',
'entities': {
  'hashtags': [{'text':'hashtag1'},{'text':'hashtag2'}]
  }
}
在Cassandra中,我可以定义集合(集合或列表)来存储hashtags数据。 但是我不知道如何在ApacheAvro中定义这个结构

以下是我的最佳尝试:

{"namespace": "ln.twitter",
 "type": "record",
 "name": "main",
 "fields": [
   {"name": "id","type": "string"},
   {"name": "text","type": "string"},
   {"name": "hashtags","type": "string"} // is there any better format for this ?
 ]
}
我需要你的建议

谢谢,
Yusta.

实体字段中需要显式记录(或映射)。下面是一个应该有效的模式:

{
  "type": "record",
  "name": "Main",
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "text",
      "type": "string"
    },
    {
      "name": "entities",
      "type": {
        "type": "record",
        "name": "Entities",
        "fields": [
          {
            "name": "hashtags",
            "type": {
              "type": "array",
              "items": {
                "type": "record",
                "name": "Hashtag",
                "fields": [
                  {
                    "name": "text",
                    "type": "string"
                  }
                ]
              }
            }
          }
        ]
      }
    }
  ]
}
如果有帮助,您可以使用从任何有效的JSON记录生成(匿名)Avro模式。然后,您只需要将名称添加到
记录
类型中

您可以在将其
切换到
后在示例中试用它:


entities
字段中需要显式记录(或映射)。下面是一个可以工作的模式:

{
  "type": "record",
  "name": "Main",
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "text",
      "type": "string"
    },
    {
      "name": "entities",
      "type": {
        "type": "record",
        "name": "Entities",
        "fields": [
          {
            "name": "hashtags",
            "type": {
              "type": "array",
              "items": {
                "type": "record",
                "name": "Hashtag",
                "fields": [
                  {
                    "name": "text",
                    "type": "string"
                  }
                ]
              }
            }
          }
        ]
      }
    }
  ]
}
如果有帮助,您可以使用从任何有效的JSON记录生成(匿名)Avro模式。然后您只需要向
记录
类型添加名称

您可以在将其
切换到
后在示例中试用它: