Hive中DML資料操作

2021-09-29 18:30:25 字數 1134 閱讀 8742

1.資料匯入

1)向表中裝載資料(load) 語法

load data:表示載入資料

local:表示從本地載入資料到hive表;否則從hdfs載入資料到hive表

inpath:表示載入資料的路徑

into table:表示載入到哪張表

student:表示具體的表

overwrite:表示覆蓋表中已有資料,否則表示追加

partition:表示上傳到指定分割槽

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

基本插入資料

基本模式插入(根據單張表查詢結果)

多插入模式(根據多張表查詢結果)

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

create table if not existsstudent1 as select id,name fromstudent;

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

建立表,並指定在hdfs上的位置

上傳資料到hdfs上

dfs -put /opt/module/datas/student.txt  /user/hive/warehouse/student1;

5)import資料到指定hive表中

先用export匯出後,再將資料匯入

2.資料匯出

1)insert匯出

將查詢的結果匯出到本地

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

將查詢的結果匯出到hdfs上(沒有local)

2)hadoop命令匯出到本地

dfs -get/user/hive/warehouse/student/month=201709/000000_0  /opt/module/datas/export/student1.txt;

3)hive shell 命令匯出

bin/hive -e 'select * from default.student;'> /opt/module/datas/export/student1.txt;

4)export匯出到hdfs上

5)sqoop匯出

3.清除表中資料(truncate)

truncate tablestudent;

這裡truncate只能刪除管理表,不能刪除外部表中資料

Hive學習(六)DML資料操作

目錄 資料匯入 裝載資料 load 通過查詢語句向表中插入資料 insert 查詢語句中建立表並載入資料 as select 資料匯出 清除表中資料 語法 load data local inpath file path overwrite into table tb name partition ...

Hive學習筆記(五) DML 資料操作

5.2 資料匯出 5.3 清除表中資料 truncate 1 語法 hive load data local inpath opt module datas student.txt overwrite into table student partition partcol1 val1,1 load...

hive常見的DML操作

一 load資料 load data local inpath filepath overwrite into table tablename partition partcol1 val1,partcol2 val2 filepath 如果是local則是本地檔案,否則就是hdfs檔案 overw...