当前位置: 首页 > news >正文

二百四十五、海豚调度器——用DolphinScheduler调度执行复杂的HiveSQL(HQL包含多种海豚无法正确识别的符号)

一、目的

在Hive中完成复杂JSON,既有对象还有数组而且数组中包含数组的解析后,原本以为没啥问题了,结果在DolphinScheduler中调度又出现了大问题,搞了一天、试了很多种方法、死了无数脑细胞,才解决了这个问题!

二、HiveSQL

insert  overwrite  table  hurys_dc_dwd.dwd_json_statistics partition(day)
selectt1.device_no,source_device_type,sn,model,create_time,cycle,get_json_object(coil_list,'$.laneNo')  lane_no,get_json_object(coil_list,'$.laneType')           lane_type,section_no,get_json_object(coil_list,'$.coilNo')             coil_no,get_json_object(coil_list,'$.volumeSum')          volume_sum,get_json_object(coil_list,'$.volumePerson')       volume_person,get_json_object(coil_list,'$.volumeCarNon')       volume_car_non,get_json_object(coil_list,'$.volumeCarSmall')     volume_car_small,get_json_object(coil_list,'$.volumeCarMiddle')    volume_car_middle,get_json_object(coil_list,'$.volumeCarBig')       volume_car_big,get_json_object(coil_list,'$.speedAvg')           speed_avg,get_json_object(coil_list,'$.speed85')            speed_85,get_json_object(coil_list,'$.timeOccupancy')      time_occupancy,get_json_object(coil_list,'$.averageHeadway')     average_headway,get_json_object(coil_list,'$.averageGap')         average_gap,substr(create_time,1,10) day
from (selectget_json_object(statistics_json,'$.deviceNo')          device_no,get_json_object(statistics_json,'$.sourceDeviceType')  source_device_type,get_json_object(statistics_json,'$.sn')                sn,get_json_object(statistics_json,'$.model')             model,get_json_object(statistics_json,'$.createTime')        create_time ,get_json_object(statistics_json,'$.data.cycle')        cycle,
       get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.sectionNo') section_no,section_list
from hurys_dc_ods.ods_statistics
lateral view explode(split(replace(replace(replace(get_json_object(statistics_json,'$.data.sectionList'),'[',''),']',''),'},{"sectionNo"','}|{"sectionNo"'),"\\|")) tf as section_listwhere day='2024-07-18' --  date_sub(current_date(), 1)   -- '2024-07-18' --) as t1
lateral view explode(split(replace(replace(replace(get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.coilList'),'[',''),']',''),'},','}|'),"\\|")) tf1 as coil_listwhere substr(create_time,1,10) =  '2024-07-18' --date_sub(current_date(), 1)   --'2024-07-17'
;

三、原先海豚任务的调度方式

在shell脚本里添加HiveSQL语句

#! /bin/bash
source /etc/profile

nowdate=`date --date='0 days ago' "+%Y%m%d"`
yesdate=`date -d yesterday +%Y-%m-%d`

hive -e "
use hurys_dc_dwd;

set hive.vectorized.execution.enabled=false;

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=1000;
set hive.exec.max.dynamic.partitions=1500;


with t1 as(
select
       get_json_object(statistics_json,'$.deviceNo')          device_no,
       get_json_object(statistics_json,'$.sourceDeviceType')  source_device_type,
       get_json_object(statistics_json,'$.sn')                sn,
       get_json_object(statistics_json,'$.model')             model,
       get_json_object(statistics_json,'$.createTime')        create_time ,
       get_json_object(statistics_json,'$.data.cycle')        cycle,
       get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.sectionNo') section_no,
       section_list
from hurys_dc_ods.ods_statistics
lateral view explode(split(replace(replace(replace(get_json_object(statistics_json,'$.data.sectionList'),'[',''),']',''),'},{"sectionNo"','}|{"sectionNo"'),"\\\\|")) tf as section_list
    where day='$yesdate'
)
insert  overwrite  table  hurys_dc_dwd.dwd_json_statistics partition(day)
select
        t1.device_no,
        source_device_type,
        sn,
        model,
        substr(create_time,1,19)                          create_time ,
        cycle,
        get_json_object(coil_list,'$.laneNo')  lane_no,
        get_json_object(coil_list,'$.laneType')           lane_type,
        section_no,
        get_json_object(coil_list,'$.coilNo')             coil_no,
        get_json_object(coil_list,'$.volumeSum')          volume_sum,
        get_json_object(coil_list,'$.volumePerson')       volume_person,
        get_json_object(coil_list,'$.volumeCarNon')       volume_car_non,
        get_json_object(coil_list,'$.volumeCarSmall')     volume_car_small,
        get_json_object(coil_list,'$.volumeCarMiddle')    volume_car_middle,
        get_json_object(coil_list,'$.volumeCarBig')       volume_car_big,
        get_json_object(coil_list,'$.speedAvg')           speed_avg,
        get_json_object(coil_list,'$.speed85')            speed_85,
        get_json_object(coil_list,'$.timeOccupancy')      time_occupancy,
        get_json_object(coil_list,'$.averageHeadway')     average_headway,
        get_json_object(coil_list,'$.averageGap')         average_gap,
        substr(create_time,1,10) day
from t1
lateral view explode(split(replace(replace(replace(get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.coilList'),'[',''),']',''),'},','}|'),"\\\\|")) tf1 as coil_list
    where  substr(create_time,1,10) ='$yesdate'
"

四、原先方式报错日志

海豚无法正确识别HiveSQL里解析复杂JSON的多种符号

五、解决方式

把HiveSQL放在一个SQL文件里,然后在脚本里是执行Hive的sourceSQL文件

1 SQL文件

--使用hurys_dc_ods数据库
use hurys_dc_dwd;

--hive调优(必须先执行调优语句,否则部分复杂SQL运行会有问题)
set hive.vectorized.execution.enabled=false;
--开启动态分区功能(默认 true,开启)
set hive.exec.dynamic.partition=true;
--设置为非严格模式   nonstrict 模式表示允许所有的分区字段都可以使用动态分区
set hive.exec.dynamic.partition.mode=nonstrict;
--在每个执行 MR 的节点上,最大可以创建多少个动态分区
set hive.exec.max.dynamic.partitions.pernode=1000;
--在所有执行 MR 的节点上,最大一共可以创建多少个动态分区。默认 1000
set hive.exec.max.dynamic.partitions=1500;


insert  overwrite  table  hurys_dc_dwd.dwd_json_statistics partition(day)
select
        t1.device_no,
        source_device_type,
        sn,
        model,
        create_time,
        cycle,
        get_json_object(coil_list,'$.laneNo')  lane_no,
        get_json_object(coil_list,'$.laneType')           lane_type,
        section_no,
        get_json_object(coil_list,'$.coilNo')             coil_no,
        get_json_object(coil_list,'$.volumeSum')          volume_sum,
        get_json_object(coil_list,'$.volumePerson')       volume_person,
        get_json_object(coil_list,'$.volumeCarNon')       volume_car_non,
        get_json_object(coil_list,'$.volumeCarSmall')     volume_car_small,
        get_json_object(coil_list,'$.volumeCarMiddle')    volume_car_middle,
        get_json_object(coil_list,'$.volumeCarBig')       volume_car_big,
        get_json_object(coil_list,'$.speedAvg')           speed_avg,
        get_json_object(coil_list,'$.speed85')            speed_85,
        get_json_object(coil_list,'$.timeOccupancy')      time_occupancy,
        get_json_object(coil_list,'$.averageHeadway')     average_headway,
        get_json_object(coil_list,'$.averageGap')         average_gap,
        substr(create_time,1,10) day
from (select
       get_json_object(statistics_json,'$.deviceNo')          device_no,
       get_json_object(statistics_json,'$.sourceDeviceType')  source_device_type,
       get_json_object(statistics_json,'$.sn')                sn,
       get_json_object(statistics_json,'$.model')             model,
       get_json_object(statistics_json,'$.createTime')        create_time ,
       get_json_object(statistics_json,'$.data.cycle')        cycle,
       get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.sectionNo') section_no,
       section_list
from hurys_dc_ods.ods_statistics
lateral view explode(split(replace(replace(replace(get_json_object(statistics_json,'$.data.sectionList'),'[',''),']',''),'},{"sectionNo"','}|{"sectionNo"'),"\\|")) tf as section_list
    where day= date_sub(current_date(), 1)
    ) as t1
lateral view explode(split(replace(replace(replace(get_json_object(replace(replace(section_list,':{',':[{'),'}}','}]}'),'$.coilList'),'[',''),']',''),'},','}|'),"\\|")) tf1 as coil_list
where substr(create_time,1,10) =  date_sub(current_date(), 1)
;

2 海豚任务执行脚本

#! /bin/bash
source /etc/profile

nowdate=`date --date='0 days ago' "+%Y-%m-%d"`
yesdate=`date -d yesterday +%Y-%m-%d`

hive -e "
source   dwd_json_statistics.sql

3 执行任务,验证结果

终于解决了,以后碰到类似调度器识别不了SQL里符号的问题,实在不行就用这个方法,把SQL放在SQL文件里,然后在脚本里执行这个SQL文件就行了,这样就能规避这类问题了

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Python药物副作用生物图分析算法和矩阵降维算法
  • 2022.11.17 阿里钉钉数据开发岗位一面
  • PyEcharts知识点详解(每张图都有!)(巨详细!!)
  • BGP路由反射器
  • Apache Doris + Paimon 快速搭建指南|Lakehouse 使用手册(二)
  • mysql字符类型字段设置默认值为当前时间
  • react配置代理的3中方法
  • 9. 机器学习汇总(数据、模型、流程、心血管疾病预测)
  • 编程类精品GPTs
  • 05 循环神经网络
  • Webpack 5 Tree Shaking与Module Federation
  • 【管控业财一体化】
  • k8s核心知识总结
  • 构造函数的详解和new操作符
  • 项目架构知识点总结
  • [译]CSS 居中(Center)方法大合集
  • 【剑指offer】让抽象问题具体化
  • AzureCon上微软宣布了哪些容器相关的重磅消息
  • Docker入门(二) - Dockerfile
  • OSS Web直传 (文件图片)
  • Vue组件定义
  • 回流、重绘及其优化
  • 基于MaxCompute打造轻盈的人人车移动端数据平台
  • 力扣(LeetCode)56
  • 排序(1):冒泡排序
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 微信开放平台全网发布【失败】的几点排查方法
  • 一个普通的 5 年iOS开发者的自我总结,以及5年开发经历和感想!
  • 译自由幺半群
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • ​人工智能书单(数学基础篇)
  • ###STL(标准模板库)
  • #565. 查找之大编号
  • #include
  • #Linux杂记--将Python3的源码编译为.so文件方法与Linux环境下的交叉编译方法
  • $(this) 和 this 关键字在 jQuery 中有何不同?
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (31)对象的克隆
  • (C语言)strcpy与strcpy详解,与模拟实现
  • (ibm)Java 语言的 XPath API
  • (STM32笔记)九、RCC时钟树与时钟 第二部分
  • (TOJ2804)Even? Odd?
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (不用互三)AI绘画工具应该如何选择
  • (二)测试工具
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (十六)一篇文章学会Java的常用API
  • (微服务实战)预付卡平台支付交易系统卡充值业务流程设计
  • (转)fock函数详解
  • (转)setTimeout 和 setInterval 的区别
  • (转)Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一
  • (转载)CentOS查看系统信息|CentOS查看命令
  • **《Linux/Unix系统编程手册》读书笔记24章**
  • .gitignore文件_Git:.gitignore
  • .JPG图片,各种压缩率下的文件尺寸