Hive:无法使用地图列插入表中



这是我的表

hive> desc test_tab;
OK
test_map    map<string,string>
test_date               string
# Partition Information
# col_name              data_type               comment
test_date               string
Time taken: 0.087 seconds, Fetched: 7 row(s)

这是我的插入语句

hive> insert into table test_tab
    > values ('2018-02-28', map("key","val"));

但我得到

FAILED: ParseException line 2:0 cannot recognize input near 'values' '(' ''2018-02-28'' in select clause

我也尝试了

hive> insert into table test_tab partition (test_date = '2018-02-28')
    > select  map("key","val");
FAILED: NullPointerException null

我在做什么错?

这是Hive版本信息

Hive 0.13.1-SNAPSHOT

您可以通过两种方式将数据加载到蜂巢表中
*使用HDFS命令:
您的表结构应由" ="终止的地图键

终止
CREATE TABLE `test_sample`(
  `test_map` map<string,string>   
)
PARTITIONED BY (
  `test_date ` string)
ROW FORMAT DELIMITED
  FIELDS TERMINATED BY ','
  MAP KEYS TERMINATED BY '='
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'

示例输入.txt
feb = 28

hadoop fs -put input.txt HDFS_dest_Path

将文件加载到hadoop fs中后,然后将数据加载到表中:

load data inpath <location of the hadoop table> into table test_sample partition(test_date='2019-02-28');
  • 使用查询:

如果文件系统中已经存在类似的数据,则可以通过Hive查询将其插入表中。

INSERT INTO TABLE test_tab PARTITION(test_date= '2019-02-28')
select map from  test_sample;

注意:test_tab表不一定需要的'='约束终止的地图键。

最新更新