Hive 8 資料匯入hive的多種方式

2021-08-31 04:08:04 字數 2590 閱讀 9251

load data local inpath 『filepath' [overwrite] into table tablename [partition (partcol1=val1,...)]
注意:

(1)local代表本地

(2)overwrite代表覆蓋,如果不加,就是追加

(3)分割槽表載入,特殊性  partition (partcol1=val1,...)

例項1:

load data local inpath '/opt/datas/emp.txt' into table emp_part2 partition(`datetime`='20171209',hour='01');
例項2:

(1)準備資料

[root@localhost data]# more data1.txt

1,tom,m

3,mike,m

[root@localhost data]# more data2.txt

2,mary,f

(2)準備分割槽表

hive> desc patition_table;

oksid int

sname string

gender string

# partition information

# col_name data_type comment

gender string

time taken: 0.328 seconds, fetched: 8 row(s)

(3)匯入資料到分割槽表

hive> load data local inpath '/root/data/data1.txt' into table patition_table partition (gender='m');

copying data from file:/root/data/data1.txt

copying file: file:/root/data/data1.txt

loading data to table default.patition_table partition (gender=m)

partition default.patition_table stats: [numfiles=1, numrows=0, totalsize=17, rawdatasize=0]

oktime taken: 2.772 seconds

hive> load data local inpath '/root/data/data2.txt' into table patition_table partition (gender='f');

copying data from file:/root/data/data2.txt

copying file: file:/root/data/data2.txt

loading data to table default.patition_table partition (gender=f)

partition default.patition_table stats: [numfiles=1, numrows=0, totalsize=9, rawdatasize=0]

oktime taken: 1.615 seconds

沒有local

load data  inpath 『filepath' [overwrite] into table tablename [partition (partcol1=val1,...)]
insert into table tablename select * from tablenamesource
資料本身已經存在hdfs上,建表的時候指定hdfs上的路徑

create table emp_inner(

empno int,

ename string,

job string,

mgr int,

hiredate string,

sal double,

comm double,

deptno int

)row format delimited fields terminated by '\t'

location '/user/hive/warehouse/hadoop.db/emp';

特殊:如果分割槽表,要記得alter table emp_part add(增加)/drop(刪除) partition(`datetime`='20171209',hour='03').例如 

alter table emp_part2 add partition(`datetime`='20171209',hour='03');
create table track_log.result as

select `date`,hour,count(url) pv,count(distinct guid) uv from track_log.yhd_part group by `date`,hour;

HIVE資料匯入

1.text資料檔案匯出text資料表中 資料格式 建立相應的資料表 create table if not exists text table id int,count int comment table desc partitioned by date int row format delimi...

Hive資料匯入

1.操作準備資料來源 drop table if exists b create table b as select id,name,tel,age from b 2.複製檔案 如果資料檔案恰好是使用者需要的格式,那麼只需要複製檔案或資料夾就可以 hadoop fs cp source path t...

hive的資料匯入

hive的資料匯入 使用load語句 load data local inpath filepath overwrite into table tablename partition partcol1 val1,partcol2 val2,將student1.txt資料匯入表t2 load data...