我有一个AWS IoT规则将传入的JSON发送到Kinesis Firehose。如何过滤进入AWS Hive表的多行JSON数据
从我的物联网发布的JSON数据是全部在一行上 - 例如:
{"count":4950, "dateTime8601": "2017-03-09T17:15:28.314Z"}
在管理界面的IOT测试“测试”部分允许你发布的消息,默认为以下(注格式化多-line JSON):
{
"message": "Hello from AWS IoT console"
}
我流的流水到S3,然后通过EMR转换为柱状格式最终由雅典娜使用。
问题是,在转换为列格式时,Hive(特别是JSON SerDe)无法处理跨越多行的JSON对象。它会炸毁转换,而不会转换好的单行JSON记录。
我的问题是:
- 你如何设置流水忽略多行JSON?
- 如果不可能,如何告诉Hive在载入表之前删除换行符,或者至少捕获异常并尝试继续?
我已经开始尝试定义蜂巢表时忽略畸形的JSON:
DROP TABLE site_sensor_data_raw;
CREATE EXTERNAL TABLE site_sensor_data_raw (
count int,
dateTime8601 timestamp
)
PARTITIONED BY(year int, month int, day int, hour int)
ROW FORMAT serde 'org.apache.hive.hcatalog.data.JsonSerDe'
with serdeproperties (
'ignore.malformed.json' = 'true',
"timestamp.formats"="yyyy-MM-dd'T'HH:mm:ss.SSS'Z',millis"
)
LOCATION 's3://...';
这里是我的全HQL,做转换:
--Example of converting to OEX/columnar formats
DROP TABLE site_sensor_data_raw;
CREATE EXTERNAL TABLE site_sensor_data_raw (
count int,
dateTime8601 timestamp
)
PARTITIONED BY(year int, month int, day int, hour int)
ROW FORMAT serde 'org.apache.hive.hcatalog.data.JsonSerDe'
with serdeproperties (
'ignore.malformed.json' = 'true',
"timestamp.formats"="yyyy-MM-dd'T'HH:mm:ss.SSS'Z',millis"
)
LOCATION 's3://bucket.me.com/raw/all-sites/';
ALTER TABLE site_sensor_data_raw ADD PARTITION (year='2017',month='03',day='09',hour='15') location 's3://bucket.me.com/raw/all-sites/2017/03/09/15';
ALTER TABLE site_sensor_data_raw ADD PARTITION (year='2017',month='03',day='09',hour='16') location 's3://bucket.me.com/raw/all-sites/2017/03/09/16';
ALTER TABLE site_sensor_data_raw ADD PARTITION (year='2017',month='03',day='09',hour='17') location 's3://bucket.me.com/raw/all-sites/2017/03/09/17';
DROP TABLE to_orc;
CREATE EXTERNAL TABLE to_orc (
count int,
dateTime8601 timestamp
)
STORED AS ORC
LOCATION 's3://bucket.me.com/orc'
TBLPROPERTIES ("orc.compress"="ZLIB");
INSERT OVERWRITE TABLE to_orc SELECT count,dateTime8601 FROM site_sensor_data_raw where year=2017 AND month=03 AND day=09 AND hour=15;