前言
介紹Hive數(shù)據(jù)加載方式(insert、load)
方式一:load data
基礎(chǔ)語法:load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student[partition ]
參數(shù)說明:
1 load data: 表示加載數(shù)據(jù)
2 local: 表示從本地加載數(shù)據(jù)到 hive 表;否則從 HDFS 加載數(shù)據(jù)到 hive 表
3 inpath: 表示加載數(shù)據(jù)的路徑
相對路徑,例如:project/data1
絕對路徑,例如:/user/hive/project/data1
包含模式的完整 URI,如:hdfs://namenode:9000/user/hive/project/data1
4 overwrite: 表示覆蓋表中已有數(shù)據(jù),否則表示追加。目標(biāo)表(或者分區(qū))中的內(nèi)容會被刪除,然后再將filepath指向的文件/目錄中的內(nèi)容添加到表/分區(qū)中
5 into table: 表示加載到哪張表
6 student: 表示具體的表
7 partition: 表示上傳到指定分區(qū)
-- 加載本地文件
load data local inpath '/home/hadoop/load1.txt' into table tb_load1;
-- 加載HDFS文件
load data inpath '/hive/test/load2.txt' into table tb_load1;
-- 加載分區(qū)數(shù)據(jù)
load data inpath '/hive/test/load_part_male.txt' into table tb_load2
partition (sex='male');
--使用overwrite:會覆蓋之前的數(shù)據(jù)
load data local inpath '/home/hadoop/load3.txt' overwrite into table tb_load1;
方式二: insert 插入
1.普通表
-- 覆蓋
insert overwrite table tb_insert1 select id,name from tb_select1;
-- 追加
insert into table tb_insert1 select id,name from tb_select1;
2.分區(qū)表
-- 分區(qū)插入
insert overwrite table tb_insert_part partition(sex = 'male')
select id,name from tb_select1 where sex='male';
-- 動態(tài)分區(qū)插入(需先設(shè)置非嚴(yán)格模式)
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table tb_dy_part partition(sex)
select id,name,sex from tb_select1;
方式三:as select
注意
: 只能以as方式加載數(shù)據(jù), 如其他有分區(qū)字段, 分區(qū)字段只以字段形式保留
create table tb_create_mode as
select id,name from tb_select1;
數(shù)據(jù)導(dǎo)出
(1)導(dǎo)出到本地
insert overwrite local directory '/home/hadoop/'
select id,name from tb_select1;
例子 :
INSERT overwrite directory "/user/yuanpengfei/ypf/lifeng/vehPOI" ROW format delimited fields terminated BY ","
select substr( md5(concat('mb',field_2,'xx')),9,6), field_3, field_4, field_5, field_6, field_7
from default.longchuan_od_temp
總結(jié)
如果此篇文章有幫助到您, 希望打大佬們能
關(guān)注
、點贊
、收藏
、評論
支持一波,非常感謝大家!
如果有不對的地方請指正!!!文章來源:http://www.zghlxwxcb.cn/news/detail-768961.html
參考1
參考2文章來源地址http://www.zghlxwxcb.cn/news/detail-768961.html
到了這里,關(guān)于Hive數(shù)據(jù)加載方式(load、insert;普通表、分區(qū)表)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!