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');
  • 相关阅读:
    14、java中的equals()和toString()方法
    13、java中的多态
    1、editplus中将选取向前移动
    《Java4Android视频教程》学习笔记(一)
    android 构建数据库SQLite
    SWOT自我分析
    函数传递是如何让HTTP服务器工作的
    Node.js模块
    Viewcontrol的生命周期
    iOS开发-用宏定义求2个数中的最大值
  • 原文地址:https://www.cnblogs.com/654wangzai321/p/9970371.html
Copyright © 2011-2022 走看看