我已经阅读了网站上的所有示例,但它们都不适用于我。我添加了Brickhouse UDFS:
create temporary function collect_struct as 'brickhouse.udf.collect.CollectUDAF'
和
CREATE TEMPORARY FUNCTION collect AS 'brickhouse.udf.collect.CollectUDAF'
我使用了Hive SELECT statement to create an ARRAY of STRUCTS和
Hive select data into an array of structs
我的SQL:
create temporary function collect as 'brickhouse.udf.collect.CollectUDAF';
CREATE TABLE test ( <br>
house_id bigint,<br>
first_name string,<br>
last_name string<br>
);
INSERT INTO test VALUES<br>
(1,"Bob","jones"),<br>
(1,"Jenny","jones"),<br>
(2,"Sally","johnson"),<br>
(3,"John","smith"),<br>
(3,"Barb","smith");
select house_id<br>
,collect(named_struct("first_name", first_name, "last_name", last_name))<br>
from test<br>
group by house_id;
我总是得到同样的错误:
失败:ClassCastException org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector 无法施展 org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector
有什么想法吗?
答案 0 :(得分:1)
我正在使用Hive版本1.1.0,并且能够创建结构数组,而无需Brickhouse jar文件的UDF。试试这个。
SELECT house_id ,
collect_list(named_struct("first_name", first_name, "last_name", last_name))
FROM house
GROUP BY house_id;
1 [{"first_name":"Bob","last_name":"jones"},{"first_name":"Jenny","last_name":"jones"}]
2 [{"first_name":"Sally","last_name":"johnson"}]
3 [{"first_name":"John","last_name":"smith"},{"first_name":"Barb","last_name":"smith"}]