HADOOP-HIVE分区,桶,倾斜概念 + 删除表 - 学习笔记(6)

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

 修改表

 

 

 

 

 

 

 

 

 

 

 

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

posted @ 2020-05-17 17:17  po-A  阅读(373)  评论(0编辑  收藏  举报

Tushare大数据开放社区-免费提供各类金融数据和区块链数据 , 助力智能投资与创新型投资。

Python, Matlab, R, Web数据抽取学习交流。