hive表,怎么给表进行压缩
时间: 2023-07-14 21:14:14 浏览: 61
Hive支持多种压缩格式,包括LZO、Snappy、Gzip、Bzip2等。在创建表时,可以通过指定表的属性来设置压缩格式。
例如,创建一个使用Snappy格式进行压缩的表可以如下所示:
```
CREATE TABLE mytable (
col1 string,
col2 int,
col3 double
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION '/user/hive/warehouse/mytable'
TBLPROPERTIES ('mapred.output.compress'='true', 'mapred.output.compression.type'='BLOCK', 'mapred.output.compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
```
其中,TBLPROPERTIES中的三个属性分别表示开启压缩、设置压缩类型为BLOCK(按块压缩)、使用Snappy格式进行压缩。
也可以直接在已经存在的表中添加压缩属性,例如:
```
ALTER TABLE mytable SET TBLPROPERTIES ('mapred.output.compress'='true', 'mapred.output.compression.type'='BLOCK', 'mapred.output.compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
```
这样就可以将已经存在的表进行压缩。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)