操作:
1、從db2 中導出數據到txt中
2、修改文件中的分隔符為“:”
3、在hive中新建表(建表時需要制定分隔符)
4、導入數據
--------
1、從db2 中導出數據到txt中
db2 -x "select col1,col2,col3 from tbl_name where xxx with ur">filename.txt
2、修改文件中的分隔符為“:”
cat filename.txt | awk '{print $1":"$2":"$3}'>filename1.txt
3、在hive中新建表(建表時需要制定分隔符)
ROW FORMAT DELIMITED 分隔符設置開始語句
FIELDS TERMINATED BY:設置字段與字段之間的分隔符
COLLECTION ITEMS TERMINATED BY:設置一個復雜類型(array,struct)字段的各個item之間的分隔符
MAP KEYS TERMINATED BY:設置一個復雜類型(Map)字段的key value之間的分隔符
Hive> create table t(id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>)
> row format delimited
> fields terminated by '\t'
> collection items terminated by ','
> map keys terminated by ':'
> lines terminated by '\n';
OK
Time taken: 0.287 seconds
ROW FORMAT DELIMITED 必須在其它分隔設置之前,也就是分隔符設置語句的最前
LINES TERMINATED BY必須在其它分隔設置之后,也就是分隔符設置語句的最后,否則會報錯
hive> create table t (id struct<id1:int,id2:int,id3:int>,name array<string>,xx map<int,string>)
> row format delimited
> fields terminated by '\t'
> lines terminated by '\n'
> collection items terminated by ','
> map keys terminated by ':';
FAILED: ParseException line 5:0 missing EOF at 'collection' near ''\n''
4、導入數據至hive中
load data local inpath 'filename1.txt' into table tbl_cdhd_usr_id_xxt_tmp