国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

hive的數(shù)據(jù)導(dǎo)入

這篇具有很好參考價(jià)值的文章主要介紹了hive的數(shù)據(jù)導(dǎo)入。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1 數(shù)據(jù)導(dǎo)入

1.1 向表中裝載數(shù)據(jù)(Load)

1)語(yǔ)法

hive> 
load data [local] inpath '數(shù)據(jù)的path' 
[overwrite] into table table_name[partition (partcol1=val1,…)];

(1)load data:表示加載數(shù)據(jù)。

(2)local:表示從本地加載數(shù)據(jù)到Hive表;否則從HDFS加載數(shù)據(jù)到Hive表。

(3)inpath:表示加載數(shù)據(jù)的路徑。

(4)overwrite:表示覆蓋表中已有數(shù)據(jù),否則表示追加。

(5)intotable:表示加載到哪張表。

(6)student:表示具體的表。

(7)partition:表示上傳到指定分區(qū)。

2)實(shí)操案例

(0)創(chuàng)建一張表

hive (default)> 
create table student(
   id int, 
   name string
) 
row format delimited fields terminated by'\t';

(1)加載本地文件到hive

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

(2)加載HDFS文件到hive中

①上傳文件到HDFS

hive (default)> dfs -put /opt/module/hive/datas/student.txt/user/atguigu;

②加載HDFS上數(shù)據(jù),導(dǎo)入完成后去HDFS上查看文件是否還存在

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

(3)加載數(shù)據(jù)覆蓋表中已有的數(shù)據(jù)

①上傳文件到HDFS

hive (default)> dfs -put/opt/module/hive/datas/student.txt /user/atguigu;

②加載數(shù)據(jù)覆蓋表中已有的數(shù)據(jù)

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

1.2 通過(guò)查詢(xún)語(yǔ)句向表中插入數(shù)據(jù)(Insert)

1)創(chuàng)建一張表

hive (default)> 
create table student3(
   id int, 
   name string
) 
row format delimited fields terminated by'\t';

2)基本模式插入數(shù)據(jù)

hive (default)> insert into table  student3 values(1,'wangwu'),(2,'zhaoliu');

3)根據(jù)查詢(xún)結(jié)果插入數(shù)據(jù)

hive (default)> insert overwrite tablestudent3 
select 
   id, 
   name 
from student 
where id < 1006;

insert into:以追加數(shù)據(jù)的方式插入到表或分區(qū),原有數(shù)據(jù)不會(huì)刪除。

insert overwrite:會(huì)覆蓋表中已存在的數(shù)據(jù)。

注:insert不支持插入部分字段,并且后邊跟select語(yǔ)句時(shí),select之前不能加as,加了as會(huì)報(bào)錯(cuò),一定要跟下面的as select區(qū)分開(kāi)。

1.3 查詢(xún)語(yǔ)句中創(chuàng)建表并加載數(shù)據(jù)(As Select)

根據(jù)查詢(xún)結(jié)果創(chuàng)建表(查詢(xún)的結(jié)果會(huì)添加到新創(chuàng)建的表中)。

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

1.4 創(chuàng)建表時(shí)通過(guò)Location指定加載數(shù)據(jù)路徑

1)上傳數(shù)據(jù)到HDFS上

[lily@hadoop102 datas]$ hadoop fs-mkdir -p /student5;
[lily@hadoop102 datas]$ hadoop fs -putstudent.txt /student5

2)創(chuàng)建表,并指定在HDFS上的位置

hive (default)>
create external table if notexists student5(
   id int, 
   name string
)
row format delimited fields terminated by'\t'
location '/student5';

3)查詢(xún)數(shù)據(jù)

hive (default)> select * from student5;

1.5 Import數(shù)據(jù)到指定Hive表中

注:先用export導(dǎo)出后,再將數(shù)據(jù)導(dǎo)入。并且因?yàn)閑xport導(dǎo)出的數(shù)據(jù)里面包含了元數(shù)據(jù),因此import要導(dǎo)入的表不可以存在,否則報(bào)錯(cuò)。

hive (default)> 
import table student2 from '/user/hive/warehouse/export/student';

2 數(shù)據(jù)導(dǎo)出

2.1 Insert導(dǎo)出

1)將查詢(xún)的結(jié)果導(dǎo)出到本地

hive (default)> 
insert overwrite local directory'/opt/module/hive/datas/export/student' 
select * from student;

2)將查詢(xún)的結(jié)果格式化導(dǎo)出到本地

hive(default)> 
insert overwrite local directory'/opt/module/hive/datas/export/student' 
row format delimited fields terminated by'\t' 
select * from student;

3)將查詢(xún)的結(jié)果導(dǎo)出到HDFS上(沒(méi)有l(wèi)ocal)

hive (default)> insert overwrite directory'/user/atguigu/student2' 
row format delimited fields terminated by'\t' 
select * from student;

:insert導(dǎo)出,導(dǎo)出的目錄不用自己提前創(chuàng)建,Hive會(huì)幫我們自動(dòng)創(chuàng)建,但是由于是overwrite,所以導(dǎo)出路徑一定要寫(xiě)具體,否則很可能會(huì)誤刪數(shù)據(jù)。

2.2 Export導(dǎo)出到HDFS

hive (default)> 
export table default.student to 
 '/user/hive/warehouse/export/student';

注:Export和Import主要用于兩個(gè)Hadoop平臺(tái)集群之間Hive表遷移,不能直接導(dǎo)出到本地。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-635320.html

到了這里,關(guān)于hive的數(shù)據(jù)導(dǎo)入的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • (C#) IIS 響應(yīng)標(biāo)頭過(guò)濾敏感信息(如:Server/X-Powered-By等) 運(yùn)維知識(shí)

    (C#) IIS 響應(yīng)標(biāo)頭過(guò)濾敏感信息(如:Server/X-Powered-By等) 運(yùn)維知識(shí)

    再一次凈網(wǎng)行動(dòng)中,客戶(hù)要求安全改造發(fā)現(xiàn)了接口請(qǐng)求的header標(biāo)頭中出現(xiàn)如圖中的敏感信息。 ? 其意義在于告知瀏網(wǎng)站是用什么語(yǔ)言或者框架編寫(xiě)的。解決辦法就是修改該響應(yīng)頭為一個(gè)錯(cuò)誤的值,將攻擊者導(dǎo)向一個(gè)錯(cuò)誤的方向。 這里只說(shuō)windows 的iis環(huán)境,不考慮其他服務(wù)器的

    2024年02月11日
    瀏覽(115)
  • 二百零九、Hive——with嵌套語(yǔ)句報(bào)錯(cuò):hadoop.hive.ql.parse.SemanticException: Line 2:5 Ambiguous table alias ‘t2‘

    二百零九、Hive——with嵌套語(yǔ)句報(bào)錯(cuò):hadoop.hive.ql.parse.SemanticException: Line 2:5 Ambiguous table alias ‘t2‘

    在Hive的with嵌套語(yǔ)句時(shí),HQL報(bào)錯(cuò)Line 2:5 Ambiguous table alias \\\'t2\\\' org.apache.hadoop.hive.ql.parse.SemanticException: Line 2:5 Ambiguous table alias \\\'t2\\\' 看報(bào)錯(cuò)提示,Ambiguous table alias \\\'t2\\\',似乎是with嵌套子語(yǔ)句命名t2報(bào)錯(cuò),但是我試了很多其他命名,都報(bào)類(lèi)似的錯(cuò)誤,如果大家知道原因的話還望告知,謝

    2024年01月20日
    瀏覽(17)
  • hive建表,與插入數(shù)據(jù)

    hive建表,與插入數(shù)據(jù)

    思路,hive導(dǎo)入分區(qū)表,只能通過(guò)臨時(shí)表導(dǎo)入。 固建立臨時(shí)表(不分區(qū)),導(dǎo)入數(shù)據(jù)到臨時(shí)表,創(chuàng)建分區(qū)表,通過(guò)【insert 分區(qū)表 select 臨時(shí)表】 導(dǎo)入分區(qū)表 打開(kāi)hue或者直接hive ----------------------------- 創(chuàng)建分區(qū)表 ----------------------------- 外部表external 以日期進(jìn)行分區(qū)partitioned 數(shù)據(jù)

    2024年02月10日
    瀏覽(17)
  • 【大數(shù)據(jù)】Hive 表中插入多條數(shù)據(jù)

    在 Hive 中,我們可以使用 INSERT INTO 語(yǔ)句向表中插入數(shù)據(jù)。當(dāng)我們需要插入多條數(shù)據(jù)時(shí),有多種方式可以實(shí)現(xiàn)。本文將介紹如何在 Hive 表中插入多條數(shù)據(jù),并提供相應(yīng)的代碼示例。 最簡(jiǎn)單的方式是使用單個(gè) INSERT INTO 語(yǔ)句插入多條數(shù)據(jù)。我們可以使用值列表的方式將多條數(shù)據(jù)一

    2024年02月12日
    瀏覽(30)
  • MySQL 數(shù)據(jù)庫(kù) group by 語(yǔ)句怎么優(yōu)化?

    MySQL 數(shù)據(jù)庫(kù) group by 語(yǔ)句怎么優(yōu)化?

    我這里創(chuàng)建一張訂單表 復(fù)制代碼 同時(shí)也在表里插了一些數(shù)據(jù) 現(xiàn)在我們這里執(zhí)行 group by 語(yǔ)句 復(fù)制代碼 很明顯,這里就可以統(tǒng)計(jì)出來(lái) 每件商品一共有多少訂單數(shù)據(jù)! 2.1、explain 分析 不同的數(shù)據(jù)庫(kù)版本,用 explain 執(zhí)行的結(jié)果并不一致,同樣是上面 sql 語(yǔ)句 「MySQL 5.7 版本」 Extr

    2024年02月06日
    瀏覽(17)
  • Hive創(chuàng)建分區(qū)表并插入數(shù)據(jù)

    業(yè)務(wù)中經(jīng)常會(huì)遇到這種需求:數(shù)據(jù)每天全量更新,但是要求月底將數(shù)據(jù)單獨(dú)保存一份以供后期查詢(xún)某月節(jié)點(diǎn)的信息。這時(shí)就要考慮用到Hive的分區(qū)表實(shí)現(xiàn),即按照月份創(chuàng)建分區(qū)表,相當(dāng)于新的月份數(shù)據(jù)保存在新表,進(jìn)而實(shí)現(xiàn)保存了歷史數(shù)據(jù)。 分區(qū)表的創(chuàng)建本質(zhì)是在HDFS創(chuàng)建了一

    2024年02月07日
    瀏覽(22)
  • 大數(shù)據(jù)面試題:Hive的cluster by 、sort by、distribute by 、order by 區(qū)別?

    面試題來(lái)源: 《大數(shù)據(jù)面試題 V4.0》 大數(shù)據(jù)面試題V3.0,523道題,679頁(yè),46w字 參考答案: 可回答:1)Hive的排序函數(shù);2)Hive的排序,以及各自的區(qū)別;3)四個(gè)by的區(qū)別? 參考答案: 共有四種排序:Order By,Sort By,Distribute By,Cluster By 1、Order By :全局排序 對(duì)輸入的數(shù)據(jù)做排

    2024年02月09日
    瀏覽(20)
  • MySql按條件插入數(shù)據(jù),MySQL插入語(yǔ)句寫(xiě)where條件,MySQL在插入時(shí)做冪等

    MySql按條件插入數(shù)據(jù),MySQL插入語(yǔ)句寫(xiě)where條件,MySQL在插入時(shí)做冪等

    使用MySQL的刪、改、查功能時(shí),我們都可以根據(jù)where條件來(lái)對(duì)指定數(shù)據(jù)進(jìn)行操作。 插入語(yǔ)句如何通過(guò)where條件,來(lái)判斷是否允許插入呢? 此時(shí)表里有三條數(shù)據(jù)了: 上面sql執(zhí)行結(jié)果: insert into test_table (id, content) select * from (select ‘4’, ‘內(nèi)容4’) as tmp where not exists ( select 1 from

    2023年04月09日
    瀏覽(26)
  • 【postgresql 基礎(chǔ)入門(mén)】插入數(shù)據(jù)的多種方式 單條,多值,查詢(xún)結(jié)果,插入數(shù)據(jù)沖突處理,批量導(dǎo)入,多種方式讓數(shù)據(jù)插入更靈活

    ? 專(zhuān)欄內(nèi)容 : postgresql內(nèi)核源碼分析 手寫(xiě)數(shù)據(jù)庫(kù)toadb 并發(fā)編程 ? 開(kāi)源貢獻(xiàn) : toadb開(kāi)源庫(kù) 個(gè)人主頁(yè) :我的主頁(yè) 管理社區(qū) :開(kāi)源數(shù)據(jù)庫(kù) 座右銘:天行健,君子以自強(qiáng)不息;地勢(shì)坤,君子以厚德載物. 入門(mén)準(zhǔn)備 postgrersql基礎(chǔ)架構(gòu) 快速使用 初始化集群 數(shù)據(jù)庫(kù)服務(wù)管理 psql客戶(hù)

    2024年02月08日
    瀏覽(25)
  • Hive(19):DML之Insert插入數(shù)據(jù)

    Hive(19):DML之Insert插入數(shù)據(jù)

    1 背景:RDBMS中insert使用(insert+values) 在MySQL這樣的RDBMS中,通常是insert+values的方式來(lái)向表插入數(shù)據(jù),并且速度很快。這也是RDBMS中插入數(shù)據(jù)的核心方式。 假如說(shuō)對(duì)Hive的定位不清,把Hive當(dāng)成RDBMS來(lái)使用,也使用insert+values的方式插入數(shù)據(jù),會(huì)如何呢? 你會(huì)發(fā)現(xiàn)執(zhí)行過(guò)程非常非

    2024年02月13日
    瀏覽(48)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包