hive中的分桶表
桶表也是一种用于优化查询而设计的表类型。
创建通表时,指定桶的个数、分桶的依据字段,hive就可以自动将数据分桶存储。
查询时只需要遍历一个桶里的数据,或者遍历部分桶,这样就提高了查询效率
------创建订单表
create table user_leads
(
leads_id string,
user_id string,
user_id string,
user_phone string,
user_name string,
create_time string
)
clustered by (user_id)
sorted by(leads_id)
into 10 buckets
row format delimited fields terminated by '\t'
stored as textfile;
clustered by是指根据 user_id 的值进行哈希后模除分桶个数,
根据得到的结果,确定这行数据分入哪个桶中,这样的分法,
可以确保相同 user_id 的数据放入同一个桶中。
而经销商的订单数据,大部分是根据user_id进行查询的。
这样大部分情况下是只需要查询一个桶中的数据就可以了。
sorted by 是指定桶中的数据以哪个字段进行排序,排序的好处是,在join操作时能获得很高的效率。
into 10 buckets是指定一共分10个桶
在HDFS上存储时,一个桶存入一个文件中,这样根据user_id进行查询时,可以快速确定数据存在于哪个桶中,而只遍历一个桶可以提供查询效率
加载到分桶表
------先创建普通临时表
create table user_leads_tmp
(
leads_id string,
user_id string,
user_id string,
user_phone string,
user_name string,
create_time string
)
row format delimited fields terminated by ','
stored as textfile;
------数据载入临时表
load data local inpath '/home/hadoop/lead.txt' overwrite into table user_leads_tmp;
------导入分桶表
set hive.enforce.bucketing = true; -- 为true就是设置为启用分桶。
insert overwrite table user_leads select * from user_leads_tmp;
drop table sospdm.tmp_yinfei_test;
create table sospdm.tmp_yinfei_test
(
id string,cust_num string
)partitioned by (statis_date string) clustered by (id) sorted by (id) into 5 buckets
row format delimited fields terminated by ','
;
1,cust_num_1
2,cust_num_2
3,cust_num_3
4,cust_num_4
5,cust_num_5
6,cust_num_6
7,cust_num_7
8,cust_num_8
9,cust_num_9
drop table sospdm.tmp_yinfei_test_tmp;
create table sospdm.tmp_yinfei_test_tmp
(
id string,cust_num string
)partitioned by (statis_date string)
row format delimited fields terminated by ','
;
load data local inpath '/home/sospdm/yf/test.txt' overwrite into table tmp_yinfei_test_tmp partition (statis_date='20190408');
set hive.enforce.bucketing = true;
insert overwrite table tmp_yinfei_test partition(statis_date='20190408') select id,cust_num from tmp_yinfei_test_tmp;
hive中的分桶表的更多相关文章
- Hive学习笔记——Hive中的分桶
对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...
- Hive 学习之路(五)—— Hive 分区表和分桶表
一.分区表 1.1 概念 Hive中的表对应为HDFS上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为HDFS上表目录的子目录,数据按照分区存储在子目录中.如 ...
- Hive 系列(五)—— Hive 分区表和分桶表
一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...
- 入门大数据---Hive分区表和分桶表
一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...
- hive 分区表和分桶表
1.创建分区表 hive> create table weather_list(year int,data int) partitioned by (createtime string,area ...
- 第2节 hive基本操作:11、hive当中的分桶表以及修改表删除表数据加载数据导出等
分桶表 将数据按照指定的字段进行分成多个桶中去,说白了就是将数据按照字段进行划分,可以将数据按照字段划分到多个文件当中去 开启hive的桶表功能 set hive.enforce.bucketing= ...
- Hive为什么要分桶
对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...
- 一起学Hive——创建内部表、外部表、分区表和分桶表及导入数据
Hive本身并不存储数据,而是将数据存储在Hadoop的HDFS中,表名对应HDFS中的目录/文件.根据数据的不同存储方式,将Hive表分为外部表.内部表.分区表和分桶表四种数据模型.每种数据模型各有 ...
- Hive 教程(四)-分区表与分桶表
在 hive 中分区表是很常用的,分桶表可能没那么常用,本文主讲分区表. 概念 分区表 在 hive 中,表是可以分区的,hive 表的每个区其实是对应 hdfs 上的一个文件夹: 可以通过多层文件夹 ...
随机推荐
- socket-WebSocket HttpListener TcpListener 服务端客户端的具体使用案例
/// <summary>/// 启动服务监听的ip和端口的主线程/// </summary>/// <param name="tunnelPort" ...
- Windows服务启动进程----Cjwdev.WindowsApi.dll
windows服务下无法启动外部程序 做一个windows服务监听服务,涉及到windows服务启动外部程序的一个过程,但是调试测试发现,无法简单的用process.start()这种方法, 原因是在 ...
- HttpListener通讯成功案例
1.创建WindowsService,如下代码 using System;using System.Net;using System.Net.Sockets;using System.ServiceP ...
- SpringMvc + Jsp+ 富文本 kindeditor 进行 图片ftp上传nginx服务器 实现
一:html 原生态的附件上传 二:实现逻辑分析: 1.1.1 需求分析 Common.js 1.绑定事件 2.初始化参数 3.上传图片的url: /pic/upload 4.上图片参数名称: upl ...
- ( linker command failed with exit code 1) 错误解决方案 项目使用的是pod
targets -> build settings -> architectures -> build active architecture only -> debug 改成 ...
- linux 使用的部分命令
搜索所有运行着的线程 ps -A | grep apt-get 你会得到类似下面的输出: root ? Ss : : /bin/sh /usr/lib/apt/apt.systemd.daily _a ...
- java常用实用类
1.String类概念 java程序中默认导入java.lang包的,像java.lang.String等String类属于final类,用户不能扩展String类,String 类没有子类.Stri ...
- python网络爬虫笔记(九)
4.1.1 urllib2 和urllib是两个不一样的模块 urllib2最简单的就是使用urllie2.urlopen函数使用如下 urllib2.urlopen(url[,data[,timeo ...
- Tomcat配置域名/IP访问及其中遇到的问题注意事项
1.先在tomcat下的conf下找到server.xml文件,用记事本打开后,首先对端口号进行修改,以前一直以为8080是默认的端口号,其实默认的端口号是80 <Connector port= ...
- B: Ocean的游戏(前缀和)
B: Ocean的游戏 Time Limit: 1 s Memory Limit: 128 MB Submit My Status Problem Description 给定一个字符串s, ...