Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
869 views
in Technique[技术] by (71.8m points)

jsonpath - AWS Glue Custom Classifiers Json Path

I have a set of Json data files that look like this

[
  {"client":"toys",
   "filename":"toy1.csv",
   "file_row_number":1,
   "secondary_db_index":"4050",
   "processed_timestamp":1535004075,
   "processed_datetime":"2018-08-23T06:01:15+0000",
   "entity_id":"4050",
   "entity_name":"4050",
   "is_emailable":false,
   "is_txtable":false,
   "is_loadable":false}
]

I have created a Glue Crawler with the following custom classifier Json Path

$[*]

Glue returns the correct schema with the columns correctly identified.

However, when I query the data on Athena... all the data is landing in the first column and the rest of the columns are empty.

How can I get the data to spread according to their columns?

image of Athena query

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is a issue connected to Hive. I suggest two approaches. Firstly, you can create new table in Athena with struct data type like this:

CREATE EXTERNAL TABLE `example`(
`row` struct<client:string,filename:string,file_row_number:int,secondary_db_index:string,processed_timestamp:int,processed_datetime:string,entity_id:string,entity_name:string,is_emailable:boolean,is_txtable:boolean,is_loadable:boolean> COMMENT 'from deserializer')
ROW FORMAT SERDE 
'org.openx.data.jsonserde.JsonSerDe' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://example'
TBLPROPERTIES (
'CrawlerSchemaDeserializerVersion'='1.0', 
'CrawlerSchemaSerializerVersion'='1.0', 
'UPDATED_BY_CRAWLER'='example', 
'averageRecordSize'='271', 
'classification'='json', 
'compressionType'='none', 
'jsonPath'='$[*]', 
'objectCount'='1', 
'recordCount'='1', 
'sizeKey'='271', 
'transient_lastDdlTime'='1535533583', 
'typeOfData'='file')

And then you can run the query as follows:

SELECT row.client, row.filename, row.file_row_number FROM "example"

Secondly, you can re-design your json file as below and then run the Crawler again. In this example I used Single-JSON-Record-Per-Line format.

{"client":"toys","filename":"toy1.csv","file_row_number":1,"secondary_db_index":"4050","processed_timestamp":1535004075,"processed_datetime":"2018-08-23T06:01:15+0000","entity_id":"4050","entity_name":"4050","is_emailable":false,"is_txtable":false,"is_loadable":false},
{"client":"toys2","filename":"toy2.csv","file_row_number":1,"secondary_db_index":"4050","processed_timestamp":1535004075,"processed_datetime":"2018-08-23T06:01:15+0000","entity_id":"4050","entity_name":"4050","is_emailable":false,"is_txtable":false,"is_loadable":false}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...