【问题标题】:How to convert a 10G JSON file to Avro?如何将 10G JSON 文件转换为 Avro?
【发布时间】:2015-12-16 21:40:14
【问题描述】:

我有一个大约 10G 的 JSON 文件。每行只包含一个 JSON 文档。我想知道将其转换为 Avro 的最佳方法是什么。理想情况下,我希望每个文件保留多个文档(例如 10M)。我认为 Avro 支持在同一个文件中包含多个文档。

【问题讨论】:

    标签: json avro


    【解决方案1】:

    您应该能够使用 Avro 工具的 fromjson 命令(有关更多信息和示例,请参阅 here)。您可能希望事先将文件拆分为 10M 块(例如使用 split(1))。

    【讨论】:

      【解决方案2】:

      将大型 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"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-07
        • 1970-01-01
        • 2021-03-12
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 2020-05-20
        • 2020-10-01
        相关资源
        最近更新 更多