V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yangbin9317
V2EX  ›  问与答

新手问个关于 Hive 的问题

  •  
  •   yangbin9317 · 2018-01-19 23:33:37 +08:00 · 948 次点击
    这是一个创建于 2260 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问一下计算 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

    想问一下问题出在哪里

    4 条回复    2018-01-20 09:50:34 +08:00
    widewing
        1
    widewing  
       2018-01-20 00:48:03 +08:00 via Android
    因为 load 进去的数据压缩了吧
    yangbin9317
        2
    yangbin9317  
    OP
       2018-01-20 09:03:25 +08:00
    @widewing 两个表都是 rcfile 模式
    widewing
        3
    widewing  
       2018-01-20 09:31:52 +08:00 via Android   ❤️ 1
    rcfile 也是可选压不压的吧 insert 进去的默认不给压缩吧
    yangbin9317
        4
    yangbin9317  
    OP
       2018-01-20 09:50:34 +08:00
    @yangbin9317 谢了 我再看看文档
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5372 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 08:36 · PVG 16:36 · LAX 01:36 · JFK 04:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.