您如何将数据插入复杂的数据类型"Struct"?在蜂巢 [英] How do you insert data into complex data type "Struct" in Hive

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

问题描述

我对Hive和Stack Overflow完全陌生.我正在尝试创建具有复杂数据类型"STRUCT"的表,然后在Hive中使用INSERT INTO TABLE填充它.

I'm completely new to Hive and Stack Overflow. I'm trying to create a table with complex data type "STRUCT" and then populate it using INSERT INTO TABLE in Hive.

我正在使用以下代码:

CREATE TABLE struct_test
(
 address STRUCT<
                houseno:    STRING
               ,streetname: STRING
               ,town:       STRING
               ,postcode:   STRING
               >
);

INSERT INTO TABLE struct_test
SELECT NAMED_STRUCT('123', 'GoldStreet', London', W1a9JF') AS address
FROM dummy_table
LIMIT 1;

我收到以下错误:

编译语句时发生错误:FAILED:语义异常[错误 10044]:无法插入目标,因为列号类型为 不同的'struct_test':无法将列0从struct转换为 数组>.

Error while compiling statement: FAILED: semanticException [Error 10044]: Cannot insert into target because column number type are different 'struct_test': Cannot convert column 0 from struct to array>.

我能够成功使用类似的代码来创建和填充数据类型Array,但是Struct却遇到了困难.我已经尝试了很多在网上找到的代码示例,但是似乎没有一个对我有用……我对此非常感谢,因为我已经坚持了很长时间了!谢谢.

I was able to use similar code with success to create and populate a data type Array but am having difficulty with Struct. I've tried lots of code examples I've found online but none of them seem to work for me... I would really appreciate some help on this as I've been stuck on it for quite a while now! Thanks.

推荐答案

您的SQL错误.您应该使用sql:

your sql error. you should use sql:

INSERT INTO TABLE struct_test 
       SELECT NAMED_STRUCT('houseno','123','streetname','GoldStreet', 'town','London', 'postcode','W1a9JF') AS address 
           FROM dummy_table LIMIT 1;

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

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