AWS Athena嵌套JSON错误

时间:2017-08-12 09:54:03

标签: json amazon-web-services amazon-s3 amazon-athena

我有一个嵌套的JSON文件,如下所示:

\n  \"total\" : 510,\n  \"start\" : 0,\n  \"count\" : 500,\n  \"data\" : [ {\n    \"id\" : 294,\n    \"candidate\" : {\n      \"id\" : 5275,\n      \"firstName\" : \"bob\",\n      \"lastName\" : \"bob\"\n    },\n    \"sendingUser\" : {\n      \"id\" : 5,\n      \"firstName\" : \"tom\",\n      \"lastName\" : \"tom\"\n    },\n    \"dateAdded\" : 1487865908960,\n    \"jobOrder\" : {\n      \"id\" : 71,\n      \"title\" : \"Job\"\n    },\n    \"status\" : \"1st Interview\",\n    \"_score\" : 1.0\n  }

我将它存储在S3中并尝试在AWS Athena中创建一个表,我所做的编辑器如下:

CREATE EXTERNAL TABLE IF NOT EXISTS cvtest (
  data struct < candidate struct <id string, firstName string, lastName string>,
                sendingUser struct <id string, firstName string, lastName string>,
                dateAdded string,
                jobOrder string,
                score string
              > 
  )           
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://es-cvsent'; 

但查询会遇到以下错误;

FAILED: ParseException line 2:26 missing : at 'struct' near '<EOF>' line 2:37 missing : at 'string' near '<EOF>' line 2:55 missing : at 'string' near '<EOF>' line 2:72 missing : at 'string' near '<EOF>' line 3:28 missing : at 'struct' near '<EOF>' line 3:39 missing : at 'string' near '<EOF>' line 3:57 missing : at 'string' near '<EOF>' line 3:74 missing : at 'string' near '<EOF>' line 4:26 missing : at 'string' near '<EOF>' line 5:25 missing : at 'string' near '<EOF>' line 6:22 missing : at 'string' near '<EOF>'

This query ran against the "test" database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: 84e876e8-b947-490e-b2b6-7bf9c376266e.

谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:0)

数据本身看起来不像是有效的JSON,但无论如何,您都应该能够创建表,因为此时基础数据尚未经过验证。 (之后查询表将不起作用)。

您遇到的问题是语法错误,请参见this documentation。“:”用于结构定义中的列和数据类型之间。

这应该有效

data struct<candidate:struct<id:string, firstName:string, lastName:string>,
                sendingUser:struct<id:string, firstName:string, lastName:string>,
                dateAdded:string,
                jobOrder:string,
                score:string
              >