【发布时间】:2013-03-15 18:33:09
【问题描述】:
我在 hive 中有一个外部表
CREATE EXTERNAL TABLE FOO (
TS string,
customerId string,
products array< struct <productCategory:string, productId:string> >
)
PARTITIONED BY (ds string)
ROW FORMAT SERDE 'some.serde'
WITH SERDEPROPERTIES ('error.ignore'='true')
LOCATION 'some_locations'
;
表的记录可能包含以下数据:
1340321132000, 'some_company', [{"productCategory":"footwear","productId":"nik3756"},{"productCategory":"eyewear","productId":"oak2449"}]
有谁知道是否有一种方法可以简单地从该记录中提取所有 productCategory 并将其作为 productCategories 数组返回而不使用explode。类似于以下内容:
["footwear", "eyewear"]
或者我需要编写自己的GenericUDF,如果是这样,我不太了解Java(一个Ruby人),有人可以给我一些提示吗?我从 Apache Hive 阅读了一些关于 UDF 的说明。但是,我不知道哪种集合类型最适合处理数组,以及哪种集合类型最适合处理结构?
===
我已经通过编写 GenericUDF 回答了这个问题,但我遇到了另外 2 个问题。在这个SO Question
【问题讨论】: