如何選擇南京網(wǎng)站建設(shè)橙子建站
目錄
1.hive命令和參數(shù)配置
2.hive數(shù)據(jù)壓縮
3.hive數(shù)據(jù)存儲(chǔ)
0.原文件大小? 18.1MB
1.textfile行存儲(chǔ)格式, 壓縮后size:18MB
2.行存儲(chǔ)格式:squencefile ,壓縮后大小8.89MB?
3. 列存儲(chǔ)格式 orc - ZILIB ,壓縮后大小2.78MB
?4.列存儲(chǔ)格式? orc-snappy? ,壓縮后大小3.75MB
5.列存儲(chǔ)格式之parquets ,壓縮后大小13.09MB?
?4.在linux中查看文件大小的命令
1.hive命令和參數(shù)配置
hive參數(shù)設(shè)置范圍 : 配置文件參數(shù) > ? 命令行參數(shù) ?> ? set參數(shù)聲明
hive參數(shù)設(shè)置優(yōu)先級(jí): set參數(shù)聲明 ?> ? 命令行參數(shù) ? > ?配置文件參數(shù)
注意: 一般執(zhí)行SQL需要指定的參數(shù), 都是通過 set參數(shù)聲明 方式進(jìn)行配置,因?yàn)樗鼘儆诋?dāng)前會(huì)話的臨時(shí)設(shè)置,斷開后就失效了
?2.hive數(shù)據(jù)壓縮
==Hive底層是運(yùn)行MapReduce,所以Hive支持什么壓縮格式本質(zhì)上取決于MapReduce。==
在后續(xù)可能會(huì)使用GZ(GZIP), 保證壓縮后的數(shù)據(jù)更小, 同時(shí)壓縮和解壓的速度比較OK的,
但是大部分的選擇主要會(huì)選擇另一種壓縮方案, snappy, 此種方案可以保證在合理的壓縮比下, 擁有更高的解壓縮的速度
snappy | A fast compressor/decompressor On a single core of a Core i7 processor in 64-bit mode, Snappy compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more.
?
開啟壓縮
create database hive6;
use hive6;
-- 開啟壓縮(map階段或者reduce階段)
--開啟hive支持中間結(jié)果的壓縮方案
set hive.exec.compress.intermediate; -- 查看默認(rèn)
set hive.exec.compress.intermediate=true ;
--開啟hive支持最終結(jié)果壓縮
set hive.exec.compress.output; -- 查看默認(rèn)
set hive.exec.compress.output=true;--開啟MR的map端壓縮操作
set mapreduce.map.output.compress; -- 查看默認(rèn)
set mapreduce.map.output.compress=true;
--設(shè)置mapper端壓縮的方案
set mapreduce.map.output.compress.codec; -- 查看默認(rèn)
set mapreduce.map.output.compress.codec= org.apache.hadoop.io.compress.SnappyCodec;-- 開啟MR的reduce端的壓縮方案
set mapreduce.output.fileoutputformat.compress; -- 查看默認(rèn)
set mapreduce.output.fileoutputformat.compress=true;
-- 設(shè)置reduce端壓縮的方案
set mapreduce.output.fileoutputformat.compress.codec; -- 查看默認(rèn)
set mapreduce.output.fileoutputformat.compress.codec = org.apache.hadoop.io.compress.SnappyCodec;
--設(shè)置reduce的壓縮類型
set mapreduce.output.fileoutputformat.compress.type; -- 查看默認(rèn)
set mapreduce.output.fileoutputformat.compress.type=BLOCK;
3.hive數(shù)據(jù)存儲(chǔ)
行存儲(chǔ)的特點(diǎn):?查詢滿足條件的一整行數(shù)據(jù)的時(shí)候,列存儲(chǔ)則需要去每個(gè)聚集的字段找到對(duì)應(yīng)的每個(gè)列的值,行存儲(chǔ)只需要找到其中一個(gè)值,其余的值都在相鄰地方,所以此時(shí)行存儲(chǔ)查詢的速度更快。
列存儲(chǔ)的特點(diǎn):?因?yàn)槊總€(gè)字段的數(shù)據(jù)聚集存儲(chǔ),在查詢只需要少數(shù)幾個(gè)字段的時(shí)候,能大大減少讀取的數(shù)據(jù)量;每個(gè)字段的數(shù)據(jù)類型一定是相同的,列式存儲(chǔ)可以針對(duì)性的設(shè)計(jì)更好的設(shè)計(jì)壓縮算法。
行存儲(chǔ): textfile和squencefile
?? ?優(yōu)點(diǎn): 每行數(shù)據(jù)連續(xù)存儲(chǔ) ? ? ? ? ? ? ?select * from 表名; 查詢行,全表速度相對(duì)較快
?? ?缺點(diǎn): 每列類型不一致,空間利用率不高 ? select 列名 from 表名; 查詢速度相對(duì)較慢
列存儲(chǔ): orc(zlib,snappy)和parquet
?? ?優(yōu)點(diǎn): 每列數(shù)據(jù)連續(xù)存儲(chǔ) ? ? ? ? select 列名 from 表名; ?查詢列的速度相對(duì)較快,因?yàn)轭愋投际且粯?所以利于壓縮和存儲(chǔ),空間利用率高
?? ?缺點(diǎn): 因?yàn)槊啃袛?shù)據(jù)不是連續(xù)存儲(chǔ) ?select * from 表名;查詢速度相對(duì)較慢
?? ?
注意: ORC文件格式的數(shù)據(jù), 默認(rèn)內(nèi)置一種壓縮算法:zlib , 在實(shí)際生產(chǎn)中一般會(huì)將ORC壓縮算法替換為 snappy使用,格式為: STORED AS orc tblproperties ("orc.compress"="SNAPPY")?
0.原文件大小? 18.1MB
?
1.textfile行存儲(chǔ)格式, 壓縮后size:18MB
--存儲(chǔ)壓縮比
-- 存儲(chǔ)格式應(yīng)用對(duì)比
-- 演示textfile行存儲(chǔ)格式: 18.1 m
create table log_text (track_time string,url string,session_id string,referer string,ip string,end_user_id string,city_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE ; -- TEXTFILE當(dāng)前默認(rèn)的,可以省略-- 查詢數(shù)據(jù)
select * from log_text;
壓縮后size:18MB?,原封不動(dòng)
?2.行存儲(chǔ)格式:squencefile ,壓縮后大小8.89MB
?壓縮后大小8.89MB
create table log_text_sequen (track_time string,url string,session_id string,referer string,ip string,end_user_id string,city_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS sequencefile ;
-- 加載數(shù)據(jù)(先上傳數(shù)據(jù)文件到根目錄)
insert into table log_text_sequen select * from log_text;
-- 查詢數(shù)據(jù)
select * from log_text_sequen ;
3. 列存儲(chǔ)格式 orc - ZILIB ,壓縮后大小2.78MB
/*ORC文件格式的數(shù)據(jù), 默認(rèn)內(nèi)置一種壓縮算法:ZLIB , 在實(shí)際生產(chǎn)中一般會(huì)將ORC壓縮算法替換為 snappy
格式為: STORED AS orc tblproperties ("orc.compress"="SNAPPY") */
create table log_orc_zlib(
track_time string,
url string,
session_id string,
referer string,
ip string,
end_user_id string,
city_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS orc ;-- 默認(rèn)內(nèi)置一種壓縮算法:ZLIB-- 加載數(shù)據(jù)(先上傳數(shù)據(jù)文件到根目錄,可以)
insert into table log_orc_zlib select * from log_text; --24s 726ms size 2.78MB
--回到HDFS中查看,原來18MB的文件,在算法壓縮后,變成2.78MB,壓縮后在hdfs中查看是亂碼
-- 查詢數(shù)據(jù)
select * from log_orc_zlib;
壓縮后大小2.78MB?
?4.列存儲(chǔ)格式? orc-snappy? ,壓縮后大小3.75MB
/*ORC文件格式的數(shù)據(jù), 默認(rèn)內(nèi)置一種壓縮算法:ZLIB , 在實(shí)際生產(chǎn)中一般會(huì)將ORC壓縮算法替換為 snappy
格式為: STORED AS orc tblproperties ("orc.compress"="SNAPPY") */
-- [重點(diǎn)orc配合snappy]
-- 演示orc列存儲(chǔ)(指定snappy): 3.75 m
create table log_orc_snappy(track_time string,url string,session_id string,referer string,ip string,end_user_id string,city_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS orc tblproperties ("orc.compress"="SNAPPY"); -- 配合SNAPPY壓縮-- 加載數(shù)據(jù)(先上傳數(shù)據(jù)文件到根目錄)
insert into table log_orc_snappy select * from log_text;
-- 查詢數(shù)據(jù)
select * from log_orc_snappy;
5.列存儲(chǔ)格式之parquets ,壓縮后大小13.09MB?
-- 演示parquet壓縮存儲(chǔ):13.09 m
create table log_parquet(
track_time string,
url string,
session_id string,
referer string,
ip string,
end_user_id string,
city_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS PARQUET ;-- 加載數(shù)據(jù)(先上傳數(shù)據(jù)文件到根目錄)
insert into table log_parquet select * from log_text;
-- 查詢數(shù)據(jù)
select * from log_parquet;
壓縮后大小13.9MB?
?4.在linux中查看文件大小的命令
查看文件大小的hdfs dfs -du -h '路徑';
[root@node1 ~]# hdfs dfs -du -h '/user/hive/warehouse/hive6.db/log_text/log.data' ;
18.1 M ?54.4 M ?/user/hive/warehouse/hive6.db/log_text/log.data
?
[root@node1 ~]# hdfs dfs -du -h '/user/hive/warehouse/hive6.db/log_orc_zlib/000000_0';
2.8 M ?8.3 M ?/user/hive/warehouse/hive6.db/log_orc_zlib/000000_0
?