[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. JavaScript 中对变量和函数声明提前的演示样例

    如题所看到的,看以下的演示样例(能够使用Chrome浏览器,然后F12/或者右键,审查元素.调出开发人员工具,进入控制台console输入)(使用技巧: 控制台输入时Shift+Enter能够中途代码 ...

  2. 转:utf8汉字编码16进制对照

    http://blog.chinaunix.net/uid-25544300-id-3281847.html GB    Unicode  UTF-8     Chinese Character Co ...

  3. 11.MATLAB基本编程

    概述: 1 脚本M文件 clear all; %设置精度 format long; %定义变量 n= s= %循环 :n s=s+/^i; end s format short; 2 函数M文件 fu ...

  4. 19. Remove Nth Node From End of List[M]删除链表的倒数第N个节点

    题目 Given a linked list, remove the n-th node from the end of list and return its head. *Example: Giv ...

  5. Spark RDD概念学习系列之典型RDD的特征

    不多说,直接上干货!

  6. SQL Server 计算汉字笔画函数

    create function [dbo].[fun_getbh](@char nchar(2)) returns int as begin return( case when unicode(@ch ...

  7. 备份IIS

    备份IIS,这里实质指的是备份IIS配置.如果要备份IIS部署的网站的话,直接Copy目录就行了. 备份IIS配置其实和备份系统含义差不多,为了方便系统或者IIS出现故障后能够及时恢复到某节点上,所以 ...

  8. 使用 async/ await 进行 异步 编程

    一.异步函数 异步函数概念. 通常 是 指用 async 修饰 符 声明 的, 可 包含 await 表达式 的 方法 或 匿名 函数 1. 从 语言 的 视角 来看, 这些 await 表达式 正是 ...

  9. <Android Framework 之路>Android5.1 Camera Framework(四)——框架总结

    前言 从之前的几篇文件,可以基本弄清楚 Camera从APK,经过framework的衔接,与HAL层进行交互,最终通过驱动完成Camera的一些动作. Camera层次分析 APP层 Framewo ...

  10. solarwinds之配置系统管理(System manager)

    配置windows的 1.  打开System Manager   2.  点击new新加一个接口   3.  选择要监控的资源   4.  确认好自己要监控的资源后如下   5.  这里以监控内存使 ...