简体   繁体   English

如何在Hive 2中将数据插入复杂数据类型“Struct”

[英]How do you insert data into complex data type “Struct” in Hive 2

This is the structure of the table 这是表的结构

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. case,activity和person表已经存在,并且具有select中显示的结构。

you cannot use the NAMED_STRUCT in an INSERT statement with VALUES (even more, you cannot use any udfs inserting with values) . 你不能在带有VALUES的INSERT语句中使用NAMED_STRUCT(更多的是,你不能使用任何带有值的udfs插入)。 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 
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM