db2導出數據並導入hive臨時表中


操作:

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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM