Hive 資料匯入匯出方式小結

2021-10-23 13:58:09 字數 3138 閱讀 3523

1.最基本的匯入方式:load

load data [ local ] inpath '/opt/module/datas/test.txt' [overwrite] into table student [partition (partcol1=val1,…)];

栗子:

a).載入本地檔案到 hive

hive (default)> load data local inpath '/opt/module/datas/test.txt' into table default.test;

b).載入 hdfs 檔案到 hive

hive (default)> load data inpath '/user/lpy/hive/test.txt' into table default.test;

c).載入資料覆蓋表中已有的資料

hive (default)> load data inpath '/user/lpy/hive/test.txt' overwrite into table default.test;

d).載入資料到二級分割槽表中

hive (default)> load data local inpath '/opt/module/datas/test.txt' into table

default.test partition(month='200008', day='20');

2.通過查詢語句向表中插入資料(insert)

栗子:

a).基本資料插入

hive (default)> insert into table  test partition(month='200008') values(1,'zhangsan'),(2,』lisi』);

b).根據單張表查詢結果插入

hive (default)> insert overwrite table student partition(month='201708') select id, name from student where month='201709';

c).多表(多分割槽)插入模式(根據多張表查詢結果)

hive (default)> from test

insert overwrite table test partition(month='200207')

select id, name where month='200209'

insert overwrite table test partition(month='200206')

select id, name where month='200209';

3.查詢語句中建立表並載入資料(as select)

a).根據查詢結果建立表(查詢的結果會新增到新建立的表中)

hive (default)> create table if not exists test2 as select id, name from test;

4.建立表時通過location指定載入資料路徑

hive (default)> create external table if not exists test3(

id int, name string

)row format delimited fields terminated by '\t'

location '/test;

5.import 資料到指定 hive 表中

注意:

hive (default)> import table test2 partition(month='200209') from

'/user/hive/warehouse/export/test';

1.insert匯出

a).將查詢的結果匯出到本地

hive (default)> insert overwrite local directory '/opt/module/datas/export/test'

select * from test;

b).將查詢的結果格式化匯出到本地

hive(default)>insert overwrite local directory '/opt/module/datas/export/test1'

row format delimited fields terminated by '\t' select * from test;

c).將查詢的結果匯出到hdfs上

hive (default)> insert overwrite directory '/user/lpy/test2'

row format delimited fields terminated by '\t'

select * from test;

2.hadoop命令匯出到本地

hive (default)> dfs -get /user/hive/warehouse/test/month=200209/000000_0

/opt/module/datas/export/test3.txt;

3.hive shell 命令匯出

基本語法:( hive -f/-e 執行語句或者指令碼 > file )

[lpy@hadoop102 hive]$ bin/hive -e 'select * from default.test;' >

/opt/module/datas/export/test4.txt;

4.export匯出到hdfs上

hive (default)> export table default.test to '/user/hive/warehouse/export/test';
注意:

Hive匯入匯出方式

從本地匯入 load data local inpath home 1.txt overwrite into table student 從hdfs匯入 load data inpath user hive warehouse 1.txt overwrite into table student 查...

Hive幾種資料匯入匯出方式

匯入 hive幾種資料匯入方式 匯出 1.拷貝檔案 如果資料檔案恰好是使用者需要的格式,那麼只需要拷貝檔案或資料夾就可以。hadoop fs cp source path target path 2.匯出到本地檔案系統 不能使用insert into local directory來匯出資料,會報錯...

Hive 匯入匯出資料

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