蜂巢:无法插入带有地图列的表格

时间:2019-03-01 00:38:17

标签: java hive hiveql

这是我的桌子

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 0.13.1-SNAPSHOT

1 个答案:

答案 0 :(得分:0)

您可以通过两种方式将数据加载到配置单元表中
*使用HDFS命令:
您的表格结构应以“ =”(任何定界符)结尾的MAP KEYS结束

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'

示例input.txt
2月= 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');
  • 使用查询:

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

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

注意:test_tab表不一定需要以'='约束的MAP键。

相关问题