zoukankan      html  css  js  c++  java
  • HADOOP-HIVE分区,桶,倾斜概念 + 删除表

    HIVE分区,桶,倾斜概念

    ref:https://edu.hellobi.com/course/93/play/lesson/2037

     静态分区:

    按日期来分区

    动态分区:

    商品二级类目分区(图书、数码等),是不确定的

    set hive.exec.dynamic.partition 查看设置true/false

    true: 可动态分区

    hive> set hive.exec.dynamic.partition;
    hive.exec.dynamic.partition=true

    set hive.exec.dynamic.partition.mode 默认情况下是strict,我们为了灵活最好设置成nonstrict

    hive> set hive.exec.dynamic.partition.mode=nonstrict;
    hive> set hive.exec.dynamic.partition.mode;
    hive.exec.dynamic.partition.mode=nonstrict

    分区表

    桶表

     Skewed Tables 倾斜表

     100万用户名,50万是null,那么就是有倾斜的。

    查询的时候要过滤,对倾斜数据做过滤。

    临时表:

     创建2个表,一个临时表test1,一个非临时表test1;

    hive> create table test1(id int);
    OK
    Time taken: 0.2 seconds

    hive> create temporary table test1(name string);
    OK
    Time taken: 0.109 seconds
    hive> desc test1;
    OK
    name string
    Time taken: 0.019 seconds, Fetched: 1 row(s)

    下面这个例子中看到,只是把临时表test1删除了,但是非临时表test1仍然存在。

    hive> drop table test1;
    OK
    Time taken: 0.128 seconds
    hive> show tables;
    OK
    test
    test1
    Time taken: 0.09 seconds, Fetched: 2 row(s)

    我们也可以使用desc formatted test1;来查看详细信息;

    对于 非临时表 来说,存放位置location和tmp表示不同的。
    Location: hdfs://bigdata:9000/user/hive/warehouse/test1 Table Type: MANAGED_TABLE

    临时表则在/tmp/文件夹下。

    临时表:
    Location: hdfs://bigdata:9000/tmp/hive/root/5c538ba1-fdb8-4cf6-a54c-4dcdf8d66c0a/_tmp_space.db/8a90cd30-6ca8-46f2-98cf-822783a0aa8d Table Type: MANAGED_TABLE

    删除表

      PURGE - 无法恢复

    刚才删除临时表的例子:

    hive> dfs -ls /user/root/.Trash/Current/;
    Found 1 items
    drwx------   - root staff          0 2020-05-17 17:07 /user/root/.Trash/Current/tmp

    hive> dfs -ls /user/root/.Trash/Current/tmp/hive/root;
    Found 1 items
    drwx------ - root staff 0 2020-05-17 17:07 /user/root/.Trash/Current/tmp/hive/root/5c538ba1-fdb8-4cf6-a54c-4dcdf8d66c0a

    再次删除非临时表test1:

    hive> drop table test1;
    OK
    Time taken: 0.963 seconds
    hive> dfs -ls /user/root/.Trash/Current/;
    Found 2 items
    drwx------   - root staff          0 2020-05-17 17:07 /user/root/.Trash/Current/tmp
    drwx------   - root staff          0 2020-05-17 17:23 /user/root/.Trash/Current/user
    hive> dfs -ls /user/root/.Trash/Current/user/hive/warehouse;
    Found 1 items
    drwxr-xr-x   - root staff          0 2020-05-17 17:03 /user/root/.Trash/Current/user/hive/warehouse/test1
    hive> 

     例子:我们新建id.txt最后一行为空,复制到test文件里。

    [root@bigdata Documents]# cat id.txt 
    1
    2
    3
    4
    5
    6
    7
    8
    
    [root@bigdata Documents]# hdfs dfs  -put id.txt /user/hive/warehouse/test

    hive> desc test;
    OK
    id int

    hive> select * from test;
    OK
    1
    2
    3
    4
    5
    6
    7
    8
    NULL

    发现最后一行空值,变为了NULL.

     

     

     对external表 进行删除,发现id.txt仍然存在。

    hive> drop table test;
    OK
    Time taken: 0.449 seconds
    hive> select * from test;
    FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'test'

    清空表

     *被清空的表必须是内表,否则抛出异常。

    hive> create external table test_ext(id int);
    OK
    Time taken: 0.369 seconds
    hive> truncate table test_ext;
    FAILED: SemanticException [Error 10146]: Cannot truncate non-managed table test_ext.

    ALTER REF:https://edu.hellobi.com/course/93/play/lesson/2038

     修改表

     

     

     

     

     

    如需转载请标明本文博客园链接地址。

  • 相关阅读:
    jQuery Colorpicker Spectrum api 中文 文档 属性 事件 方法
    java使用dbutils工具类实现小程序 管家婆记账软件
    java实现服务端开启多线程处理客户端的上传图片请求
    java 基于tcp客户端服务端发送接收数据
    java基于udp实现键盘录入聊天
    java实现udp发送端和接收端
    java通过读取本地文件获取反射方法参数,执行对象方法
    java通过反射获取私有的构造方法,及反射擦除泛型数据类型约束
    Java反射获取类对象的三种方式
    java使用DBCP连接池创建工具类
  • 原文地址:https://www.cnblogs.com/watermarks/p/12905916.html
Copyright © 2011-2022 走看看