新手问个关于 Hive 的问题

2018-01-19 23:33:37 +08:00
 yangbin9317

问一下计算 Hive 通过 where 筛选出来的数据所占的磁盘空间。

有如下表 table

CREATE EXTERNAL TABLE `table`(
  `some_data`,
  `type` string
PARTITIONED BY (
  `dt` string,
  `hour` string)
STORED AS INPUTFORMAT
  'org.apache.hadoop.hive.ql.io.RCFileInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.RCFileOutputFormat'
LOCATION
  'hdfs://table'

假设希望计算 type=1 的数据大小,我是这样做的

新建表

CREATE EXTERNAL TABLE `tmp_table`(
  `some_data` string,
  `typeDontQuery` string
PARTITIONED BY (
  `dt` string,
  `type` string)
STORED AS INPUTFORMAT
  'org.apache.hadoop.hive.ql.io.RCFileInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.RCFileOutputFormat'
LOCATION
  'hdfs://tmp_table'

把 table 中的数据按 type 分区插入到新建的tmp_table中,SQL 如下

INSERT OVERWRITE TABLE tmp_table
PARTITION (dt=20180101, type=1)
SELECT some_data, type AS typeDontQuery
WHERE dt=20180101 AND type=1
FROM table;

结果发现 tmp_tabletype=1分区比table中这一天所有type所占的空间还要大很多

我是这样查分区大小的hadoop fs -du -h hdfs://table/dt=20180101hadoop fs -du -h hdfs://tmp_table/dt=20180101/type=1

想问一下问题出在哪里

963 次点击
所在节点    问与答
4 条回复
widewing
2018-01-20 00:48:03 +08:00
因为 load 进去的数据压缩了吧
yangbin9317
2018-01-20 09:03:25 +08:00
@widewing 两个表都是 rcfile 模式
widewing
2018-01-20 09:31:52 +08:00
rcfile 也是可选压不压的吧 insert 进去的默认不给压缩吧
yangbin9317
2018-01-20 09:50:34 +08:00
@yangbin9317 谢了 我再看看文档

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/424387

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX