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

一.需求

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

目前创新互联建站已为数千家的企业提供了网站建设、域名、虚拟空间、绵阳服务器托管、企业网站设计、右江网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

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

1.创建静态分区表:

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.插入数据:

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

3.查询数据:

hive>select * from emp_static_partition;

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

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

1.创建动态分区表:

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.插入数据:

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

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

需要设置属性的值:

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

假如不设置,报错如下:
生产中Hive静态和动态分区表,该怎样抉择呢?
3.查询数据:

hive>select * from emp_dynamic_partition;
生产中Hive静态和动态分区表,该怎样抉择呢?
分区列为deptno,实现了动态分区

四.总结

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

本文标题:生产中Hive静态和动态分区表,该怎样抉择呢?
本文网址:https://www.cdcxhl.com/article22/gpiicc.html

成都网站建设公司_创新互联,为您提供企业建站商城网站网站设计公司网站导航Google网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设