在Hive中提取结构数组

pch*_*chu 6 hadoop hive hiveql

我在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'  
;
Run Code Online (Sandbox Code Playgroud)

该表的记录可能包含以下数据:

1340321132000, 'some_company', [{"productCategory":"footwear","productId":"nik3756"},{"productCategory":"eyewear","productId":"oak2449"}]
Run Code Online (Sandbox Code Playgroud)

有没有人知道是否有办法简单地从该记录中提取所有productCategory并将其作为productCategories数组返回,而不使用explode.类似于以下内容:

["footwear", "eyewear"] 
Run Code Online (Sandbox Code Playgroud)

或者我是否需要编写自己的GenericUDF,如果是这样,我不太了解Java(一个Ruby人),有人可以给我一些提示吗?我从Apache Hive读了一些关于UDF的说明.但是,我不知道哪种集合类型最适合处理数组,以及处理结构的集合类型是什么?

===

我通过编写GenericUDF来回答这个问题,但我遇到了另外两个问题.正是在这个SO问题中

www*_*www 0

如果数组的大小是固定的(如 2 )。请尝试:

products[0].productCategory,products[1].productCategory
Run Code Online (Sandbox Code Playgroud)

但如果没有,UDF 应该是正确的解决方案。我想你可以在 JRuby 中做到这一点。GL!