【发布时间】:2015-12-16 21:40:14
【问题描述】:
我有一个大约 10G 的 JSON 文件。每行只包含一个 JSON 文档。我想知道将其转换为 Avro 的最佳方法是什么。理想情况下,我希望每个文件保留多个文档(例如 10M)。我认为 Avro 支持在同一个文件中包含多个文档。
【问题讨论】:
我有一个大约 10G 的 JSON 文件。每行只包含一个 JSON 文档。我想知道将其转换为 Avro 的最佳方法是什么。理想情况下,我希望每个文件保留多个文档(例如 10M)。我认为 Avro 支持在同一个文件中包含多个文档。
【问题讨论】:
将大型 JSON 文件转换为 Avro 的最简单方法是使用来自 Avro website 的 avro-tools。
创建简单架构后,可以直接转换文件。
java -jar avro-tools-1.7.7.jar fromjson --schema-file cpc.avsc --codec deflate test.1g.json > test.1g.deflate.avro
示例架构:
{
"type": "record",
"name": "cpc_schema",
"namespace": "com.streambright.avro",
"fields": [{
"name": "section",
"type": "string",
"doc": "Section of the CPC"
}, {
"name": "class",
"type": "string",
"doc": "Class of the CPC"
}, {
"name": "subclass",
"type": "string",
"doc": "Subclass of the CPC"
}, {
"name": "main_group",
"type": "string",
"doc": "Main-group of the CPC"
}, {
"name": "subgroup",
"type": "string",
"doc": "Subgroup of the CPC"
}, {
"name": "classification_value",
"type": "string",
"doc": "Classification value of the CPC"
}, {
"name": "doc_number",
"type": "string",
"doc": "Patent doc_number"
}, {
"name": "updated_at",
"type": "string",
"doc": "Document update time"
}],
"doc:": "A basic schema for CPC codes"
}
【讨论】: