[英]How can I insert into a hive table with parquet fileformat and SNAPPY compression?
蜂巢2.1
我有以下表格定義:
CREATE EXTERNAL TABLE table_snappy (
a STRING,
b INT)
PARTITIONED BY (c STRING)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION '/'
TBLPROPERTIES ('parquet.compress'='SNAPPY');
現在,我想向其中插入數據:
INSERT INTO table_snappy PARTITION (c='something') VALUES ('xyz', 1);
但是,當我查看數據文件時,只看到沒有任何壓縮的普通鑲木地板文件。 在這種情況下,如何啟用快速壓縮?
目標:以拼花格式和SNAPPY壓縮配置單元表數據。
我也嘗試設置多個屬性:
SET parquet.compression=SNAPPY;
SET hive.exec.compress.output=true;
SET mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
SET mapred.output.compression.type=BLOCK;
SET mapreduce.output.fileoutputformat.compress=true;
SET mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
SET PARQUET_COMPRESSION_CODEC=snappy;
以及
TBLPROPERTIES ('parquet.compression'='SNAPPY');
但沒有任何幫助。 我對GZIP壓縮嘗試了同樣的方法,但似乎效果不佳。 我開始考慮是否有可能。 任何幫助表示贊賞。
檢查parquet-tools
是否被壓縮的最好方法之一是使用parquet-tools
。
create external table testparquet (id int, name string)
stored as parquet
location '/user/cloudera/testparquet/'
tblproperties('parquet.compression'='SNAPPY');
insert into testparquet values(1,'Parquet');
現在,當您查看文件時,它可能在任何地方都沒有.snappy
[cloudera@quickstart ~]$ hdfs dfs -ls /user/cloudera/testparquet
Found 1 items
-rwxr-xr-x 1 anonymous supergroup 323 2018-03-02 01:07 /user/cloudera/testparquet/000000_0
讓我們進一步檢查...
[cloudera@quickstart ~]$ hdfs dfs -get /user/cloudera/testparquet/*
[cloudera@quickstart ~]$ parquet-tools meta 000000_0
creator: parquet-mr version 1.5.0-cdh5.12.0 (build ${buildNumber})
file schema: hive_schema
-------------------------------------------------------------------------------------------------------------------------------------------------------------
id: OPTIONAL INT32 R:0 D:1
name: OPTIONAL BINARY O:UTF8 R:0 D:1
row group 1: RC:1 TS:99
-------------------------------------------------------------------------------------------------------------------------------------------------------------
id: INT32 SNAPPY DO:0 FPO:4 SZ:45/43/0.96 VC:1 ENC:PLAIN,RLE,BIT_PACKED
name: BINARY SNAPPY DO:0 FPO:49 SZ:58/56/0.97 VC:1 ENC:PLAIN,RLE,BIT_PACKED
[cloudera@quickstart ~]$
它是snappy
壓縮。
小心TBLPROPERTIES
。
應該是TBLPROPERTIES("parquet.compression"="SNAPPY")
TBLPROPERTIES("parquet.compress"="SNAPPY");
TBLPROPERTIES("parquet.compression"="SNAPPY")
而不是TBLPROPERTIES("parquet.compress"="SNAPPY");
我對這兩種情況都進行了測試,第一種情況工作得很好。
測試環境:Cloudera CDH 5.13
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.