Hive 資料匯入方法

2021-10-02 14:25:45 字數 3796 閱讀 6328

hive版本:hive 1.1.0-cdh5.14.2

insert into table tablename [partition (partcol1[=val1], partcol2[=val2] …)] values values_row [, values_row …]

舉例如下:

insert into table score_part partition (month='2020-02') values ('01','01',98),('01','02',95);
standard syntax:

insert overwrite table tablename1 [

partition

(partcol1=val1, partcol2=val2 ...

)[ifnot

exists

]] select_statement1 from from_statement;

insert

into

table tablename1 [

partition

(partcol1=val1, partcol2=val2 ...

)] select_statement1 from from_statement;

hive extension (multiple inserts):

from from_statement

insert overwrite table tablename1 [

partition

(partcol1=val1, partcol2=val2 ...

)[ifnot

exists

]] select_statement1

[insert overwrite table tablename2 [

partition..

.[ifnot

exists

]] select_statement2]

[insert

into

table tablename2 [

partition..

.] select_statement2]..

.;from from_statement

insert

into

table tablename1 [

partition

(partcol1=val1, partcol2=val2 ...

)] select_statement1

[insert

into

table tablename2 [

partition..

.] select_statement2]

[insert overwrite table tablename2 [

partition..

.[ifnot

exists

]] select_statement2]..

.;hive extension (dynamic partition inserts):

insert overwrite table tablename partition

(partcol1[

=val1]

, partcol2[

=val2]..

.) select_statement from from_statement;

insert

into

table tablename partition

(partcol1[

=val1]

, partcol2[

=val2]..

.) select_statement from from_statement;

insert into table score_part partition (month='2020-01') select s_id, c_id, s_score  from score3;
注意:

★需要開啟動態分割槽功能;

★設定為nonstrict模式(允許不指定分割槽插入);

★selec子句最後乙個字段,必須為分割槽字段;

--開啟動態分割槽功能

set hive.exec.dynamic.partition=true;

--設定hive為非嚴格模式

set hive.exec.dynamic.partition.mode=nonstrict;

--動態載入資料到分割槽表

insert into table order_dynamic_partition partition(order_time)

select order_number, order_price, order_time from t_order;

create table if not exists score_part as select * from score;
注意:匯入本地檔案需用local關鍵字

load data [local] inpath 『filepath』 [overwrite] into table tablename [partition (partcol1=val1, partcol2=val2 …)]

load data local inpath '/home/hadoop/hive/data/score.csv' overwrite into table score_part partition (month='2020-02');
load data inpath '/hivedatas/score.csv' overwrite into table score_part partition (month='2020-02');
建立表

0: jdbc:hive2://node03:10000> create external table score8 like score4

. . . . . . . . . . . . . . > location '/scoredatas';

建立目錄,並上傳資料檔案

0: jdbc:hive2://node03:10000> dfs -mkdir /scoredatas;

0: jdbc:hive2://node03:10000> dfs -put /home/hadoop/hive/data/score.csv /scoredatas/;

查詢資料

0: jdbc:hive2://node03:10000> select * from score8;
注意:import的檔案需為export命令匯出的

0: jdbc:hive2://node03:10000> create table score9 like score4;

no rows affected (0.123 seconds)

0: jdbc:hive2://node03:10000> export table score4 to '/score4';

no rows affected (0.203 seconds)

0: jdbc:hive2://node03:10000> import table score9 from '/score4';

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 匯入匯出資料

將檔案中的資料載入到表中 load data local inpath examples files kv1.txt overwrite into table pokes 載入本地資料,同時給定分割槽資訊 load data local inpath examples files kv2.txt o...