Hive表中Partition的创建
作用:
在Hive Select查询中一般会扫描整个表内容,会消耗很多时间做没必要的工作。有时候只需要扫描表中关心的一部分数据,在对应的partition里面去查找就可以,减少查询时间。
1. 创建表
]# cat create_rating_table_p.sql
create external table rating_table_p
(userId STRING,
movieId STRING,
rating STRING
)
partitioned by (dt STRING)
row format delimited fields terminated by '\t'
lines terminated by '\n';
2. 导入数据
LOAD DATA LOCAL INPATH '/usr/local/hive/test/hive_test_3/ml-latest-small/2009-12.data' OVERWRITE INTO TABLE rating_table_p partition(dt='2009-12');
LOAD DATA LOCAL INPATH '/usr/local/hive/test/hive_test_3/ml-latest-small/2003-09.data' OVERWRITE INTO TABLE rating_table_p partition(dt='2003-09');
3. HDFS上面查看,会在以表名为文件夹下面,有两个以时间命名的文件夹,对应日期数据存在对应文件夹下面
]$ hdfs dfs -ls /user/hive/warehouse/rating_table_p
Found items
drwxrwxrwx - hadoop supergroup -- : /user/hive/warehouse/rating_table_p/dt=-
drwxrwxrwx - hadoop supergroup -- : /user/hive/warehouse/rating_table_p/dt=-
4. Hive表中查询
hive> select userid, dt from rating_table_p where dt='2009-12' limit ;
OK
-
-
-
-
-
-
-
-
-
-
5. 删除分区
alter table rating_table_p drop if exists partition(dt='2003-10');
6.添加分区
alter table rating_table_p add if not exists partition(dt='2003-10');
Hive表中Partition的创建的更多相关文章
- 将DataFrame数据如何写入到Hive表中
1.将DataFrame数据如何写入到Hive表中?2.通过那个API实现创建spark临时表?3.如何将DataFrame数据写入hive指定数据表的分区中? 从spark1.2 到spark1.3 ...
- 使用spark对hive表中的多列数据判重
本文处理的场景如下,hive表中的数据,对其中的多列进行判重deduplicate. 1.先解决依赖,spark相关的所有包,pom.xml spark-hive是我们进行hive表spark处理的关 ...
- sqoop导入数据到hive表中的相关操作
1.使用sqoop创建表并且指定对应的hive表中的字段的数据类型,同时指定该表的分区字段名称 sqoop create-hive-table --connect "jdbc:oracle: ...
- 20.采集项目流程篇之清洗数据绑定到hive表中
先启动hive 在mydb2这个数据库中创建表: create external table mydb2.access(ip string,day string,url string,upflow s ...
- 11.把文本文件的数据导入到Hive表中
先在hive里面创建一个表 create table mydb2.t3(id int,name string,age int) row format delimited fields terminat ...
- 使用spark将内存中的数据写入到hive表中
使用spark将内存中的数据写入到hive表中 hive-site.xml <?xml version="1.0" encoding="UTF-8" st ...
- 如何将hive表中的数据导出
近期经常将现场的数据带回公司测试,所以写下该文章,梳理一下思路. 1.首先要查询相应的hive表,比如我要将c_cons这张表导出,我先查出hive中是否有这张表. 查出数据,证明该表在hive中存在 ...
- 批量导入数据到hive表中:假设我有60张主子表如何批量创建导入数据
背景:根据业务需要需要把60张主子表批量入库到hive表. 创建测试数据: def createBatchTestFile(): Unit = { to ) { val sWriter = new P ...
- spark读取mongodb数据写入hive表中
一 环境: spark-: hive-; scala-; hadoop--cdh-; jdk-1.8; mongodb-2.4.10; 二.数据情况: MongoDB数据格式{ "_i ...
随机推荐
- [移动] Xamarin install
It was not possible to complete an automatic installation. This might be due to a problem with your ...
- Spring Cloud Eureka 服务消费者
参考<spring cloud 微服务实战> 现在已经构建了服务注册中心和服务提供中心,下面就来构建服务消费者: 服务消费者主要完成:发现服务和消费服务.其中服务的发现主要由Eureka的 ...
- jfinal如何查看post还是get请求?
jfinal如何查看post还是get请求? controller里面getRequest().getMethod()就行了. 值为 'GET' 或者 'POST'
- 7.19python昨日复习和多线程
关于GIL锁的经典面试题!!
- eclipse配置Js环境spket
网上下载spket-1.6.16.jar破解版(目前最新版本) 1.如果你的JDK在1.6以上,可以直接双击spket-1.6.16.jar运行安装. 其它,使用命令行方式.(注意:自己切换命令行到s ...
- C语言清屏函数
Devc++ 与VC中的清屏函数 #include<stdio.h> #include<stdlib.h>//清屏函数的头文 int main() { int i; for(i ...
- CodeForces - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
- Python:列表生成式
List Comprehensions #列表生成式:Python内置的非常简单却强大的可以用来创建list的生成式. #生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]可 ...
- 企业证书安装App
通过苹果自带的浏览器访问:itms-services:///?action=download-manifest&url=https://www.xxxx.com:xxx/xxxx/xxx.pl ...
- 5 Tips for Building a Winning DevOps Culture
对于企业来说,前途未卜的改变往往很难发生,就像航海一样,重复的往往是久经验证的安全航线,这点在DevOps文化的构建上同样如此.近日,CA Technologies的高级策略师Peter Waterh ...