【发布时间】:2015-07-19 16:12:03
【问题描述】:
我使用 JSON 格式的 twitter 数据并创建了我的 Hive 结构来存储数据。我也在使用 SerDe org.openx.data.jsonserde.JsonSerDe 来序列化/反序列化每一行。
我有一个问题列,它是地理列(对于我的应用程序来说最重要的列)。该列的结构如下(完整的结构在底部):
geo struct<coordinates:array<double>, type:string>
这适用于具有正确数据的行: “地理”:{“类型”:“点”,“坐标”:[0.123337,0.955139]}
但是,我的大部分数据都包含 geo 列的以下内容: “地理”:“无”
这会导致以下 SerDe 错误: 数据不是 JSONObject 而是 java.lang.String,值为 None
格式化我的数据并不是一个真正的选择,因为有将近 1 TB 的原始文本文件,所以我想尽可能避免这种情况!
也许我需要编写自己的 SerDe 来解决这个问题,但有谁知道我是否可以为未填充的地理数据进行强制转换或类似的操作?
完整的表结构:
CREATE TABLE tweets (
coordinates struct<coordinates:array<double>, type:string>,
created_at string,
favorite_count int,
geo struct<coordinates:array<double>, type:string>,
lang string,
place struct<attributes:struct<street_address:string>, bounding_box:struct<coordinates:array<array<array<double>>>, type:string>, country:string, country_code:string, full_name:string, id:string, name:string, place_type:string, url:string>,
retweet_count int,
source string,
text string,
timestamp_ms timestamp)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
with serdeproperties ("ignore.malformed.json" = "true")
location '/user/hue/tweets/';
【问题讨论】: