• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > 基于sparksql调用shell脚本执行SQL,sparksqlshell

基于sparksql调用shell脚本执行SQL,sparksqlshell

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含sparksql hbase,sparksql hive,sparksql udf,sparksql dataframe,sparksql教程等服务器相关知识,网友希望可以进行参考

基于sparksql调用shell脚本执行SQL,sparksqlshell


[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的端口

--conf spark.ui.port=4075 

默认为4040,会与其他正在跑的任务冲突,这里修改为4075


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

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



原来的语句是用hive -e 执行的,修改为spark后速度大加快了。原来为15min,提升速度后为 45s.




版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 基于sparksql调用shell脚本执行SQL,sparksqlshell

相关文章

  • pig里面没有if:不能判断一个条件后决定一个执行步骤,pigif
  • Flume 开发者指南V1.5.2,flume开发者v1.5.2
  • 详说大数据计算的可类化Classable,类化classable
  • Hadoop实战 Hadoop Pipes运行C++程序问题解决,hadooppipes
  • 《转》OpenStack Live Migration,《转》openstack
  • NOSQL(四)放宽一致性约束,nosql一致性
  • Hive 和普通关系数据库的异同,hive关系数据库
  • Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect,sqlitealtertable
  • 相似度计算map-reduce实现思路,计算map-reduce思路
  • hadoop 2.6.0 安装过程,hadoop2.6.0

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • 漫谈分布式系统:三种通信范型
    • Deep learning by Andrew Ng,learningandrew
    • HDP 2.2.4 Hue Oozie Editor生成workflow.xml的几点问题,oozieworkflow.xml
    • 如何动态地给vSphere虚拟机模板注入信息,vsphere虚拟机
    • 关于hadoop程序优化的几点建议,hadoop几点建议
    • 【hadoop】 3002-mapreduce程序统计单词个数示例,hadoopmapreduce
    • hbase遇到问题及解决方法,hbase遇到问题
    • Hadoop学习总结,hadoop总结
    • kernel interrupt,interrupt
    • A Note on Distributed Computing,anoteondialectic

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有