这是表的结构
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 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
案例、 Activity 和人员表已经存在,并且具有选择中显示的结构。
最佳答案
您不能在带有 VALUES 的 INSERT 语句中使用 NAMED_STRUCT(更重要的是,您不能使用任何带有值的 udfs 插入)。这是一个解决方法的工作示例。
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
;
关于java - 如何将数据插入 Hive 2 中的复杂数据类型 “Struct”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50631068/