从多个列创建配置单元Map

vaj7vani  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(305)

我有一个表,其中包含一个id和12列,我想在所有12列中创建Map:
基表:

CREATE TABLE test_transposed(
id string,
jan double,
feb double,
mar double,
apr double,
may double,
jun double,
jul double,
aug double,
sep double,
oct double,
nov double,
dec double)
ROW FORMAT SERDE
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'

最终表格:

CREATE TABLE test_map(
id string,
trans map<String,Double>)
ROW FORMAT SERDE
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'

实现这一目标的最佳方法是什么?我在这里发现了类似的问题,但没用。我不想写 test_transposed 数据到文件,然后创建外部表 test_map 最重要的是。

yc0p9oo0

yc0p9oo01#

create table test_map
stored as textfile
as
select  id
       ,map
        (
             'jan',jan
            ,'feb',feb
            ,'mar',mar
            ,'apr',apr
            ,'may',may
            ,'jun',jun
            ,'jul',jul
            ,'aug',aug
            ,'sep',sep
            ,'oct',oct
            ,'nov',nov
            ,'dec',dec
        )               as trans

from    test_transposed

相关问题