提取结构数组我在蜂房在蜂巢
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数组返回,而不使用爆炸。像下面这样:
["footwear", "eyewear"]
或者我需要写我自己GenericUDF,如果是这样,我不知道太多的Java(Ruby的人),能有人给我一些提示?我从Apache Hive阅读了关于UDF的一些说明。但是,我不知道哪个集合类型最适合处理数组,以及要处理结构的集合类型是什么?
===
我有所写一个GenericUDF回答了这个问题,但我遇到了其他2个问题。它是在这个SO Question
谢谢,但数组的大小是不固定的。虽然使用JRuby的好主意,为此,需要使用Java来编写GenericUDF。更糟的是,在编写GenericUDF时没有太多参考。 – pchu 2013-03-26 12:23:14