问题描述
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;