在Amazon Athena中使用压缩GEOJSON报错,能否支持压缩地理空间数据?
Athena查询压缩GEOJSON数据报错问题解决
我用Athena查询GEOJSON格式的地理空间数据,未压缩的文件查询正常,但用gzip压缩后触发以下错误:
HIVE_CURSOR_ERROR: Illegal character ((CTRL-CHAR, code 31)): only regular white space (
,
, ) is allowed between tokens at [Source: org.apache.hadoop.fs.FSDataInputStream@6acf4fe5: org.apache.hadoop.fs.BufferedFSInputStream@2793fa25; line: 1, column: 2]
想问Athena是否支持压缩的地理空间数据?
补充建表语句:
CREATE EXTERNAL TABLE `locations`( `id` bigint COMMENT 'from deserializer', `boundaryshape` binary COMMENT 'from deserializer') ROW FORMAT SERDE 'com.esri.hadoop.hive.serde.JsonSerde' STORED AS INPUTFORMAT 'com.esri.json.hadoop.EnclosedJsonInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://mydata/transformed/' TBLPROPERTIES ( 'classification'='json', 'write.compression'='GZIP')
Athena支持压缩的地理空间数据,你的问题出在缺少压缩格式的表属性配置,导致Athena无法正确解析gzip压缩文件。
你需要在建表的TBLPROPERTIES中添加'compressionType'='gzip'配置,修改后的建表语句如下:
CREATE EXTERNAL TABLE `locations`( `id` bigint COMMENT 'from deserializer', `boundaryshape` binary COMMENT 'from deserializer') ROW FORMAT SERDE 'com.esri.hadoop.hive.serde.JsonSerde' STORED AS INPUTFORMAT 'com.esri.json.hadoop.EnclosedJsonInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://mydata/transformed/' TBLPROPERTIES ( 'classification'='json', 'write.compression'='GZIP', 'compressionType'='gzip')
额外注意事项:
- 压缩文件需为标准gzip格式,建议文件名以
.gz结尾,方便Athena自动识别(配置compressionType后无后缀也可解析,但加后缀更稳妥) - 你使用的Esri JsonSerDe和EnclosedJsonInputFormat本身支持gzip解析,只要配置正确即可正常读取
内容的提问来源于stack exchange,提问作者Greg Hinch
相关产品推荐
相关产品推荐

