如何在Hive 2中将数据插入复杂的数据类型"Struct"中 [英] How do you insert data into complex data type “Struct” in Hive 2

查看:79
本文介绍了如何在Hive 2中将数据插入复杂的数据类型"Struct"中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是表格的结构

CREATE TABLE warehouse (
 time timestamp, 
 person struct<id : int, name: string, organization : string>, 
 activity struct<id : int, name: string>, 
 case struct<id : int, name: string, organization : string>
);

创建该表没有问题,问题在于如何将数据插入到该表中.我正在尝试类似的方法,但是它不起作用

The table is created without problems, the problem is how to insert data into that table. I was trying something like this but it does not work

INSERT INTO TABLE warehouse VALUES('2018-05-31'),
SELECT NAMED_STRUCT('id', 1, 'name', 'Alex', 'organization', 'CITI') AS person,
SELECT NAMED_STRUCT('id', 1, 'name', 'Buy') AS activity,
SELECT NAMED_STRUCT('id', 1, 'name', 'Gold', 'organization', 'London') AS case
FROM case 

案例,活动和人员表已经存在,并且具有在选择中显示的结构.

The case, activity and person tables already exist and have the structure shown in the select.

推荐答案

您不能在带有VALUES的INSERT语句中使用NAMED_STRUCT(甚至不能使用任何插入有值的udfs).这是一个变通的工作示例.

you cannot use the NAMED_STRUCT in an INSERT statement with VALUES (even more, you cannot use any udfs inserting with values) . This is a workaround working example.

CREATE TABLE warehouse (
 time timestamp, 
 person struct<id : int, name: string, organization : string>, 
 activity struct<id : int, name: string>, 
 `case` struct<id : int, name: string, organization : string>
);


INSERT INTO TABLE warehouse
select 
'2018-05-31',
NAMED_STRUCT('id', 1, 'name', 'Alex', 'organization', 'CITI'),
NAMED_STRUCT('id', 1, 'name', 'Buy'),
NAMED_STRUCT('id', 1, 'name', 'Gold', 'organization', 'London') 
FROM (
select '1'
) t 
;

这篇关于如何在Hive 2中将数据插入复杂的数据类型"Struct"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆