【问题标题】:Redshift: copy command Json data from s3Redshift:从 s3 复制命令 Json 数据
【发布时间】:2019-05-17 12:26:15
【问题描述】:

我有以下 JSON 数据。

{  
   "recordid":"69",
   "recordTimestamp":1558087302591,
   "spaceId":"space-cd88557d",
   "spaceName":"Kirtipur",
   "partnerId":"Kirtipur",
   "eventType":"event-location-update",
   "eventlocationupdate":{  
      "event":{  
         "eventid":"event-qcTUrDAThkbPsXi438rRk",
         "userId":"",
         "tags":[  

         ],
         "mobile":"",
         "email":"",
         "gender":"OTHER",
         "firstName":"",
         "lastName":"",
         "postalCode":"",
         "optIns":[  

         ],
         "otherFields":[  

         ],
         "macAddress":"55:56:81????????a4:6d"
      },
      "location":{  
         "locationId":"location-bdfsfsf6a8d96",
         "name":"Kirtipur Office - wireless",
         "inferredLocationTypes":[  
            "NETWORK"
         ],
         "parent":{  
            "locationId":"location-c39ffc49",
            "name":"Kirtipur",
            "inferredLocationTypes":[  
               "vianet"
            ],
            "parent":{  
               "locationId":"location-8b47asdfdsf1c6a",
               "name":"Kirtipur",
               "inferredLocationTypes":[  
                  "ROOT"
               ]
            }
         }
      },
      "ssid":"",
      "rawUserId":"",
      "visitId":"visit-ca04ds5secb8d",
      "lastSeen":1558087081000,
      "deviceClassification":"",
      "mapId":"",
      "xPos":1.8595887,
      "yPos":3.5580606,
      "confidenceFactor":0.0,
      "latitude":0.0,
      "longitude":0.0
   }
}

我需要使用复制命令从 s3 存储桶中加载它。我已将此文件上传到我的 S3 存储桶。

我使用过 csv 文件的复制命令,但没有使用过 JSON 文件的复制命令。我研究了通过复制命令导入 json,但没有找到可靠的有用命令示例。

我在复制命令中使用了以下代码。

COPY vianet_raw_data 
from 's3://vianet-test/vianet.json' 
with credentials as '' 
format as json 'auto';

这没有插入任何数据。

谁能帮我处理这种 JSON 的复制命令?

感谢和问候

【问题讨论】:

标签: amazon-redshift


【解决方案1】:

有两种情况(很可能是第一种):

  1. 您希望 AWS 的自动选项从您在第 2 行中提供的 s3 加载。为此,您可以:
COPY vianet_raw_data 
from 's3://vianet-test/vianet.json' 
with credentials as '' 
json 'auto';
  1. 使用自定义 json 加载路径(即您不希望所有路径都自动)
COPY vianet_raw_data 
from 's3://vianet-test/vianet.json' 
with credentials as '' 
format as json 's3://vianet-test/vianet_PATHS.json';

这里,“s3://vianet-test/vianet_PATHS.json”包含您要查看的主要位置的所有特定 JSON。

参考:https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html#r_COPY_command_examples-copy-from-json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    相关资源
    最近更新 更多