ToB企服应用市场:ToB评测及商务社交产业平台

标题: Hive执行计划之hive依赖及权限查询和常见使用场景 [打印本页]

作者: 没腿的鸟    时间: 2023-6-8 08:14
标题: Hive执行计划之hive依赖及权限查询和常见使用场景
目录

概述

Hive查看执行计划的命令中还有两个不怎么常用但很重要的命令,接下来详细介绍一下。
有一个问题:如何在hiveSQL执行之前就探查到这段逻辑的血缘依赖关系?
hive血缘是很多生产级数仓必须要提供的功能,大多数解决方案都是使用hive hooks的方法通过SQL执行后解析得到hive表的依赖关系
这个方案能细粒度到字段级依赖,属于很完善的一个解决方案,但有很多场景我们需要在SQL执行之前就得到依赖关系,那么如何解决的呢?
1.explain dependency的查询与使用

explain dependency 提供了这样的一个解决方案,它可以查询一段SQL需要的数据来源,以JSON的形式展现结果数据。里面主要包含两部分内容:
可以通过以下例子来进行比对,其中例1是查询非分区普通表SQL的explain dependency,例2是查询分区表SQL的explain dependency。
例1 使用explain dependency查看SQL非分区普通表。
  1. explain dependency
  2. -- 统计年龄小于30岁各个年龄里,昵称里带“小”的人数
  3. select age,count(0) as num from temp.user_info_all_no
  4. where age < 30 and nick like '%小%'
  5. group by age;
复制代码
输出结果内容:
  1. {"input_tables":[{"tablename":"temp@user_info_all_no","tabletype":"MANAGED_TABLE"}],"input_partitions":[]}
复制代码
例2 使用explain dependency查看SQL查询分区表。
  1. explain dependency
  2. -- 统计年龄小于30岁各个年龄里,昵称里带“小”的人数,其中ymd字段为分区字段
  3. select age,count(0) as num from temp.user_info_all where ymd >= '20230501'
  4. and age < 30 and nick like '%小%'
  5. group by age;
复制代码
输出结果内容:
  1. {"input_tables":[{"tablename":"temp@user_info_all","tabletype":"MANAGED_TABLE"}],"input_partitions":[{"partitionName":"temp@user_info_all@ymd=20230501"},{"partitionName":"temp@user_info_all@ymd=20230502"},{"partitionName":"temp@user_info_all@ymd=20230503"},{"partitionName":"temp@user_info_all@ymd=20230504"},{"partitionName":"temp@user_info_all@ymd=20230505"},{"partitionName":"temp@user_info_all@ymd=20230529"}]}
复制代码
2.借助explain dependency解决一些常见问题

explain dependency的使用场景有以下几个:
场景一,快速排除。快速排除因为读不到相应分区的数据而导致任务数据输出异常。例如,在一个以天为分区的任务中,上游任务因为生产过程不可控因素出现异常或者空跑,导致下游任务引发异常。通过这种方式,可以快速查看SQL读取的分区是否出现异常。
场景二,理清表的输入,帮助理解程序的运行,特别是有助于理解有多重子查询,多表连接的依赖输入。
场景三,提前通过解析hiveSQL脚本进行血缘依赖解析,用于一些定制化数据平台工具开发中的血缘构建。
explain dependency的使用能帮助开发者解决哪些问题呢?
2.1.识别看似等价的SQL代码实际上是不等价的:

对于接触SQL不久的程序员来说,很多人容易将

select * from a left join b on a.no=b.no and a.f>1 and a.f1 and a.f= '20230501' and a.ymd = '20230501' and a.ymd = '20230501' and b.ymd = '20230501' and b.ymd = '20230501' and a.ymd = '20230501' and b.ymd = '20230501' and a.ymd = '20230501' and ymd = '20230501' and ymd = '20230501' and ymd = '20230501' and b.ymd = '20230501' and ymd = '20230501' and ymd = '20230501' and ymd = '20230501' and a.ymd




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4