一、hive 的數(shù)據(jù)導入
Linux本地文件以及數(shù)據(jù)格式:
在hive中創(chuàng)建表:
create table t_user(
id int
,name string
)
row format delimited
fields terminated by ","
lines terminated by '\n'
stored as textfile;
stored as常見的幾種格式
1. TextFile:使用TextFile格式存儲的表將數(shù)據(jù)以文本文件的形式進行存儲。這是最常用的默認存儲格式。
2. SequenceFile:使用SequenceFile格式存儲的表將數(shù)據(jù)以鍵-值對的形式存儲,適用于數(shù)據(jù)壓縮和高效讀取。
3. ORC(Optimized Row Columnar):ORC是Hive的一種高性能列式存儲格式,它以列的方式組織數(shù)據(jù),提供了更高的壓縮率和查詢性能。
4. Parquet:Parquet是一種列式存儲格式,也是Hive的一個常用選項。它支持高度壓縮和謂詞下推等優(yōu)化,適用于大規(guī)模數(shù)據(jù)分析。
5. Avro:Avro是一種跨語言的數(shù)據(jù)序列化系統(tǒng),Hive可以使用Avro格式存儲數(shù)據(jù)!
加載本地數(shù)據(jù)
load data local inpath '/home/hivedata/user.txt' into table t_user ;
-- 如果在into前面加了overwrite就是覆蓋之前的數(shù)據(jù)重新導入數(shù)據(jù)
加載hdfs上的數(shù)據(jù)
*注意:hdfs上需要有數(shù)據(jù)
從本地上傳文件到hdfs上
// 追加添加
load data inpath '/yan/hivedata/user.txt' into table t_user;
//覆蓋添加
load data inpath '/yan/hivedata/user.txt' into table t_user;
把別的表中的數(shù)據(jù)插入目標表
create table u1(
id int,
name string
);
insert into u1
(select id ,name from t_user);
# 查詢一次插入多個表 ,把from寫在前面
from t_user
insert into u2 select *
insert into u3 select id ,name;
克隆表
-- 把表結(jié)構(gòu)和數(shù)據(jù)一起復制
create table u4 as select * from t_user;
-- 只復制表結(jié)構(gòu),只需要使用like 表名即可,不用select
create table u5 like t_user;
本地數(shù)據(jù)導入和hdfs數(shù)據(jù)導入的區(qū)別:
本地:將數(shù)據(jù)copy到hdfs的表目錄下
hdfs:將數(shù)據(jù)剪切到hdfs的表目錄下
二、hive中數(shù)據(jù)的導出
導出到本地文件系統(tǒng)的目錄下
# 必須加overwrite
insert overwrite local directory '/home/hivedata/out/out1' select * from t_user;
# 在本地Linux系統(tǒng)中,最后一級的out1也是目錄
導出到hdfs的目錄下
-- 比本地少了local
insert overwrite directory '/yan/hivedata/out/out1' select * from t_user;
導出的數(shù)據(jù)文件中,默認字段不分割,其中的方括號是hdfs默認的分隔,之前的逗號分隔符沒有了
把hdfs上的數(shù)據(jù)導入到Linux本地:文章來源:http://www.zghlxwxcb.cn/news/detail-525318.html
hive -e 'select * from zoo.t_user' >> /home/hivedata/out/out2/02
# 02是我建的空文件
# 導出的文件中字段分隔符默認是\t
文章來源地址http://www.zghlxwxcb.cn/news/detail-525318.html
到了這里,關(guān)于hive數(shù)據(jù)的導入導出的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!