Hive的数据模型之分区表

准备数据表:

create table sampledata
(sid int, sname string, gender string, language int, math int, english int)
row format delimited fields terminated by ',' stored as textfile;

准备文本数据:

sampledata.txt
1,Tom,M,60,80,96
2,Mary,F,11,22,33
3,Jerry,M,90,11,23
4,Rose,M,78,77,76
5,Mike,F,99,98,98

将文本数据插入到数据表:

hive> load data local inpath '/root/pl62716/hive/sampledata.txt' into table sampledata;

-partition对应于数据库中的Partition 列的密集索引

-在Hive中,表中的一个Partition对应于表下的一个目录,所有的Partition的数据都存储在对应的目录中。

创建分区表:

create table partition_table
(sid int, sname string)
partitioned by (gender string)
row format delimited fields terminated by ',';

向分区表中插入数据:

hive> insert into table partition_table partition(gender='M') select sid, sname from sampledata where gender='M';
hive> insert into table partition_table partition(gender='F') select sid, sname from sampledata where gender='F';

从内部表解析比从分区表解析效率低:

(1)内部表:

hive> explain select * from sampledata where gender='M';
OK
STAGE DEPENDENCIES:
Stage-0 is a root stage STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: sampledata
Statistics: Num rows: 1 Data size: 90 Basic stats: COMPLETE Column stats: NONE
Filter Operator
predicate: (gender = 'M') (type: boolean)
Statistics: Num rows: 1 Data size: 90 Basic stats: COMPLETE Column stats: NONE
Select Operator
expressions: sid (type: int), sname (type: string), 'M' (type: string), language (type: int), math (type: int), english (type: int)
outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
Statistics: Num rows: 1 Data size: 90 Basic stats: COMPLETE Column stats: NONE
ListSink Time taken: 0.046 seconds, Fetched: 20 row(s)

(2)分区表:

hive> explain select * from partition_table where gender='M';
OK
STAGE DEPENDENCIES:
Stage-0 is a root stage STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: partition_table
Statistics: Num rows: 2 Data size: 13 Basic stats: COMPLETE Column stats: NONE
Select Operator
expressions: sid (type: int), sname (type: string), 'M' (type: string)
outputColumnNames: _col0, _col1, _col2
Statistics: Num rows: 2 Data size: 13 Basic stats: COMPLETE Column stats: NONE
ListSink Time taken: 0.187 seconds, Fetched: 17 row(s)

Hive_Hive的数据模型_分区表的更多相关文章

  1. Hive_Hive的数据模型_汇总

    体系结构: 元数据 /HQL的执行安装: 嵌入 /远程 /本地管理: CLI /web界面 /远程服务数据类型: 基本 /复杂 /时间数据模型: 数据存储 /内部表 /分区表 /外部表 /桶表 /视图 ...

  2. Hive_Hive的数据模型_数据存储

    Hive的数据模型_数据存储 web管理工具察看HDFS文件系统:http://<IP>:50070/ 基于HDFS没有专门的数据存储格式,默认使用制表符存储结构主要包括:数据库,文件,表 ...

  3. Hive_Hive的数据模型_内部表

    Hive的数据模型_内部表 - 与数据库中的Table在概念上是类似.- 每一个Table在Hive中都有一个相应的目录存储数据.- 所有的Table数据(不包括External Table)都保存在 ...

  4. Hive_Hive的数据模型_外部表

    Hive的数据模型之外部表 外部表(External Table)- 指向已经在HDFS中存在的数据,可以创建Partition- 它和内部表在元数据的组织上是相同的,而实际数据的存储则有较大的差异. ...

  5. Hive_Hive的数据模型_视图

    - 视图是一种虚表,是一个逻辑概念:可以跨越多张表- 视图建立在已有表的基础上,视图赖以建立的这些表称为基表.- 视图可以简化复杂的查询. 创建视图 create view viewName as s ...

  6. Hive_Hive的数据模型_桶表

    对数据进行HASH运算,放在不同文件中,降低热块,提高查询速度. 例如:根据sname进行hash运算存入5个桶中. create table bucket_table(sid int, sname ...

  7. 21Mybatis_订单商品数据模型_一对多查询——resultMap方式

    这篇文章延续订单商品数据模型,这张讲述的是一对多的查询.(用resultMap) 给出几张表的内容: User表:

  8. 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结

    上一篇文章分析了数据模型,这篇文章就给出一个需求,这个需求是一对一查询,并完成这个需求. ------------------------------------------------------- ...

  9. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结

    之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...

随机推荐

  1. 用js实现图片(小球)在屏幕上上下左右移动

    <html> <head> <title>Document</title> </head> <body style="bac ...

  2. Win7 下安装MongoDB

    1).下载MongoDBhttp://downloads.mongodb.org/win32/mongodb-win32-i386-2.4.5.zip 下载Windows 32-bit版本并解压缩,程 ...

  3. 在node.js中建立你的第一个HTTp服务器

    这一章节我们将从初学者的角度介绍如何建立一个简单的node.js HTTP 服务器 创建myFirstHTTPServer.js //Lets require/import the HTTP modu ...

  4. Java如何创建内部类对象

    public static void main(String[] args) { Person p = new Test().new Person(); } class Person { String ...

  5. .DS_Store 文件是什么?Mac下面如何禁止.DS_Store生成

    .DS_Store是Mac OS保存文件夹的自定义属性的隐藏文件,如文件的图标位置或背景色,相当于Windows的desktop.ini. 1,禁止.DS_store生成:打开 “终端” ,复制黏贴下 ...

  6. dmidecode 命令

    dmidecode                                                 #  查看全面硬件信息dmidecode | grep "Product ...

  7. 1053 Path of Equal Weight (30)(30 分)

    Given a non-empty tree with root R, and with weight W~i~ assigned to each tree node T~i~. The weight ...

  8. 【LeetCode】016 3Sum Closest

    题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...

  9. Vue cli项目开启Gzip

    目录 安装 compression-webpack-plugin 更改配置文件 服务器开启gzip功能 安装 compression-webpack-plugin 建议安装v1.1.11版本,最新版本 ...

  10. 如何得到WPF中控件绑定的EventTrigger

    System.Windows.Interactivity.Interaction.GetTriggers(sender as DependencyObject)[0].Actions