hadoop之hive高级操作
在输出结果较多,需要输出到文件中时,可以在hive CLI之外执行hive -e "sql" > output.txt操作
但当SQL语句太长或太多时,这种方式不是很方便,可以考虑将SQL语句存为sql.hql文件中,然后执行 hive -f sql.hql >output.txt操作
如果是多个语句,且要输出到多个文件,只好把SQL写在shell脚本中,下面附一个例子
start_day=$
end_day=$
start_date=`date +"%Y-%m-%d" -d "${start_day}"`
end_date=`date +"%Y-%m-%d" -d "${end_day}"` active="
use ycappdata;
select ctl_dt,'active' ,count(distinct dvid) from sa_daydau_detail
where ctl_dt between '${start_date}' and '${end_date}'
group by ctl_dt,'active' ;" loss="
use ycappdata;
select date_add(from_unixtime(unix_timestamp(lastactivedate,'yyyy/MM/dd hh:mm:ss'),'yyyy-MM-dd'),),'loss' ,count(distinct deviceid) from ext_db_apploginstats
where from_unixtime(unix_timestamp(lastactivedate,'yyyy/MM/dd hh:mm:ss'),'yyyy-MM-dd') between date_sub('${start_date}',) and date_sub('${end_date}',)
group by date_add(from_unixtime(unix_timestamp(lastactivedate,'yyyy/MM/dd hh:mm:ss'),'yyyy-MM-dd'),),'loss';" active_month_distribute="
use ycappdata;
select a.ctl_dt,'active_month_distribute',concat('m',month(start_dt)),count(distinct b.dvid) from
(select ctl_dt,dvid from sa_daydau_detail where ctl_dt between '${start_date}' and '${end_date}')a
left outer join
(select start_dt,dvid from sa_firststartdate_dvid where start_dt between '2017-01-01' and '${end_date}')b
on lower(a.dvid)=lower(b.dvid)
group by a.ctl_dt,'active_month_distribute',concat('m',month(start_dt)) ;" active_date_distribute="
use ycappdata;
select a.ctl_dt,'active_date_distribute',
case when datediff(a.ctl_dt,b.start_dt)= then 'd0' when datediff(a.ctl_dt,b.start_dt)<= then 'd30'
when datediff(a.ctl_dt,b.start_dt)<= then 'd60' when datediff(a.ctl_dt,b.start_dt)<= then 'd90'
when datediff(a.ctl_dt,b.start_dt)<= then 'd120' when datediff(a.ctl_dt,b.start_dt)<= then 'd150'
when datediff(a.ctl_dt,b.start_dt)<= then 'd180' else 'd181' end,count(distinct b.dvid) from
(select ctl_dt,dvid from sa_daydau_detail where ctl_dt between '${start_date}' and '${end_date}')a
left outer join
(select start_dt,dvid from sa_firststartdate_dvid where start_dt between '2017-01-01' and '${end_date}')b
on lower(a.dvid)=lower(b.dvid)
group by a.ctl_dt,'active_date_distribute',case when datediff(a.ctl_dt,b.start_dt)= then 'd0' when datediff(a.ctl_dt,b.start_dt)<= then 'd30'
when datediff(a.ctl_dt,b.start_dt)<= then 'd60' when datediff(a.ctl_dt,b.start_dt)<= then 'd90'
when datediff(a.ctl_dt,b.start_dt)<= then 'd120' when datediff(a.ctl_dt,b.start_dt)<= then 'd150'
when datediff(a.ctl_dt,b.start_dt)<= then 'd180' else 'd181' end ;" hive -e "${active}" >> app_operate.txt
hive -e "${loss}" >> app_operate.txt
hive -e "${active_month_distribute}" >> app_operate.txt
hive -e "${active_date_distribute}" >> app_operate.txt while [ ${start_day} -le ${end_day} ]
do
current_date=`date +"%Y-%m-%d" -d "${start_day}"` week_active="
use ycappdata;
select '${current_date}','week_active',count(distinct dvid) from sa_daydau_detail
where ctl_dt between date_sub('${current_date}',pmod(datediff('${current_date}', '2017-01-02'), )) and '${current_date}'
group by '${current_date}','week_active'; " month_active="
use ycappdata;
select '${current_date}','month_active',count(distinct dvid) from sa_daydau_detail
where ctl_dt between trunc('${current_date}','MM') and '${current_date}'
group by '${current_date}','month_active'; " active_active_distribute="
use ycappdata;
select '${current_date}','active_active_distribute',concat('d',days),count(distinct ab.dvid) from
(select b.dvid,count(distinct b.ctl_dt) as days from
(select ctl_dt,dvid from sa_daydau_detail
where ctl_dt='${current_date}')a
join
(select ctl_dt,dvid from sa_daydau_detail
where ctl_dt between date_sub('${current_date}',) and '${current_date}')b
on lower(a.dvid)=lower(b.dvid)
group by b.dvid )ab
group by '${current_date}','active_active_distribute',concat('d',days);" newuser_retain="
use ycappdata;
select a.start_dt,'newuser_retain',concat('d',datediff(b.ctl_dt,a.start_dt)),count(distinct b.dvid) from
(select start_dt,dvid from sa_firststartdate_dvid
where start_dt between date_sub('${current_date}',) and '${current_date}')a
left outer join
(select ctl_dt,dvid from sa_daydau_detail
where ctl_dt between date_sub('${current_date}',) and '${current_date}')b
on lower(a.dvid)=lower(b.dvid)
group by a.start_dt,'newuser_retain',concat('d',datediff(b.ctl_dt,a.start_dt)); " active_retain="
use ycappdata;
select a.ctl_dt,'active_retain',concat('d',datediff(b.ctl_dt,a.ctl_dt)),count(distinct b.dvid) from
(select ctl_dt,dvid from sa_daydau_detail
where ctl_dt between date_sub('${current_date}',) and '${current_date}')a
left outer join
(select ctl_dt,dvid from sa_daydau_detail
where ctl_dt between date_sub('${current_date}',) and '${current_date}')b
on lower(a.dvid)=lower(b.dvid)
where a.ctl_dt<=b.ctl_dt
group by a.ctl_dt,'active_retain',concat('d',datediff(b.ctl_dt,a.ctl_dt)); " echo "${week_active}"
echo "${month_active}"
echo "${active_active_distribute}"
echo "${newuser_retain}"
echo "${active_retain}" hive -e "${week_active}" >> app_operate.txt
hive -e "${month_active}" >> app_operate.txt
hive -e "${active_active_distribute}" >> app_operate.txt
hive -e "${newuser_retain}" >> app_operate.txt
hive -e "${active_retain}" >> app_operate.txt
start_day=`date +"%Y%m%d" -d "${start_day} 1 days" `
done
hadoop之hive高级操作的更多相关文章
- Hadoop 上Hive 的操作
数据dept表的准备: --创建dept表 CREATE TABLE dept( deptno int, dname string, loc string) ROW FORMAT DELIMITED ...
- 大数据技术之_08_Hive学习_04_压缩和存储(Hive高级)+ 企业级调优(Hive优化)
第8章 压缩和存储(Hive高级)8.1 Hadoop源码编译支持Snappy压缩8.1.1 资源准备8.1.2 jar包安装8.1.3 编译源码8.2 Hadoop压缩配置8.2.1 MR支持的压缩 ...
- 初识Hadoop、Hive
2016.10.13 20:28 很久没有写随笔了,自打小宝出生后就没有写过新的文章.数次来到博客园,想开始新的学习历程,总是被各种琐事中断.一方面确实是最近的项目工作比较忙,各个集群频繁地上线加多版 ...
- Hadoop之Hive篇
想了解Hadoop整体结构及各框架角色建议飞入这篇文章,写的很好:http://www.open-open.com/lib/view/open1385685943484.html .以下文章是本人参考 ...
- 大数据技术生态圈形象比喻(Hadoop、Hive、Spark 关系)
[摘要] 知乎上一篇很不错的科普文章,介绍大数据技术生态圈(Hadoop.Hive.Spark )的关系. 链接地址:https://www.zhihu.com/question/27974418 [ ...
- hadoop记录-hive常见设置
分区表 set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict;create tabl ...
- hadoop安装hive及java调用hive
1.安装hive 在安装hive前,请确保已经安装好了hadoop,如未安装,请参考centoos 安装hadoop集群进行安装: 1.1.下载,解压 下载hive2.1.1:http://mirr ...
- HIVE简单操作
1.hive命令登录HIVE数据库后,执行show databases;命令可以看到hive数据库中有一个默认的default数据库. [root@hadoop hive]# hive Logging ...
- Hadoop生态圈-Hive快速入门篇之HQL的基础语法
Hadoop生态圈-Hive快速入门篇之HQL的基础语法 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客的重点是介绍Hive中常见的数据类型,DDL数据定义,DML数据操作 ...
随机推荐
- Vim 写 iOS App
Vim 写 iOS App 我们都知道 Vim 和 Emacs 都是文本编辑器中的上古神器,你也许用 ctags,cscopes 配合 Vim 完成过大型 C 或者 C++ 的开发,你也许配合过其他插 ...
- 至HDFS附加内容
在最近的项目开发中遇到的问题: 需要产生良好hdfs文件的其他内容.但使用在线版1.0.3.见发现官方文件,于1.0.4支持的文件的版本号之后append 一下是向hdfs中追加信息的操作方法 假设你 ...
- /var/tmp/.oracle 和 oracle listener (监听)的一点理解
关于 /var/tmp/.oracle 的作用測试 ~---查看 /var/tmp 的权限 [root@lixora var]# ll total 164 ... drwxrwxrwt 3 root ...
- 4 DDD里面的界限上下文
1 界限上下文概念的出现 当开发一个电子商务系统的时候,会给系统划分很多子域,销售子域是核心子域,此外还有物流子域,商品子域等支撑子域.在这些子域里面,一个商品product在销售子域和商品子域里面外 ...
- Python 推断素数
a = raw_input() #输入数字 a = int(a) #铸造成int b=True #的标记 for i in range(2,a): #从2开始循环本身 if a%i==0: #除了自己 ...
- iOS 往来--书面资料
写接触知识和查询功能的基础,现在我们就来看看信息写入 新 变化 删除 #pragma mark - 系人信息 //创建联系人 - (void) creatNewRecord { CFErrorRef ...
- cocos2D-X从的源代码的分析cocos2D-X学习OpenGL(1)----cocos2D-X渲染架构
个人原创.欢迎转载,转载请注明原文地址http://blog.csdn.net/bill_man 从本篇文章開始,将分析cocos2D-X 3.0源码,第一部分是从cocos2D-X学习OpenGL ...
- 合并 && 还原属性链
效果 原数据 { "id": 10, "text": { "title": "title", "content ...
- WPF实现弹幕
实现效果 运用WPF的DoubleAnimation实现桌面端的弹幕效果 示例代码 https://github.com/zLulus/BarrageDemo
- [转载]Delphi常用类型及定义单元
原文地址:Delphi常用类型及定义单元作者:沧海一声笑 Delphi常用类型及定义单元-总结 sndplaysound mmsystem Type Unit Date ...