HIVE中的分区表是什么,我们先看操作,然后再来体会。

创建一个分区表,分区的单位时dt和国家名
hive> create table logs(ts bigint,line string)
> partitioned by (dt String,country string);

接下来我们创建要给分区

hive> load data local inpath '/root/hive/partitions/file1' into table logs
> partition (dt='2001-01-01',country='GB');

上面语句的效果是在hdfs系统上建立了一个层级目录

  -logs

    -dt=2001-01-01

    -country=GB

我们继续执行下面语句,先看一下什么效果
hive> load data local inpath '/root/hive/partitions/file2' into table logs
> partition (dt='2001-01-01',country='GB');
Loading data to table default.logs partition (dt=2001-01-01, country=GB)
OK
Time taken: 1.379 seconds
hive> load data local inpath '/root/hive/partitions/file3' into table logs
> partition (dt='2001-01-01',country='US');
Loading data to table default.logs partition (dt=2001-01-01, country=US)
OK
Time taken: 1.307 seconds
hive> load data local inpath '/root/hive/partitions/file4' into table logs
> partition (dt='2001-01-02',country='GB');
Loading data to table default.logs partition (dt=2001-01-02, country=GB)
OK
Time taken: 1.253 seconds
hive> load data local inpath '/root/hive/partitions/file5' into table logs
> partition (dt='2001-01-02',country='US');
Loading data to table default.logs partition (dt=2001-01-02, country=US)
OK
Time taken: 1.07 seconds
hive> load data local inpath '/root/hive/partitions/file6' into table logs
> partition (dt='2001-01-02',country='US');
Loading data to table default.logs partition (dt=2001-01-02, country=US)
OK
Time taken: 1.227 seconds

我们到HDFS上查看,发现建立了下面层级目录

/user/hive/warehouse/logs
├── dt=2001-01-01/
│ ├── country=GB/
│ │ ├── file1
│ │ └── file2
│ └── country=US/
│ └── file3
└── dt=2001-01-02/
├── country=GB/
│ └── file4
└── country=US/
├── file5
└── file6

是加上所有files的内容基本上一样,蓝色的^A是系统默认分隔符。八进制是‘\001’.随后参考我的另一个文章。比较详细解释了分隔符。

总结:分区表的意思,其实想明白了就很简单。就是在系统上建立文件夹,把分类数据放在不同文件夹下面,加快查询速度。

关键点1:partitioned by (dt String,country string); 创建表格时,指明了这是一个分区表。将建立双层目录,第一次目录的名字和第二层目录名字规则

PARTITIONED BY子句中定义列,是表中正式的列,成为分区列。但是数据文件中并没有这些值,仅代表目录。

关键点2: partition (dt='2001-01-01',country='GB'); 上传数据时,把数据分别上传到不同分区中。也就是分别放在不同的子目录下。

理解分区就是文件夹分而治之,查询的时候可以当作列名来显示查询的范围。

查看分区结构
hive> show partitions logs;
OK
dt=2001-01-01/country=GB
dt=2001-01-01/country=US
dt=2001-01-02/country=GB
dt=2001-01-02/country=US

 

条件限定了country='GB'目录所以只有file1,2,4的内容输出
hive> select ts,dt,line
> from logs
> where country='GB';
OK
1 2001-01-01 Log line 1
2 2001-01-01 Log line 2
4 2001-01-02 Log line 4 现在只查看dt=2001-01-02目录下country=US的文件夹下的数据。

hive> select ts,dt,line
> from logs
> where dt='2001-01-02'
> and country='US';
OK
5 2001-01-02 Log line 5
6 2001-01-02 Log line 6

 

HIVE-分区表详解以及实例的更多相关文章

  1. XML参考 :XmlReader 详解、实例

    XML参考 :XmlReader 详解.实例-- 详解 转:http://www.cnblogs.com/Dlonghow/archive/2008/07/28/1252191.html XML参考 ...

  2. Protocol Buffer技术详解(Java实例)

    Protocol Buffer技术详解(Java实例) 该篇Blog和上一篇(C++实例)基本相同,只是面向于我们团队中的Java工程师,毕竟我们项目的前端部分是基于Android开发的,而且我们研发 ...

  3. Protocol Buffer技术详解(C++实例)

    Protocol Buffer技术详解(C++实例) 这篇Blog仍然是以Google的官方文档为主线,代码实例则完全取自于我们正在开发的一个Demo项目,通过前一段时间的尝试,感觉这种结合的方式比较 ...

  4. Java学习-007-Log4J 日志记录配置文件详解及实例源代码

    此文主要讲述在初学 Java 时,常用的 Log4J 日志记录配置文件详解及实例源代码整理.希望能对初学 Java 编程的亲们有所帮助.若有不足之处,敬请大神指正,不胜感激!源代码测试通过日期为:20 ...

  5. groupadd命令详解(实例)

     groupadd命令详解(实例)  1.作用groupadd命令用于将新组加入系统. 2.格式groupadd [-g gid] [-o]] [-r] [-f] groupname 3.主要参数-g ...

  6. GLSL-几何着色器详解跟实例(GS:Geometry Shader)[转]

    [OpenGL4.0]GLSL-几何着色器详解和实例(GS:Geometry Shader) 一.什么是几何着色器(GS:Geometry Shader) Input Assembler(IA)从顶点 ...

  7. CvMat、Mat、IplImage之间的转换详解及实例

    见原博客:http://blog.sina.com.cn/s/blog_74a459380101obhm.html OpenCV学习之CvMat的用法详解及实例 CvMat是OpenCV比较基础的函数 ...

  8. C语言操作WINDOWS系统存储区数字证书相关函数详解及实例

     C语言操作WINDOWS系统存储区数字证书相关函数详解及实例 以下代码使用C++实现遍历存储区证书及使用UI选择一个证书 --使用CertOpenSystemStore打开证书存储区. --在循环中 ...

  9. httpd配置文件详解及实例

    httpd配置文件详解及实例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.http协议的组成 http协议是C/S架构:我们可以把浏览器(如:IE,Firefox,Safar ...

  10. oracle partition table 分区表详解

    Oracle partition table 分区表详解 分区表就是通过使用分区技术,将一张大表,拆分成多个表分区(独立的segment),从而提升数据访问的性能,以及日常的可维护性.分区表中,每个分 ...

随机推荐

  1. debian下使用dynamic printk分析usb网卡驱动

    在<debian下使用dynamic printk分析usb转串口驱动执行流程>中使用了usb转串口,当前例子使用usb网卡分析驱动(dm9601芯片). 仍然需要使能dynamic pr ...

  2. 常用java开发工具快捷键

    在这里列举一些开发中常用的快捷键 常用的idea的快捷键: 1.删除当前行:Ctrl+X 2.格式化代码:Ctrl+Alt+L 3.查看本页里面的内容:Ctrl+F 4.查看类的继承方式:Ctrl+H ...

  3. java定时任务Quartz Demo(2.X)

    直接上代码 public class HelloQuartz implements Job{ @Override public void execute(JobExecutionContext Jec ...

  4. HDFS-文件写入API

    package com.zhen.hdfs; import java.io.BufferedInputStream; import java.io.FileInputStream; import ja ...

  5. JavaWeb -- JSP+JavaBean模式

    SUN公司推出JSP技术后,同时也推荐了两种web应用程序的开发模式,一种是JSP+JavaBean模式,一种是Servlet+JSP+JavaBean模式. JSP+JavaBean模式适合开发业务 ...

  6. Codeforces Round #373 (Div. 2) A , B , C

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. Spark- 共享变量

    Shared Variables Normally, when a function passed to a Spark operation (such as map or reduce) is ex ...

  8. javascript 跨域问题解决办法总结

    跨域的意思就是不同域名之间的页面默认是无法通信的.因为浏览器默认是禁止跨域的: 图所示:chrome浏览器尝试获取mainFrame失败,提示DomException 1).假如你有个网站 a.com ...

  9. C++中int转string与string转int

    #include "stdafx.h" #include "string" #include "iostream" #include &qu ...

  10. iTerm2 + Oh My Zsh

    iTerm2 http://iterm2.com/downloads.html https://iterm2.com/downloads/stable/iTerm2-2_1_4.zip Oh My Z ...