zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    随笔2
    随笔
    关于updateElement接口
    随笔1
    本地访问正常,服务器访问乱码 记录
    Redis (error) NOAUTH Authentication required.解决方法
    tomcat启动很慢 停留在 At least one JAR was scanned for TLDs yet contained no TLDs.
    微信公众号消息回复
    微信公众号 报token验证失败
    idea中web.xml报错 Servlet should have a mapping
  • 原文地址:https://www.cnblogs.com/qi-yuan-008/p/11878426.html
Copyright © 2011-2022 走看看