[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_timefrom (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_timefrom dms.tracklog_5minwhere stock_type = 'STOCK'and day =substr(from_unixtime(unix_timestamp(), 'yyyyMMdd'), 1, 8)group by stock_codeorder by clickcnt desc limit 20) t1left join (select stock_code stockId, count(1) clickcntyesdayfrom dms.tracklog_5min awhere 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) t2on 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. hive运行mysql脚本_用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

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

  2. halcon可以用python吗_如何基于pythonnet调用halcon脚本

    这篇文章主要介绍了如何基于pythonnet调用halcon脚本,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 最近的项目中遇到了使用python程 ...

  3. java调用shell脚本及注意事项

    需求: get方法下载远程zip包,然后zip包解压,取出第一级目录再次进行压缩获取新的压缩zip包. 问题: 如果选择使用java代码的IO流操作,在不确定zip包大小的情况下可能会占用很大的内存, ...

  4. android执行命令行取得结果,Android调用shell脚本并取得输出

    Android调用shell脚本并获得输出 前段时间做的HLS流媒体服务器可以正常工作了,但是它的启动需要在PC机命令行中进行或者在Android下载个Terminal IDE软件,在Android上 ...

  5. C语言程序中调用脚本,C语言调用SHELL脚本

    在Linux 环境下Shell脚本具有非常强大的功能!使用Shell可以很方便的使用和管理Linux系统,最近学习了一点shell知识,所以一直在 想要是可以在C/C++中调用shell脚本那该有多 ...

  6. java调用shell脚本_Java 执行Shell脚本指令

    一.介绍 有时候我们在Linux中运行Java程序时,需要调用一些Shell命令和脚本.而Runtime.getRuntime().exec()方法给我们提供了这个功能,而且Runtime.getRu ...

  7. java无阻塞执行脚本,JAVA调用Shell脚本-及阻塞的解决方法

    JAVA调用Shell脚本--及阻塞的解决办法 用java调用shell,使用 Process p=Runtime.getRuntime().exec(String[] cmd); Runtime.e ...

  8. Python 调用shell脚本

    python调用Shell脚本,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容. 实际使用时视需求情况而选择 ...

  9. python调用Shell脚本:os.system(cmd)或os.popen(cmd),

    python调用Shell脚本,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容.实际使用时视需求情况而选择. ...

最新文章

  1. 转Meta的http-equiv属性详解
  2. 百变应用场景下,优酷基于图执行引擎的算法服务框架筑造之路!
  3. VC++ .NET 2003学习
  4. It Smells!不要让两个状态纠缠的类同时成为某个事件的观察者(一切都只是视图)...
  5. Android EditText 修改提示字体的大小
  6. Trie Tree 实现中文分词器
  7. usb PHY linux驱动
  8. ML.NET Cookbook:(16)什么是规范化?为什么我需要关心?
  9. mac instantclient_12_2 安装配置
  10. 1.4Activity保存现场状态
  11. mysql字段是否存在_mysql判断列是否存在
  12. android studio 经验
  13. excel处理几十万行数据_神奇吗?仅需4步,轻松在Excel处理300万行数据
  14. 基于LM324的音调放大电路
  15. 神马不是浮云,有未来就能改变世界
  16. 解决_使用大白菜软件安装纯净版win有预装软件的问题
  17. 分享143个ASP源码,总有一款适合您
  18. Item Categories
  19. C中Ascii码对照
  20. 图纸设计管理平台,彩虹图纸管理软件设计管理功能

热门文章

  1. android看电脑视频,教你用手机/平板,直接播放电脑上的视频
  2. 3D打印「心脏」体外存活超6个月,心肌组织带有规律性搏动,来自中科院清华...
  3. 马斯克的星际飞船又炸了!回收时发动机重启失败,「横」着砸向地面
  4. 马斯克:4年内,SpaceX的第一艘火星飞船将发射
  5. Hessian的使用以及理解(转)
  6. 【Windows】字符串处理
  7. Android滤镜效果实现及原理分析
  8. UltraISO软碟通U盘安装Centos7 的各种报错及解决方案
  9. Mysql多实例配置文档
  10. Chapter 1 First Sight——14