【Hive学习之四】Hive 案例
环境
  虚拟机:VMware 10 
  Linux版本:CentOS-6.5-x86_64 
  客户端:Xshell4
  FTP:Xftp4
  jdk8
  hadoop-3.1.1
  apache-hive-3.1.1
一、需求:统计出掉线率最高的前10基站
  数据:
    record_time:通话时间
    imei:基站编号
    cell:手机编号
    drop_num:掉话的秒数
    duration:通话持续总秒数

1、建表
--数据表
create table cell_monitor(
record_time string,
imei string,
cell string,
ph_num string,
call_num string,
drop_num int,
duration int,
drop_rate DOUBLE,
net_type string,
erl string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE; --结果表
create table cell_drop_monitor(
imei string,
total_call_num int,
total_drop_num int,
d_rate DOUBLE
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;
2、导入数据
LOAD DATA LOCAL INPATH '/root/cdr_summ_imei_cell_info.csv' OVERWRITE INTO TABLE cell_monitor;
#展示前10条
hive> select * from cell_monitor limit 10;
OK
record_time imei cell ph_num call_num NULL NULL NULL net_type erl
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
-- ::+ - 0.0 G
Time taken: 0.132 seconds, Fetched: row(s)
hive>
出现NULL 是因为字段类型是非字符串类型,匹配不上 所以显示NULL
3、查询掉线率 倒序排列
from cell_monitor cm
insert overwrite table cell_drop_monitor
select cm.imei,sum(cm.drop_num),sum(cm.duration),sum(cm.drop_num)/sum(cm.duration) d_rate
group by cm.imei
sort by d_rate desc;

二、使用hive实现wordcount
1、建表
--数据表
create table docs(line string);
--结果表
create table wc(word string, totalword int);
hive> create table docs(line string);
OK
Time taken: 0.722 seconds
hive> create table wc(word string, totalword int);
OK
Time taken: 0.045 seconds
2、导入数据
/root/wc:
hadoop hello world
hello hadoop
hbase zookeeper
name name name
导入数据:
hive> load data local inpath '/root/wc' into table docs;
Loading data to table default.docs
OK
Time taken: 0.392 seconds
hive> select * from docs;
OK
hadoop hello world
hello hadoop
hbase zookeeper
name name name
Time taken: 1.728 seconds, Fetched: 4 row(s)
3、统计
hive> select explode(split(line, ' ')) as word from docs;
OK
hadoop
hello
world
hello
hadoop
hbase
zookeeper
name
name
name
Time taken: 0.377 seconds, Fetched: row(s)
hive>
下面统计语句会产生MR任务:
from (select explode(split(line, ' ')) as word from docs) w
insert into table wc
select word, count() as totalword
group by word
order by word;

4、查询结果
hive> select * from wc;
OK
hadoop	2
hbase	1
hello	2
name	3
world	1
zookeeper	1
Time taken: 0.121 seconds, Fetched: 6 row(s)
hive>
【Hive学习之四】Hive 案例的更多相关文章
- hive学习(五) 应用案例
		
1.实现struct数据结构例子 1.1创建student表 create table student( id int, info struct<name:string,age:int> ...
 - hive学习(二) hive操作
		
hive ddl 操作官方手册https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL hive dml 操作官方手 ...
 - Hive学习之四      《Hive分区表场景案例应用案例,企业日志加载》 详解
		
文件的加载,只需要三步就够了,废话不多说,来直接的吧. 一.建表 话不多说,直接开始. 建表,对于日志文件来说,最后有分区,在此案例中,对年月日和小时进行了分区. 建表tracktest_log,分隔 ...
 - hive学习(四) hive的函数
		
1.内置运算符 1.1关系运算符 运算符 类型 说明 A = B 所有原始类型 如果A与B相等,返回TRUE,否则返回FALSE A == B 无 失败,因为无效的语法. SQL使用”=”,不使用”= ...
 - hive学习(三) hive的分区
		
1.Hive 分区partition 必须在表定义时指定对应的partition字段 a.单分区建表语句: create table day_table (id int, content string ...
 - Hive学习笔记——Hive中的分桶
		
对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...
 - Hive学习:Hive连接JOIN用例详解
		
1 准备数据: 1.1 t_1 01 张三 02 李四 03 王五 04 马六 05 小七 06 二狗 1.2 t_2 01 11 03 33 04 44 06 66 07 77 08 88 1.3 ...
 - Hive学习路线图(转)
		
Hadoophivehqlroadmap学习路线图 1 Comment Hive学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig ...
 - 【转】Hive学习路线图
		
原文博客出自于:http://blog.fens.me/hadoop-hive-roadmap/ 感谢! Hive学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Ha ...
 
随机推荐
- java 集合(一)ArrayList的继承树
			
这是ArrayList的继承树,它继承了AbstractCollection抽象类,AbstractCollection类实现了Collection接口,Collection接口继承Iterable接 ...
 - 【Python全栈-jQuery】jQuery基础知识
			
前端学习之jQuery 一. jQuery是什么? <1> jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. < ...
 - git push error:error: insufficient permission for adding an object to repository database ./object解决
			
在服务器代码库xxx.git文件夹中:1.sudo chmod -R g+ws *2.sudo chgrp -R mygroup * //mygroup是该文件夹的所有组3.git repo-conf ...
 - 前端 HTML body标签相关内容 常用标签 表单标签 form里面的 input标签介绍
			
input标签用于接收用户输入.可以利用input 可以做登录页面 input标签是行内块标签 <input> 元素会根据不同的 type 属性,变化为多种形态. name属性:表单点击提 ...
 - 20190316 Python - Pandas
			
1. python 安装3.7版本 2. 第三方包进行数据加工和呈现 需要注意的是,你安装过程中会有很多依赖包问题,如果网络异常,那么就使用https://pypi.org/ 地址去找对应的包下载 ...
 - git命令操作的时候,出现中文名显示问题
			
方法一:git config --global core.quotepath false 方法二: Windows系统的Git默认是不支持中文显示的,需要进行一系列的设置才能避免乱码的出现,下面总结如 ...
 - vue中$set的用法
			
数组: this.$set(Array,index, newValue) 对象: this.$set(Object, key, value)
 - 为什么char *name="it",printf("%s",name) 能够输出字符串?
			
“it”里面是3个字符 “i”“t”“/0”,%s会打印指针指向的字符就是“i”,知道遇到“/0”停止,所以打印出来是“it”
 - golang 的 buffered channel 及 unbuffered channel
			
The channel is divided into two categories: unbuffered and buffered. (1) Unbuffered channelFor unbuf ...
 - [vue]webpack使用样式
			
webpack: 使用自己写样式 main.js导入全局生效 import Vue from 'vue' import App from './App.vue' import './index.css ...