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. PHP闭包详解

    匿名函数 提到闭包就不得不想起匿名函数,也叫闭包函数(closures),貌似PHP闭包实现主要就是靠它.声明一个匿名函数是这样: $func = function() { }; //带结束符 可以看 ...

  2. 使用 DNSPOD API 实现域名动态解析

    0. 简单概述在家里放一个 NAS 服务器,但是宽带的 IP 地址经常改变,一般路由器自带的花生壳域名解析可以解决,如果路由器没有类似功能或者想使用自己的域名,可以尝试使用 DNSPOD API 来实 ...

  3. c++queue容器介绍

    一.queue模版类的定义在<queue>头文件中. queue与stack模版非常类似,queue模版也需要定义两个模版参数,一个是元素类型,一个是容器类型,元素类型是必要的,容器类型是 ...

  4. ES BM25 TF-IDF相似度算法设置——

    Pluggable Similarity Algorithms Before we move on from relevance and scoring, we will finish this ch ...

  5. MD5算法的简单编写

    package com.t_09; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; ...

  6. C字符串末尾的'\0'问题

    C语言的字符串要注意最后一位默认是'/0'的问题.这是一个易错点. strlen()计算长度时不考虑末尾的'\0' //例1 void test1() { ]; "; strcpy( str ...

  7. 使用Tornado作为Django App的服务器

    闲来无事,折腾折腾. 老是听说tonado是个异步web框架和服务器,作为框架倒是了解到了,但是服务器一直不太懂.所以决定了解一下,既然可以做服务器,那就把自己的django app部署到这上边去. ...

  8. spring boot 学习三:OAuth2 认证

    1:  代码地址: https://github.com/liufeiSAP/uaa-zuul 2:     安装: postgres 下载 https://www.openscg.com/bigsq ...

  9. 【244】◀▶IEW-Unit09

    Unit 9 Food 1)Model1题目及范文讲解 In the world today, there is a problem with food production. As a result ...

  10. CF-835C

    C. Star sky time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...