• hive之建立分区表和分区


    1. 建立分区表 create table

    单分区表:其中分区字段是partdate,注意分区字段不能和表字段一样,否则会报重复的错

    create table test_t2(words string,frequency string) partitioned by (partdate string) row format delimited fields terminated by '1';

    多分区表:id在前,address在后,注意多个分区字段时,是有先后顺序的

    create table test_table_hive(name string,school string) partitioned by (id int,address string) row format delimited fields terminated by '1';

    2. 新建分区:建立分区表之后,此时没有数据,也没有分区,需要建立分区

    查看分区命令show partitions:

    show partitions test_table_hive;

    建立单分区 alter table:

    alter table test_t2 add partition(partdate='20191030');
    alter table test_t2 add partition(partdate=20191030); #也可,可能是内部转换了格式
    alter table test_t2 add IF NOT EXISTS partition (partdate='20191031'); #避免重复建立分区出错
    
    alter table test_t2 add IF NOT EXISTS partition (partdate='20191031') partition (partdate='20191101'); #一次建立多个分区

    建立多字段分区:

    alter table test_table_hive add partition(id=1,adress='chengdu');
    #显示分区
    show partitions test_table_hive;

     一次建立多个多字段分区,注意多字段时,必须填满这多个分区字段,例如此时就不能只用 id 来分区:

    alter table test_table_hive add partition(id=2,adress='beijing') partition(id=3,adress='shanghai');
    show partitions test_table_hive;

     

    3. 删除分区 drop

    alter table test_t2 drop partition(partdate='20191030');

    附加:显示当前数据库

    select current_database();

    参考:

    https://blog.csdn.net/qq_36743482/article/details/78418343

  • 相关阅读:
    P3133 [USACO16JAN]无线电联系Radio Contact
    P2196 挖地雷
    P2434 [SDOI2005]区间
    P2820 局域网
    P2904 [USACO08MAR]跨河River Crossing
    P1586 四方定理
    P2983 [USACO10FEB]购买巧克力Chocolate Buying
    P2049 魔术棋子
    kali-linux破解密码运行脚本并隐藏进程
    kali安装使用
  • 原文地址:https://www.cnblogs.com/qi-yuan-008/p/11878426.html
Copyright © 2020-2023  润新知