1 Load
將文件導(dǎo)入Hive表中。
語法:
hive>load data [local] inpath 'filepath' [overwrite] into table tablename [partition (partcol1=val1, ...)];
關(guān)鍵字說明:
(1)local:表示從本地加載數(shù)據(jù)到Hive表;否則從HDFS加載數(shù)據(jù)到HIve表。
(2)overwrite:表示覆蓋表中已有數(shù)據(jù),否則表示追加。
(3)partition:表示上傳到指定分區(qū),若目標(biāo)是分區(qū)表則需要指定分區(qū)。
如:
-- 先創(chuàng)建一張表:
create table student(
id int,
name string
)
row format delimited fields terminated by '\t';
-- 加載本地文件到hive:
load data local inpath '/opt/module/hive/datas/student.txt' into table student;
-- 加載HDFS文件到hive:
--上傳文件到HDFDS:
hadoop fs -put /opt/module/hive/datas/student.txt /user/liaoyanxia
-- 加載HDFS上數(shù)據(jù),導(dǎo)入完成后去HDFS上查看文件是否存在:
load data inpath '/user/liaoyanxia/student.txt' into table student;
-- 加載數(shù)據(jù)覆蓋表中已有數(shù)據(jù):
-- 上傳文件到HDFS:
dfs -put /opt/module/datas/student.txt /user/liaoyanxia;
-- 加載數(shù)據(jù)覆蓋表中已有數(shù)據(jù):
load data inpath '/user/liaoyanxia/student.txt' overwrite into table student;
2 Insert
2.1 將查詢值插入表中
語法:
insert (into | overwrite) table tablename [partition (partcal1=val1, ...)] select_statement;
關(guān)鍵字說明:
(1)into:將結(jié)果追加到目標(biāo)表。
(2)overwrite:用結(jié)果覆蓋原有數(shù)據(jù)。
如:
-- 先創(chuàng)建一張表:
create table student1(
id int,
name string
)
row format delimited fields terminated by '\t';
--根據(jù)查詢結(jié)果插入數(shù)據(jù):
insert overwrite table student1 select id,name from student;
2.2 將給定的value插入表中
語法:
insert (into | overwrite) table tablename [partition (partcal1=[val1], ...)] values values_row [(index,'values_row'), ...];
如:
insert into table student1 values(1,'wangwu'),(2,'zhaoliu');
2.3 將查詢的結(jié)果寫入目標(biāo)路徑
語法:
insert overwrite [local] directory directory [row format roe_format] [stored ass file_format] select_statement;
如:
insert overwrite local directory '/opt/module/hive/datas/student' row format serde 'org.apache.hadoop.hive.serde2.JsonSerDe' select id,name from student;
3 Export & Import
??Export到此處語句將表的數(shù)據(jù)和元數(shù)據(jù)信息導(dǎo)出到HDFS路徑;Import將Expot導(dǎo)出的內(nèi)容導(dǎo)入Hive,恢復(fù)表中的數(shù)據(jù)和元數(shù)據(jù)。
??Export和Import用于兩個(gè)Hive實(shí)例間的數(shù)據(jù)遷移。
語法:文章來源:http://www.zghlxwxcb.cn/news/detail-487022.html
-- 導(dǎo)出:
export table tablename to 'export_target_path';
-- 導(dǎo)入:
import [external] table new_or_original_tablename from 'source_path' [location 'import_target_path'];
如:文章來源地址http://www.zghlxwxcb.cn/news/detail-487022.html
-- 導(dǎo)出:
export table default.student to '/user/hive/warehouse/export/student';
-- 導(dǎo)入:
import table student2 from 'user/hive/warehouse/export/student';
到了這里,關(guān)于【大數(shù)據(jù)之Hive】十、Hive之DML(Data Manipulation Language)數(shù)據(jù)操作語言的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!