mysql 分桶_使用hive脚本一键动态分区、分区又分桶以及脚本步骤详细详解(亲测成功)...
一、动态分区以及从linux本地文件映射到hive表中。
partitioned.sql脚本中的创造数据:
mkdir /mytemp
cd mytemp
vi stu_score.txt
1,zhangshan,50,1
2,lisi,67,1
3,tom,49,2
4,jery,48,2
hive脚本内容如下------partitioned.sql
set mapreduce.framework.name=local;
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
use test;
drop table if exists stu_score;
create table if not exists stu_score(id int,name string,score int,status int) partitioned by (dt string) row format delimited fields terminated by ',';
load data local inpath '/mytemp/stu_score.txt' into table stu_score partition (dt='2018-10-18');
load data local inpath '/mytemp/stu_score.txt' into table stu_score partition (dt='2018-10-19');
dfs -cat /user/hive/warehouse/test.db/stu_score/dt=2018-10-18/stu_score.txt;
select * from stu_score;
show partitions stu_score;
create table if not exists stu_score_tmp(id int,name string,score int,status int) row format delimited fields terminated by ',';
load data local inpath '/mytemp/stu_score.txt' into table stu_score_tmp;
select * from stu_score_tmp;
insert into stu_score partition(dt) select id,name, score,status,'2018-10-28' from stu_score_tmp;
drop table if exists stu_score_tmp;
select * from stu_score;
show partitions stu_score;
hive脚本内容详细解析如下
set mapreduce.framework.name=local;
-- 将mapreduce设置为本地运行,节省时间
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
---设置hive的动态分区参数设置
use test;
--使用test数据库,为了将表格创建在test数据库下(如果没有可以改变成自己的数据库)
drop table if exists stu_score;
--为了保证不存在目标表
create table if not exists stu_score(id int,name string,score int,status int) partitioned by (dt string) row format delimited fields terminated by ',';
创建表名为stu_score ,字段及类型:id int,name string,score int,status int
partitioned by (dt string):表示通过dt进行分区
terminated by ',':表示将文本文件中的数据通过表格分割映射到创建的表中
load data local inpath '/mytemp/stu_score.txt' into table stu_score partition (dt='2018-10-18');
加载linux本地/mytemp/stu_score.txt'文件,映射到stu_score表中的dt='2018-10-18'的分区中
load data local inpath '/mytemp/stu_score.txt' into table stu_score partition (dt='2018-10-19');
再加载linux本地/mytemp/stu_score.txt'文件,映射到stu_score表中的dt='2018-10-19'的分区中
dfs -cat /user/hive/warehouse/test.db/stu_score/dt=2018-10-18/stu_score.txt;
查看分区表在hdfs上的存储情况
select * from stu_score;
查看表内容
show partitions stu_score;
查看stu_score表的分区情况
create table if not exists stu_score_tmp(id int,name string,score int,status int) row format delimited fields terminated by ',';
load data local inpath '/mytemp/stu_score.txt' into table stu_score_tmp;
创建临时表stu_score_tmp,用于将数据动态分区到已存在的分区表中
select * from stu_score_tmp;
查看临时表的stu_score_tmp内容
insert into stu_score partition(dt) select id,name, score,status,'2018-10-28' from stu_score_tmp;
将stu_score_tmp表中的数据动态分区的形式加载到stu_score表中
drop table if exists stu_score_tmp;
删除临时表,节省数据库空间
select * from stu_score;
查看stu_score表最终内容
show partitions stu_score;
查看stu_score表的最终分区情况
执行脚本命令以及测试结果:hive -f partitioned.sql
二、分区又分桶。
可以对数据表分区之后继续分桶。
stu_part_clu.sql脚本的分区又分桶用到的资源:
mkdir /mytemp
cd /mytemp
vi stu_tmp.txt
1,tom,12
2,jack,15
3,date,23
4,hadoop,24
5,sqoop,10
6,yarn,67
7,hive,34
hive脚本的具体内容如下---stu_part_clu.sql
执行脚本命令:hive -f stu_part_clu.sql
set mapreduce.framework.name=local;
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
use test;
drop table if exists stu_part_clu;
drop table if exists stu_part_clu_tmp;
create table stu_part_clu_tmp(id int,name string,age int) row format delimited fields terminated by ',';
show tables;
load data local inpath '/mytemp/stu_tmp.txt' into table stu_part_clu_tmp;
select * from stu_part_clu_tmp;
create table stu_part_clu(id int,name string,age int)partitioned by(dt string,country string) clustered by(id) sorted by (id) into 2 buckets row format delimited fields terminated by ',';
insert into stu_part_clu partition(dt,country) select id,name,age,'2018-10-19','shanghai' from stu_part_clu_tmp;
insert into stu_part_clu partition(dt,country) select id,name,age,'2018-10-19','beijing' from stu_part_clu_tmp;
insert into stu_part_clu partition(dt,country) select id,name,age,'2018-10-20','beijing' from stu_part_clu_tmp;
dfs -ls /user/hive/warehouse/test.db/stu_part_clu/dt=2018-10-19/country=shanghai/;
dfs -ls /user/hive/warehouse/test.db/stu_part_clu/dt=2018-10-20/country=beijing/;
select * from stu_part_clu tablesample(bucket 1 out of 2 on id);
drop table if exists stu_part_clu_tmp;
show tables;
分区又分桶的脚本详细解析--待更
mysql 分桶_使用hive脚本一键动态分区、分区又分桶以及脚本步骤详细详解(亲测成功)...相关推荐
- ae导出gif插件_AE脚本-一键快速输出GIF动图格式插件脚本 GifGun 1.7.15 Win/Mac 支持AE 2020...
[脚本简介] 还记得以前AE能直接输出GIF动画格式,但软件更新到 AE CS5 后就取消了直接输出GIF的功能,其实很多时候还是会用到输出GIF格式的这个格式.GifGun 脚本可以一键输出G ...
- mysql 5.6 安装库_MySQL5.6安装步骤图文详解
MySQL是一个开放源码的小型关系型数据库管理系统,目前MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网 ...
- grafana graphite statsd搭建安装部署 实时监控_亲测成功
grafana graphite statsd搭建安装部署 实时监控_亲测成功 docker部署grafana graphite stastd实时监控告警配置_亲测成功 下载软件 # 下载carbon ...
- Linux安装svn服务器和权限配置_亲测成功
Linux安装svn服务器和权限配置_亲测成功 SVN简介 SVN是Subversion的简称,是一个开放源代码的版本控制系统,通过采用分支管理系统的高效管理,简而言之就是用于多个人共同开发同一个项目 ...
- Linux挂载磁盘和磁盘分区及设置开机自动挂载_亲测成功
Linux挂载磁盘和磁盘分区及设置开机自动挂载_亲测成功 Linux下磁盘分区命令主要由两个: fdisk :最大支持不超过2T,MBR分区: parted :支持GPT,适用于大容量分区: 如果挂载 ...
- vivo分屏_科技怎样应用在生活中?vivo分屏+Jovi语音助手=高效学习体验
学习,可以说是贯穿每个人一生的事情.它无关乎我们的年龄,无关乎我们所涉及的领域,只要我们在汲取知识,都是在向着更加广阔的领域前行.随着时间的推进,我们的学习方式也渐渐脱离了书本这单一的形式,网络查询. ...
- ios分屏_大屏时代来临,到底应该如何分屏
伴随着人们对移动端设备大屏的追求,苹果的Pad系列产品推出了大屏的Pro,大屏设备的出现自然也产生了IOS分屏功能.IOS9之后开始支持分屏多任务功能,给用户的日常使用带来了新的体验,方便用户高效的使 ...
- vivo分屏_在线上课查资料两不误,vivo“分屏多任务”让你化身多核处理器
新年刚到来,我们因为进入了特殊时期,不知道什么时候才能到头,各大中小学都延迟了开课时间.为了保证学业的顺利完成,各大师生也是绞尽脑汁,克服重重困难,以线上教学的形式来开展授课工作.如此一来,既能保证教 ...
- Mysql 优化器内部JOIN算法hash join On-Disk Hash Join Grace Hash Join Hybrid hash join过程详解
Mysql 各种hash join算法讲解 hash join的概述 提到hash join之前自然得说Nest loop join,以两个表的关联为例,它其实是个双层循环,先遍历外层的表(n条),再 ...
最新文章
- mysql和mariadb可以同时使用吗,MariaDB与MySQL在一台服务器同时运行
- Android 通过腾讯WebService API获取 地址经纬度
- 牛!又一顶级大厂开招.NET,5年35k!
- 50个最有用的Matplotlib数据分析与可视化图
- java ee 导入项目_最代码网站java项目下载后遇到项目打开,导入,运行的问题QA汇总...
- mysql relay log 配置_mysql relay log参数汇总
- mysql bcp数据文件_BCP 数据的导入和导出
- 这些超好用的 Mac 系统自带软件,来试试
- Java面试准备(一)
- STM32物联网实战教程(一)—ESP8266的AT指令集详解
- js动态添加元素时绑定onclick函数
- 网络基础知识详解(图解版)
- Presto 0.244.1 aarch64编译
- 网络请求数据demo
- oracle jta,JTA和两阶段提交,处理全局事务
- 非法字符: '\ufeff' 解决方案(Android Studio)
- vue的混入mixin拙见
- Access转出到Mysql,咱自己动手丰衣足食.. -- 纯JS代码
- 5G网络逐渐普及TSINGSEE青犀视频云边端架构网页视频实时互动直播系统又将如何发展?
- Ora2Pg 高级配置之导出指定模式
热门文章
- 首款国产8K 50P小型化广播级摄像机背后的故事
- 什么是uni-app?
- RNA-seq流程学习笔记(10)-使用HTSeq-count软件对reads进行计数
- 计算机专业择偶标准,爱情句子:说来说去我的择偶标准也就一个字——你
- python bokeh 3d_Python数据可视化:基于Bokeh的可视化绘图
- 网易视频云余利华:以用户体验为核心,深耕PaaS云生态
- 响应式设计微网站静态模板,适合游戏、新闻资讯等平台
- 《Spark用户评论监控实时报警系统》
- 基于python的opencv_基于Python和OpenCV的人脸检测
- 一个屌丝程序猿的人生(一)