【问题标题】:Redshift JSONPaths file for dynamic json file用于动态 json 文件的 Redshift JSONPaths 文件
【发布时间】:2020-06-29 10:26:49
【问题描述】:

给定下面的 json 对象

{
  "player": {
    "francesco totti": {
      "position": "forward"
    },
    "andrea pirlo": {
      "position": "midfielder"
    }
  }
}

我想将上面的文件导入 Redshift 作为下面的行

name, position
"franceso totti", "forward"
"andrea pirlo", "midfielder"

问题是“玩家”对象每小时都有动态数量的对象(我导入 Redshift 时的节奏)。例如,下一个小时的运行可能如下所示。

{
  "player": {
    "fabio cannavaro": {
      "position": "defender"
    }
  }
}

是否可以使用 JSONPaths 文件每小时导入此文件,还是需要预处理?

【问题讨论】:

    标签: amazon-redshift amazon-redshift-spectrum


    【解决方案1】:

    您可以随意重复使用 jsonpath 文件。您只需要重新运行 COPY 语句,但请记住这会将行添加到表中 - 而不是替换它们。如果您要替换,那么您需要先清除表(删除、删除/重新创建、截断 - 每个都有自己的性能和限制)。

    现在您的 json 格式不适用于 Redshift AFAIK。您将玩家名称作为字段标识符,并希望将其设置为列的值。你会想要这样的东西(抱歉这些没有经过测试):

    {
      "player": {
        "name": "francesco totti",
        "position": "forward"
        }
    },
    {
      "player": {
        "name": "andrea pirlo",
        "position": "midfielder"
        }
    }
    

    还有一个像这样的 jsonpath:

    {
        "jsonpaths": [
           "$.player.name",
           "$.player.position"
        ]
    }
    

    【讨论】:

    • 谢谢!说得通。我希望找到一种不重新格式化 JSON 的方法,但看起来我需要在最后加载它之前进行预处理。
    猜你喜欢
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    相关资源
    最近更新 更多