HIVE:如何将数据插入数据类型为MAP的列(字符串:Array <int>)

时间:2018-09-04 13:31:31

标签: hive

我有一个表CLASS1,如下所示

 hive> select * from class1;
 OK
 NULL   student_name    NULL    NULL    NULL
 5  david   60  70  80
 5  reena   55  40  80
 7  joseph  66  75  89
 Time taken: 0.659 seconds, Fetched: 4 row(s)
 hive> desc class1;
 OK
 class                  tinyint                                     
 student_name           varchar(30)                                 
 marks_english          int                                         
 marks_maths            int                                         
 marks_science          int                                         
 Time taken: 0.553 seconds, Fetched: 5 row(s)

现在我想将以下格式的数据插入到新表中

    Class     name_marks
    5   {david:[60,70,80]}
    5   {reena:[55,40,80]}
    7   {joseph:[66,75,89]}

有人可以告诉我如何创建新表并以所需格式插入数据吗?

1 个答案:

答案 0 :(得分:0)

尝试此查询:

create table new_table as
select class
     , MAP(student_name, ARRAY(marks_english, marks_maths, marks_science) as name_marks
  from old_table;