yangbin9317
V2EX  ›  问与答

新手问个关于 Hive 的问题

  •  
  •   yangbin9317 · Jan 19, 2018 · 1378 views
    This topic created in 3077 days ago, the information mentioned may be changed or developed.

    问一下计算 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 replies    2018-01-20 09:50:34 +08:00
    widewing
        1
    widewing  
       Jan 20, 2018 via Android
    因为 load 进去的数据压缩了吧
    yangbin9317
        2
    yangbin9317  
    OP
       Jan 20, 2018
    @widewing 两个表都是 rcfile 模式
    widewing
        3
    widewing  
       Jan 20, 2018 via Android   ❤️ 1
    rcfile 也是可选压不压的吧 insert 进去的默认不给压缩吧
    yangbin9317
        4
    yangbin9317  
    OP
       Jan 20, 2018
    @yangbin9317 谢了 我再看看文档
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1218 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:37 · PVG 01:37 · LAX 10:37 · JFK 13:37
    ♥ Do have faith in what you're doing.