在 Apache Avro 架构中存储列表或集合
Store list or collection in Apache Avro schema
我目前正在创建 Avro 架构来存储 Twitter 数据流。
我的数据源在 JSON:
{
'id': '123456789',
'text': 'bla bla bla...',
'entities': {
'hashtags': [{'text':'hashtag1'},{'text':'hashtag2'}]
}
}
在 Cassandra 中,我可以定义集合(集或列表)来存储主题标签数据。
但是我不知道如何在 Apache Avro 中定义这个结构。
这是我的最佳尝试:
{"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 ?
]
}
需要您的建议。
谢谢,
汤田.
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"
}
]
}
}
}
]
}
}
]
}
如果有用,您可以使用 this tool 从任何有效的 JSON 记录生成(匿名)Avro 模式。然后,您只需将名称添加到 record
类型。
您可以在将 '
切换为 "
后在您的示例中尝试:
{
"id": "123456789",
"text": "bla bla bla...",
"entities": {"hashtags": [{"text": "hashtag1"}, {"text": "hashtag2"}]}
}
我目前正在创建 Avro 架构来存储 Twitter 数据流。 我的数据源在 JSON:
{
'id': '123456789',
'text': 'bla bla bla...',
'entities': {
'hashtags': [{'text':'hashtag1'},{'text':'hashtag2'}]
}
}
在 Cassandra 中,我可以定义集合(集或列表)来存储主题标签数据。 但是我不知道如何在 Apache Avro 中定义这个结构。
这是我的最佳尝试:
{"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 ?
]
}
需要您的建议。
谢谢, 汤田.
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"
}
]
}
}
}
]
}
}
]
}
如果有用,您可以使用 this tool 从任何有效的 JSON 记录生成(匿名)Avro 模式。然后,您只需将名称添加到 record
类型。
您可以在将 '
切换为 "
后在您的示例中尝试:
{
"id": "123456789",
"text": "bla bla bla...",
"entities": {"hashtags": [{"text": "hashtag1"}, {"text": "hashtag2"}]}
}