Apache Zeppelin系列教程第十篇——SQL Debug In Zeppelin

简介: Apache Zeppelin系列教程第十篇——SQL Debug In Zeppelin

SQL Debug介绍

首先介绍下什么是SQL Debug?

但是经常有这样一个需求,一大段sql 跑出来之后,发现不是自己想要的结果?比如:

demo 1:
select id,name from (
select id,name from table1
union all
select id,name from table2
union all
select id,name from table3
union all
select id,name from table4
)t group by id,name
demo 2:
select a.id,a.name,a.class from (select id,name from table1 where id>=10) a left join (select name,class from table2 where name is not null)
 b on a.name=b.name;

比如说:

demo 1 中的sql 出来这样的结果数据

但是其中id为100的这条数据从业务逻辑上来看应该是被过滤掉的,但是实际却出来了,也就是代码实际运行结果和我们预期想的不一样

其实和c语言开发和java 开发类似,就是预期结果和代码实际结果不一致,一般在java开发或者c语言开发中,我们是通过打日志(print、log.debug )或者使用idea打断点进调试模式进行调试代码,一步一步查看中间结果,也称之为debug过程。

那么因此想到sql 实际运行结果和预期不符的时候能不能进行debug 调试呢?

大部分数据开发者遇到这个问题,都是把sql 进行拆分,比如说demo 1 的sql拆分如下4个sql,分别对每个sql 进行运行判断100这个结果到底是哪个表产出的。

select id,name from table1 where id='100'
select id,name from table2 where id='100'
select id,name from table3 where id='100'
select id,name from table4 where id='100'

或者

select * from (
select id,name,flag from (
select id,name,'1' as flag from table1
union all
select id,name,'2' as flag from table2
union all
select id,name,'3' as flag from table3
union all
select id,name,'4' as flag from table4
)t group by id,name,flag )t1 where id='100'

那有没有一种方法,也能做到像和java或者c语言一样进行调试中间结果呢,也就是idea debug或者通过打印日志的方式?因此称呼sql 调试的过程为sql debug。

java 或者c 语言 开启debug 模式,需要打印日志或者配合idea 进行debug,本文先讲述怎么通过打印日志进行SQL Debug

SQL Debug处理流程

(1)开启debug 模式

(2)拆分sql

(3)输出中间结果

(4)人工判断中间结果是否正确定位原因

(5)重复2-4过程直到找到最终结果结束

select u,
       max(tm),
       p1
from
  (
   select device_id as u,unix_timestamp(dt,'yyyy-MM-dd')*1000 as tm,p1
        from test.table1
        where dt='2023-04-09' and length(trim(device_id))>0
        union ALL
        select device_id as u,unix_timestamp(dt,'yyyy-MM-dd')*1000 as tm,p1
        from test.table2
        where dt='2023-04-09' and length(trim(device_id))>0  
    union all 
     select device_id as u,unix_timestamp(dt,'yyyy-MM-dd')*1000 as tm,p1
     from test.table3
    where dt='2023-04-09' and length(trim(device_id))>0
  ) a
GROUP BY u,
         p1

(1)将这样一段sql 进行转换成语法树(如下图),这样就完成了sql解析和拆分(实际上更复杂的sql 也可进行快速拆分)

(2)将拆分出来的sql进行批量建表

(3)实际分析问题的时候,可以直接查询建的中间表数据

(4)分析完成之后需要自动删除建的中间表数据

SQL Debug In Apache Zeppelin

在jdbc intercepter 里面根据输入的sql 选择 debug 功能

上述是点击debug 按钮后产生的结果,能看到对应每一个拆分的sql 都会被创建成一个表,对此,我们只需要对每个单独表进行查询去排查问题即可

select * from test_zeppelin.tmp_zeppelin_paragraph_1683297437359_1950110405_1 where name='xiaohe'

详细的pr 和设计文档参考:https://github.com/apache/zeppelin/pull/4598

sql-debug 核心代码:https://github.com/zhugezifang/sql-debug


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
1月前
|
SQL Java 数据库连接
Apache Doris 支持 Arrow Flight SQL 协议,数据传输效率实现百倍飞跃
近年来,随着数据科学、数据湖分析等场景的兴起,对数据读取和传输速度提出更高的要求。而 JDBC/ODBC 作为与数据库交互的主流标准,在应对大规模数据读取和传输时显得力不从心,无法满足高性能、低延迟等数据处理需求。为提供更高效的数据传输方案,Apache Doris 在 2.1 版本中基于 Arrow Flight SQL 协议实现了高速数据传输链路,使得数据传输性能实现百倍飞跃。
|
4月前
|
算法 Java Go
Apache Zeppelin 番外篇——参与开源的得与失
Apache Zeppelin 番外篇——参与开源的得与失
39 0
|
6天前
|
SQL 数据管理 关系型数据库
如何在 Windows 上安装 SQL Server,保姆级教程来了!
在Windows上安装SQL Server的详细步骤包括:从官方下载安装程序(如Developer版),选择自定义安装,指定安装位置(非C盘),接受许可条款,选中Microsoft更新,忽略警告,取消“适用于SQL Server的Azure”选项,仅勾选必要功能(不包括Analysis Services)并更改实例目录至非C盘,选择默认实例和Windows身份验证模式,添加当前用户,最后点击安装并等待完成。安装成功后关闭窗口。后续文章将介绍SSMS的安装。
9 0
|
1月前
|
Shell Linux Apache
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 apachectl命令 使用教程
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 apachectl命令 使用教程
163 1
|
1月前
|
SQL 数据可视化 Apache
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
阿里云数据库 SelectDB 内核 Doris 的 SQL 方言转换工具, Doris SQL Convertor 致力于提供高效、稳定的 SQL 迁移解决方案,满足用户多样化的业务需求。兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移。
阿里云数据库内核 Apache Doris 兼容 Presto、Trino、ClickHouse、Hive 等近十种 SQL 方言,助力业务平滑迁移
|
1月前
|
SQL 分布式计算 Apache
生态 | Apache Hudi集成Apache Zeppelin
生态 | Apache Hudi集成Apache Zeppelin
33 0
|
1月前
|
SQL 存储 Apache
在 Apache Flink SQL 中,并没有内置的 GROUP_CONCAT 函数
【2月更文挑战第16天】在 Apache Flink SQL 中,并没有内置的 GROUP_CONCAT 函数
200 2
|
2月前
|
SQL 网络协议 Java
【Java+SQL Server】前后端连接小白教程
【Java+SQL Server】前后端连接小白教程
25 0
|
4月前
|
SQL 关系型数据库 MySQL
Apache StreamPark系列教程第二篇——项目打包和开发
Apache StreamPark系列教程第二篇——项目打包和开发
83 0
|
4月前
|
SQL Apache 流计算
Apache StreamPark系列教程第一篇——安装和体验
Apache StreamPark系列教程第一篇——安装和体验
209 0

热门文章

最新文章

推荐镜像

更多