蜂巢:无法插入带有地图列的表格 [英] Hive: Cannot insert into table with map column
问题描述
这是我的桌子
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
我在做什么错了?
以下是配置单元版本信息
Here is hive version info
Hive 0.13.1-SNAPSHOT
推荐答案
您可以通过两种方式将数据加载到配置单元表中
*使用HDFS命令:
您的表格结构应以MAP KEYS终止,并以'='(任何定界符)
You can load the data into the hive table in two ways
* Using HDFS command:
Your table structure should by MAP KEYS TERMINATED BY '=' (Any delimiter)
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
sample input.txt
Feb=28
hadoop fs -put input.txt HDFS_dest_Path
将文件上传到Hadoop fs之后,然后将数据加载到表中:
Once you uplload the file into the Hadoop fs, then load data into the table:
load data inpath <location of the hadoop table> into table test_sample partition(test_date='2019-02-28');
- 使用查询:
如果文件系统中已经存在类似的数据,则可以通过配置单元查询将其插入到表中.
If similar data already present in the file system you can insert that into your table via hive Query.
INSERT INTO TABLE test_tab PARTITION(test_date= '2019-02-28')
select map from test_sample;
注意:test_tab表不一定需要以'='约束的MAP键.
NOTE: MAP KEYS TERMINATED BY '=' constraint not necessarily required for test_tab table.
这篇关于蜂巢:无法插入带有地图列的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!