您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“hive導(dǎo)入數(shù)據(jù)的方式有哪些”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
load
語(yǔ)法: load data [local] inpath ‘xx’ into table 表名 partition()
local: 如果導(dǎo)入的文件在本地文件系統(tǒng),需要加上local,使用put將本地上傳到hdfs
不加local默認(rèn)導(dǎo)入的文件是在hdfs,使用mv將源文件移動(dòng)到目標(biāo)目錄
hadoop fs -put department /
load data inpath ‘/department’ into table deptpart3 partition(area=‘suzhou’);
insert
insert方式運(yùn)行MR程序,通過(guò)程序?qū)?shù)據(jù)輸出到表目錄!
在某些場(chǎng)景,必須使用insert方式來(lái)導(dǎo)入數(shù)據(jù):
①向分桶表插入數(shù)據(jù)
②如果指定表中的數(shù)據(jù),不是以純文本形式存儲(chǔ),需要使用insert方式導(dǎo)入
語(yǔ)法: insert into|overwrite table 表名 select xxx | values(),(),()
insert into: 向表中追加新的數(shù)據(jù)
insert overwrite: 先清空表中所有的數(shù)據(jù),再向表中添加新的數(shù)據(jù)
特殊情況: 多插入模式(從一張?jiān)幢聿樵?xún),向多個(gè)目標(biāo)表插入)
from 源表
insert xxxx 目標(biāo)表 select xxx
insert xxxx 目標(biāo)表 select xxx
insert xxxx 目標(biāo)表 select xxx
舉例: from deptpart2
insert into table deptpart1 partition(area='huaxi') select deptno,dname,loc
insert into table deptpart1 partition(area='huaxinan') select deptno,dname,loc
1
2
3
4
5
6
7
8
9
10
11
12
13
location
在建表時(shí),指定表的location為數(shù)據(jù)存放的目錄
create external table if not exists default.deptpart3(deptno int,
dname string,
loc int) PARTITIONED BY(area string)
row format delimited fields terminated by ‘\t’
location ‘hdfs://hadoop1:9000/deptpart3’;
導(dǎo)出
insert : 將一條sql運(yùn)算的結(jié)果,插入到指定的路徑
語(yǔ)法: insert overwrite [local] directory ‘/opt/module/datas/export/student’
row format xxxx
select * from student;
export : 既能導(dǎo)出數(shù)據(jù),還可以導(dǎo)出元數(shù)據(jù)(表結(jié)構(gòu))!
export會(huì)在hdfs的導(dǎo)出目錄中,生成數(shù)據(jù)和元數(shù)據(jù)!
導(dǎo)出的元數(shù)據(jù)是和RDMS無(wú)關(guān)!
如果是分區(qū)表,可以選擇將分區(qū)表的部分分區(qū)進(jìn)行導(dǎo)出!
語(yǔ)法: export table 表名 [partition(分區(qū)信息) ] to 'hdfspath'
1
export table deptpart1 partition(area=‘huazhong’) to ‘/export1’;
import
不僅可以導(dǎo)入數(shù)據(jù)還可以順便導(dǎo)入元數(shù)據(jù)(表結(jié)構(gòu))。Import只能導(dǎo)入export輸出的內(nèi)容!
IMPORT [[EXTERNAL] TABLE 表名(新表或已經(jīng)存在的表) [PARTITION (part_column=“value”[, …])]]
FROM ‘source_path’
[LOCATION ‘import_target_path’]
①如果向一個(gè)新表中導(dǎo)入數(shù)據(jù),hive會(huì)根據(jù)要導(dǎo)入表的元數(shù)據(jù)自動(dòng)創(chuàng)建表
②如果向一個(gè)已經(jīng)存在的表導(dǎo)入數(shù)據(jù),在導(dǎo)入之前會(huì)先檢查表的結(jié)構(gòu)和屬性是否一致
只有在表的結(jié)構(gòu)和屬性一致時(shí),才會(huì)執(zhí)行導(dǎo)入
③不管表是否為空,要導(dǎo)入的分區(qū)必須是不存在的
import external table importtable1 from '/export1'
“hive導(dǎo)入數(shù)據(jù)的方式有哪些”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。