zoukankan      html  css  js  c++  java
  • Hive表中Partition的创建

    作用:

    在Hive Select查询中一般会扫描整个表内容,会消耗很多时间做没必要的工作。有时候只需要扫描表中关心的一部分数据,在对应的partition里面去查找就可以,减少查询时间。

    1. 创建表

    ]# cat create_rating_table_p.sql
    create external table rating_table_p
    (userId STRING,
    movieId STRING,
    rating STRING
    )
    partitioned by (dt STRING)
    row format delimited fields terminated by '	'
    lines terminated by '
    ';

    2. 导入数据

    LOAD DATA LOCAL INPATH '/usr/local/hive/test/hive_test_3/ml-latest-small/2009-12.data' OVERWRITE INTO TABLE rating_table_p partition(dt='2009-12');
    LOAD DATA LOCAL INPATH '/usr/local/hive/test/hive_test_3/ml-latest-small/2003-09.data' OVERWRITE INTO TABLE rating_table_p partition(dt='2003-09');

    3. HDFS上面查看,会在以表名为文件夹下面,有两个以时间命名的文件夹,对应日期数据存在对应文件夹下面

    ]$ hdfs dfs -ls /user/hive/warehouse/rating_table_p
    Found 2 items
    drwxrwxrwx   - hadoop supergroup          0 2018-06-25 15:27 /user/hive/warehouse/rating_table_p/dt=2003-10
    drwxrwxrwx   - hadoop supergroup          0 2018-06-25 15:26 /user/hive/warehouse/rating_table_p/dt=2009-12

    4. Hive表中查询

    hive> select userid, dt from rating_table_p where dt='2009-12' limit 10;
    OK
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12
    1    2009-12

    5. 删除分区

    alter table rating_table_p drop if exists partition(dt='2003-10');

    6.添加分区

    alter table rating_table_p add if not exists partition(dt='2003-10');
  • 相关阅读:
    秒杀系统核心高性能解决方案(待续)
    LeetCode字符串专题
    LeetCode哈希表专题
    LeetCode排序专题【算法】
    Login项目学习笔记【Android】
    LeetCode树专题(遍历,BST,Trie)(未完成)
    Android studio导入别人项目的艰难记录
    LeetCode树专题(递归)(未完成)
    LeetCode双指针专题【算法】(未完成)
    LeetCode数组与矩阵专题(未完成)
  • 原文地址:https://www.cnblogs.com/654wangzai321/p/9970371.html
Copyright © 2011-2022 走看看