我有一个包含id和12列的表,我想在所有12列中创建地图:
基本表格:
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'
实现这一目标的最佳方法是什么?
我发现了类似的问题here,但它没有帮助。我不想将test_transposed
数据写入文件,然后在其上创建外部表test_map
。
答案 0 :(得分:4)
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