hive - Insert values in Hive tables with primitive and complex data type
问题描述
If i have only one table such as student and table definition and schema is such as hive>
create table student1(S_Id int,
> S_name Varchar(100),
> Address Struct<a:int, b:String, c:int>,
> marks Map<String, Int>);
OK
Time taken: 0.439 seconds
hive>
hive> Describe Student1;
OK
s_id int
s_name varchar(100)
address struct<a:int,b:string,c:int>
marks map<string,int>
Time taken: 0.112 seconds, Fetched: 4 row(s)
Now i am trying to insert values into that Student1 table such as
hive> insert into table student1 values(1, 'Afzal', Struct(42, 'nelson Ave NY', 08309),MAP("MATH", 89));
I am getting that error
FAILED: SemanticException [Error 10293]: Unable to create temp file for insert values Expression of type TOK_FUNCTION not supported in insert/values
How do i insert values for one record in one go, Can anyone please help me?
解决方案
它在使用insert .. select
语句时起作用。创建一个单行的虚拟表,或使用一些现有的表 + 添加limit 1
。还使用named_struct
功能:
演示:
hive> insert into table student1
select 1 s_id,
'Afzal' s_name,
named_struct('a',42, 'b','nelson Ave NY', 'c',08309) address,
MAP('MATH', 89) marks
from default.dual limit 1; --this is dummy table
Loading data to table dev.student1
Table dev.student1 stats: [numFiles=1, numRows=1, totalSize=48, rawDataSize=37]
OK
Time taken: 27.175 seconds
检查数据:
hive> select * from student1;
OK
1 Afzal {"a":42,"b":"nelson Ave NY","c":8309} {"MATH":89}
Time taken: 0.125 seconds, Fetched: 1 row(s)
推荐阅读
- .net - NGEN 和 NGEN 关键计划任务有什么区别?
- azure - 我可以在本地保存 Azure VM 自定义映像吗?
- google-bigquery - 我们可以使用“创建一个新的 BigQuery 表作为触发运行预定义 BigQuery 查询的事件”吗?
- javascript - 简单文件上传不适用于 Vue.js 和 Flask 框架
- jquery - 防止元素在jquery中向上移动DOM太远
- javascript - 从 Express Server 接收 JSON 数据时无法识别语法错误
- c# - 使用 ProvisionPackageForAllUsersAsync 安装 UWP 包
- r - R 从子元素中选择 XML 属性并生成数据框
- android - Kotlinx - 为视图使用不同的根视图
- angular - Angular mat-table:如何使用更新的资源作为响应刷新数据源?