若泽大数据 www.ruozedata.com

ruozedata


  • 主页

  • 归档

  • 分类

  • 标签

  • 发展历史

  • Suche

生产中Hive静态和动态分区表,该怎样抉择呢?

Veröffentlicht am 2018-05-06 | Bearbeitet am 2019-05-13 | in Hive | Aufrufe:
一.需求

按照不同部门作为分区,导数据到目标表

二.使用静态分区表来完成

71.创建静态分区表:

1
2
3
4
5
6
7
8
9
10
create table emp_static_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double)
PARTITIONED BY(deptno int)
row format delimited fields terminated by '\t';

2.插入数据:

1
2
hive>insert into table emp_static_partition partition(deptno=10)
select empno , ename , job , mgr , hiredate , sal , comm from emp where deptno=10;

3.查询数据:

1
hive>select * from emp_static_partition;

三.使用动态分区表来完成

1.创建动态分区表:

1
2
3
4
5
6
7
8
9
create table emp_dynamic_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double)
PARTITIONED BY(deptno int)row format delimited fields terminated by '\t';

【注意】动态分区表与静态分区表的创建,在语法上是没有任何区别的

2.插入数据:

1
2
hive>insert into table emp_dynamic_partition partition(deptno)     
select empno , ename , job , mgr , hiredate , sal , comm, deptno from emp;

【注意】分区的字段名称,写在最后,有几个就写几个 与静态分区相比,不需要where

需要设置属性的值:

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

假如不设置,报错如下:

3.查询数据:

1
hive>select * from emp_dynamic_partition;

分区列为deptno,实现了动态分区

四.总结

在生产上我们更倾向是选择动态分区,
无需手工指定数据导入的具体分区,
而是由select的字段(字段写在最后,有几个写几个)自行决定导出到哪一个分区中, 并自动创建相应的分区,使用上更加方便快捷 ,在生产工作中用的非常多多。

ruozedata WeChat Bezahlung
# hive
5min掌握,Hive的HiveServer2 和JDBC客户端&代码的生产使用
生产改造Spark1.6源代码,create table语法支持Oracle列表分区
  • Inhaltsverzeichnis
  • Übersicht

ruozedata

若泽数据优秀博客汇总
155 Artikel
31 Kategorien
74 schlagwörter
RSS
GitHub B站学习视频 腾讯课堂学习视频 官网
  1. 1. 一.需求
  2. 2. 二.使用静态分区表来完成
  3. 3. 三.使用动态分区表来完成
  4. 4. 四.总结
|
若泽数据
|