Hive: Cannot insert into table with map column

若如初见. 提交于 2019-12-11 18:34:13

问题


here is my table

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)

and here is my insert statement

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

but i get

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

I also tried

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

what am i doing wrong?

Here is hive version info

Hive 0.13.1-SNAPSHOT


回答1:


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'

sample input.txt
Feb=28

hadoop fs -put input.txt HDFS_dest_Path

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');
  • Using Queries:

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;

NOTE: MAP KEYS TERMINATED BY '=' constraint not necessarily required for test_tab table.



来源:https://stackoverflow.com/questions/54936354/hive-cannot-insert-into-table-with-map-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!