简体   繁体   English

AWS Athena JSON格式失败

[英]AWS Athena JSON format failure

I am trying to upload the data from this json: 我正在尝试从此json上传数据:

JSON-A JSON-A

[
  {"name": "james", "id": 41},
  {"name": "scott", "id": 62},
  {"name": "abhi", "id": 16},
  {"name": "kevin", "id": 53},
  {"name": "beau", "id": 12},
  {"name": "shally", "id": 35},
  {"name": "jude", "id": 53},
  {"name": "jason", "id": 77},
  {"name": "hongjian", "id": 35},
  {"name": "madhur", "id": 6}
]

If it had the parent "data" key like 如果它具有父“数据”键,例如

JSON-B JSON-B

["data":{"name": "james","id": 41"},{.....}]

then I know I can do like : 那么我知道我可以做到:

CREATE EXTERNAL TABLE IF NOT EXISTS test.test (
  `data` array<struct<`name`:string,`id`:bigint>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
  'serialization.format' = '1'
) LOCATION 's3://test-bucket/';

But what should be the way to do for JSON-A? 但是,对JSON-A应该采取什么方法?

您必须将文件保存在“ s3:// test-bucket /”中:
{"name": "james", "id": 41} {"name": "scott", "id": 62} {"name": "abhi", "id": 16} {"name": "kevin", "id": 53} {"name": "beau", "id": 12} {"name": "shally", "id": 35} {"name": "jude", "id": 53} {"name": "jason", "id": 77} {"name": "hongjian", "id": 35} {"name": "madhur", "id": 6}

I do not think this will work, because of the Hive/SerDe assumption that your text file contain one record per line. 由于Hive / SerDe假设您的文本文件每行包含一条记录,因此我认为这行不通。 From the org.openx.data.jsonserde.JsonSerDe documentation : org.openx.data.jsonserde.JsonSerDe文档中

  1. One Record Per Line - although I'm not sure your sample is meant to be literal in the multiline respect, the sample does contain multiple records in the same line. 每行一条记录 -尽管我不确定您的示例在多行方面是否应为原义,但该示例的确在同一行中包含多个记录。

IMPORTANT!!! 重要!!! READ THIS BELOW!! 阅读以下内容! Json records must be one per line, that is, the serde WILL NOT WORK with multiline Json. Json记录每行必须是一个,即多行Json不能使用Serde。

  1. Array Examples One-per-Line - the serde examples do show how to work with arrays, but again, not a top-level array encompassing multiple records in the same line. 数组示例(每行一个)-serde示例确实显示了如何使用数组,但同样,不是同一行中包含多个记录的顶级数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM