[Author]: kwu

基于sparksql调用shell脚本运行SQL,sparksql提供了类似hive中的 -e  , -f ,-i的选项

1、定时调用脚本

#!/bin/sh
# upload logs to hdfs yesterday=`date --date='1 days ago' +%Y%m%d` /opt/modules/spark/bin/spark-sql -i /opt/bin/spark_opt/init.sql --master spark://10.130.2.20:7077 --executor-memory 6g --total-executor-cores 45 --conf spark.ui.port=4075 -e "\
insert overwrite table st.stock_realtime_analysis PARTITION (DTYPE='01' )
select t1.stockId as stockId,
t1.url as url,
t1.clickcnt as clickcnt,
0,
round((t1.clickcnt / (case when t2.clickcntyesday is null then 0 else t2.clickcntyesday end) - 1) * 100, 2) as LPcnt,
'01' as type,
t1.analysis_date as analysis_date,
t1.analysis_time as analysis_time
from (select stock_code stockId,
concat('http://stockdata.stock.hexun.com/', stock_code,'.shtml') url,
count(1) clickcnt,
substr(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'),1,10) analysis_date,
substr(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'),12,8) analysis_time
from dms.tracklog_5min
where stock_type = 'STOCK'
and day =
substr(from_unixtime(unix_timestamp(), 'yyyyMMdd'), 1, 8)
group by stock_code
order by clickcnt desc limit 20) t1
left join (select stock_code stockId, count(1) clickcntyesday
from dms.tracklog_5min a
where stock_type = 'STOCK'
and substr(datetime, 1, 10) = date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'),1)
and substr(datetime, 12, 5) <substr(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'), 12, 5)
and day = '${yesterday}'
group by stock_code) t2
on t1.stockId = t2.stockId;
"\ sqoop export --connect jdbc:mysql://10.130.2.245:3306/charts --username guojinlian --password Abcd1234 --table stock_realtime_analysis --fields-terminated-by '\001' --columns "stockid,url,clickcnt,splycnt,lpcnt,type" --export-dir /dw/st/stock_realtime_analysis/dtype=01;

init.sql内容为载入udf:

add jar /opt/bin/UDF/hive-udf.jar;
create temporary function udtf_stockidxfund as 'com.hexun.hive.udf.stock.UDTFStockIdxFund';
create temporary function udf_getbfhourstime as 'com.hexun.hive.udf.time.UDFGetBfHoursTime';
create temporary function udf_getbfhourstime2 as 'com.hexun.hive.udf.time.UDFGetBfHoursTime2';
create temporary function udf_stockidxfund as 'com.hexun.hive.udf.stock.UDFStockIdxFund';
create temporary function udf_md5 as 'com.hexun.hive.udf.common.HashMD5UDF';
create temporary function udf_murhash as 'com.hexun.hive.udf.common.HashMurUDF';
create temporary function udf_url as 'com.hexun.hive.udf.url.UDFUrl';
create temporary function url_host as 'com.hexun.hive.udf.url.UDFHost';
create temporary function udf_ip as 'com.hexun.hive.udf.url.UDFIP';
create temporary function udf_site as 'com.hexun.hive.udf.url.UDFSite';
create temporary function udf_UrlDecode as 'com.hexun.hive.udf.url.UDFUrlDecode';
create temporary function udtf_url as 'com.hexun.hive.udf.url.UDTFUrl';
create temporary function udf_ua as 'com.hexun.hive.udf.useragent.UDFUA';
create temporary function udf_ssh as 'com.hexun.hive.udf.useragent.UDFSSH';
create temporary function udtf_ua as 'com.hexun.hive.udf.useragent.UDTFUA';
create temporary function udf_kw as 'com.hexun.hive.udf.url.UDFKW';
create temporary function udf_chdecode as 'com.hexun.hive.udf.url.UDFChDecode';

设置ui的port

--conf spark.ui.port=4075 

默觉得4040,会与其它正在跑的任务冲突,这里改动为4075

设定任务使用的内存与CPU资源

--executor-memory 6g --total-executor-cores 45

原来的语句是用hive
-e 运行的,改动为spark后速度大加快了。

原来为15min,提升速度后为 45s.

基于sparksql调用shell脚本运行SQL的更多相关文章

  1. Java 调用 shell 脚本详解

    这一年的项目中,有大量的场景需要Java 进程调用 Linux的bash shell 脚本实现相关功能. 从之前的项目中拷贝的相关模块和网上的例子来看,有个别的“陷阱”造成调用shell 脚本在某些特 ...

  2. Centos下使用php调用shell脚本

    我们在实际项目中或许会遇到php调用shell脚本的需求.下面就用简单案例在Centos环境下实践 准备 查看php.ini中配置是否打开安全模式 //php.ini safe_mode = //这个 ...

  3. 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

    1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件  特地将执行map的个数设置为变量  测试 可以java代码传参数 ...

  4. Python 调用 Shell脚本的方法

    Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...

  5. [Python]在python中调用shell脚本,并传入参数-02python操作shell实例

    首先创建2个shell脚本文件,测试用. test_shell_no_para.sh 运行时,不需要传递参数 test_shell_2_para.sh 运行时,需要传递2个参数  test_shell ...

  6. Spring Boot 实现看门狗功能 (调用 Shell 脚本)

    需要实现看门狗功能,定时检测另外一个程序是否在运行,使用 crontab 仅可以实现检测程序是否正在运行,无法做到扩展,如:手动重启.程序升级(如果只需要实现自动升级功能可以使用 inotify)等功 ...

  7. 【原】Gradle调用shell脚本和python脚本并传参

    最近由于项目自动化构建的需要,研究了下gradle调用脚本并传参的用法,在此作个总结. Pre build.gradle中定义了$jenkinsJobName $jenkinsBuild两个Jenki ...

  8. 调用shell脚本,IP处理

    //调用shell脚本,IP处理 package com.letv.sdns.web.utils; import org.slf4j.Logger; import org.slf4j.LoggerFa ...

  9. C程序调用shell脚本共有三种方法

    C程序调用shell脚本共有三种法子 :system().popen().exec系列函数call_exec1.c ,内容为:system() 不用你自己去产生进程,它已经封装了,直接加入自己的命令e ...

随机推荐

  1. android 九宫格(16宫格)控件

    public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...

  2. File and Folder Permissions

    https://msdn.microsoft.com/en-us/library/bb727008.aspx On NTFS volumes, you can set security permiss ...

  3. 英语发音规则---D字母

    英语发音规则---D字母 一.总结 一句话总结: 1.D发[d]音? doctor ['dɒktə] n. 医生:博士 bread [bred] n. 面包:生计 hand [hænd] n. 手,手 ...

  4. 云:VMware

    ylbtech-云:VMware VMware总部位于美国加州帕洛阿尔托 ,是全球云基础架构和移动商务解决方案厂商,提供基于VMware的解决方案,企业通过数据中心改造和公有云整合业务,借助企业安全转 ...

  5. [jzoj 3175] 数树数 解题报告 (树链剖分)

    interlinkage: https://jzoj.net/senior/#main/show/3175 description: 给定一棵N 个节点的树,标号从1~N.每个点有一个权值.要求维护两 ...

  6. python中is与==的差别

    # is:比较的是两个对象的id值是否相等,# 也就是比较俩对象是否为同一个实例对象,# 是否指向同一个内存地址 # s = "alex"# abc = id(s) # 得到内存地 ...

  7. ROS-参数

    前言:参数的用法. 一.参数常用命令 命令 功能 rosparam list 参数列表 rosparam get 获取参数 rosparam set  设置参数 rosparam load 加载参数 ...

  8. 双系统下Ubuntu安装教程

    一.下载Ubuntu镜像包 二.用老毛桃制作U盘启动盘 三.下载Universal USB Installer 下载后无需安装,直接运行Universal USB Installer, step1: ...

  9. KCP kcptun

    简介 KCP是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低 30%-40%,且最大延迟降低三倍的传输效果.纯算法实现,并不负责底层协议(如UDP)的收发,需要使用者 ...

  10. 浅谈SpringCloud (一) 什么是微服务和不使用SpringCloud怎么访问服务提供者

    微服务和SpringCloud介绍 1.什么是微服务? 看过一遍介绍的很清楚的博客:https://blog.csdn.net/wuxiaobingandbob/article/details/786 ...