如何将 array<map<string,int>> 插入到 hive 表中?

问题描述

我有一个蜂巢表如下:

0: jdbc:hive2://Desktop:10000> desc tb_test2;
+-------------+-------------------------+----------+
|  col_name   |        data_type        | comment  |
+-------------+-------------------------+----------+
| name        | string                  |          |
| score_list  | array<map<string,int>>  |          |
+-------------+-------------------------+----------+

我想插入这样的数据:

A   [{"math":100,"english":90,"history":85}]  
B   [{"math":95,"english":80,"history":100}]  
C   [{"math":80,"histroy":100}]  

我试过这样:

0: jdbc:hive2://Desktop:10000> insert into tb_test2 values("A",Map("math":100,"history":85));

但得到错误

Error: Error while compiling statement: Failed: ParseException line 1:42 cannot recognize input near '"math"' ':' '100' in constant (state=42000,code=40000)

解决方法

我认为应该使用逗号,并且您也需要指定数组。

insert into tb_test2 select "A",array(map("math",100,"english",90,"history",85)) from (select 1) x;

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...