1.概述

转载:【数据仓库】元数据血缘分析

现在数据仓库基本上采用Hadoop平台了,那么数据仓库里面元数据的血缘分析的思路有哪些呢

基本上有下面这两种思路:

1、解析hql脚本,通过正则表达式去匹配每一行字符串

2、采用Hadoop自带的语法分析类解析

这里比较建议采用第二种,比较直接简单,因为第一种方式比较复杂,需要考虑场景比较多,容易出现遗漏

Hadoop 自带的类 org.apache.hadoop.hive.ql.tools.LineageInfo

将hql语句通过解析语法tree,获取hive表的源表和目标表,达到血缘分析的目的

但是这个类有一点缺陷就是对于create table xx as 这种hql语句无法解析

我们稍加修改代码就可以解决了

package com.neo.datamanager;import org.apache.hadoop.hive.ql.lib.*;
import org.apache.hadoop.hive.ql.parse.*;import java.io.IOException;
import java.util.*;public class HiveLineageInfo implements NodeProcessor {//    private static final Logger logger = LoggerFactory.getLogger(HiveLineageInfo.class);/*** Stores input tables in sql.*/TreeSet inputTableList = new TreeSet();/*** Stores output tables in sql.*/TreeSet OutputTableList = new TreeSet();/*** @return java.util.TreeSet*/public TreeSet getInputTableList() {return inputTableList;}/*** @return java.util.TreeSet*/public TreeSet getOutputTableList() {return OutputTableList;}/*** Implements the process method for the NodeProcessor interface.*/public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx,Object... nodeOutputs) throws SemanticException {ASTNode pt = (ASTNode) nd;switch (pt.getToken().getType()) {case HiveParser.TOK_CREATETABLE:OutputTableList.add(BaseSemanticAnalyzer.getUnescapedName((ASTNode) pt.getChild(0)));break;case HiveParser.TOK_TAB:OutputTableList.add(BaseSemanticAnalyzer.getUnescapedName((ASTNode) pt.getChild(0)));break;case HiveParser.TOK_TABREF:ASTNode tabTree = (ASTNode) pt.getChild(0);String table_name = (tabTree.getChildCount() == 1) ?BaseSemanticAnalyzer.getUnescapedName((ASTNode) tabTree.getChild(0)) :BaseSemanticAnalyzer.getUnescapedName((ASTNode) tabTree.getChild(0)) + "." + tabTree.getChild(1);inputTableList.add(table_name);break;}return null;}/*** parses given query and gets the lineage info.** @param query* @throws ParseException*/public void getLineageInfo(String query) throws ParseException,SemanticException {/** Get the AST tree*/ParseDriver pd = new ParseDriver();ASTNode tree = pd.parse(query);while ((tree.getToken() == null) && (tree.getChildCount() > 0)) {tree = (ASTNode) tree.getChild(0);}/** initialize Event Processor and dispatcher.*/inputTableList.clear();OutputTableList.clear();// create a walker which walks the tree in a DFS manner while maintaining// the operator stack. The dispatcher// generates the plan from the operator treeMap<Rule, NodeProcessor> rules = new LinkedHashMap<Rule, NodeProcessor>();// The dispatcher fires the processor corresponding to the closest matching// rule and passes the context alongDispatcher disp = new DefaultRuleDispatcher(this, rules, null);GraphWalker ogw = new DefaultGraphWalker(disp);// Create a list of topop nodesArrayList topNodes = new ArrayList();topNodes.add(tree);ogw.startWalking(topNodes, null);}public static void main(String[] args) throws IOException, ParseException, SemanticException {String query = "insert into table aa  select * from bb union all select * from cc";HiveLineageInfo lep = new HiveLineageInfo();lep.getLineageInfo(query);System.out.println("Input tables = " + lep.getInputTableList());System.out.println("Output tables = " + lep.getOutputTableList());}
}

运行之后结果如下:

【hadoop】hadoop 血缘解析相关推荐

  1. Hadoop源码解析之: TextInputFormat如何处理跨split的行

    Hadoop源码解析之: TextInputFormat如何处理跨split的行 转载于:https://blog.51cto.com/taikongren/1742425

  2. Hive SQL血缘解析

    Druid可以直接获得所有的列 http://t.csdn.cn/mO4TX 利用Hive提供的LineageLogger与Execution Hooks机制做血缘 https://blog.csdn ...

  3. Hadoop -- hadoop介绍

    Hadoop hadoop介绍 hadoop核心组件 hadoop特性优点 hadoop发展 hadoop介绍 hadoop底层是Java语言实现 是Apache软件基金会的一款开源软件 允许用户使用 ...

  4. linux如何授权HADOOP,hadoop用户权限管理

    在上一篇博文我描述了在单机linux上安装hadoop,网址:http://my.oschina.net/hetiangui/blog/142897,这里我主要描述下hadoop的用户权限管理. 上篇 ...

  5. [设计] Doris血缘解析流程

    一.背景 1.1 元数据概述 元数据是凌久中台重要功能模块,是数据治理的重要一环,元数据治理是一切数据治理的基础,主要分为元数据管理和表血缘管理: 元数据管理主要用来做数据地图.数据资产等: 血缘治理 ...

  6. Hadoop常见错误解析

    1:Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out  Answer: 程序里面需要打开多个文件,进行分析,系统一般默认数量 ...

  7. Hadoop中Partition解析

    1.解析Partition Map的结果,会通过partition分发到Reducer上,Reducer做完Reduce操作后,通过OutputFormat,进行输出,下面我们就来分析参与这个过程的类 ...

  8. Hadoop源码解析

    一.hadoop的Job 提交流程源码 流程图: 1.从我们编写的mapreduce的代码中进入job提交源码 支线一:进入connect(); 2.支线二:进入submitter.submitJob ...

  9. 超详细单机版搭建hadoop环境图文解析

    转自:http://weixiaolu.iteye.com/blog/1401931 安装过程: 一.安装Linux操作系统 二.在Ubuntu下创建hadoop用户组和用户 三.在Ubuntu下安装 ...

最新文章

  1. Ubuntu 14.04 64位上配置JDK操作步骤
  2. python【数据结构与算法】完全背包(附代码)
  3. pacman安装php的位置,PacMan 01——地图的搭建
  4. flutter AppBar
  5. MyBatis1:MyBatis入门
  6. 使用正则表达式模拟读写INI文件
  7. [vue] 有在vue中使用过echarts吗?踩过哪些坑?如何解决的?
  8. HTTP与HTTPS的安全性讨论
  9. lt;备份gt;10月12日 内核编译与日志
  10. react接收后端文件_React如何从后端获取数据并渲染到前端?
  11. Nginx启动报[10013]错误
  12. 二类查询(中兴笔试)
  13. Python自动化模拟键盘操作
  14. 微信小程序上传silk格式录音并转码为mp3
  15. 《人工智能——从小白到大神》,张亚勤院士与百度陈尚义理事长联袂推荐
  16. 推荐 :35个国内外社会科学数据网站资源汇总(附链接)
  17. 【181225】VC++控制文字横向打印和纵向打印的方向源代码
  18. 计算机的4个主要功能,计算机的四个基本功能
  19. twelveth-alien_invasion-alien_invasion.py
  20. jsp公共自行车租赁系统

热门文章

  1. 特斯拉将国产Model 3和Model Y后轮驱动版价格上调4752元
  2. 刚刚,“国民”APP微信崩了!官方致歉:已经逐步恢复
  3. 涨疯了!国产鞋被爆炒,原价1499元卖48889元,有人几天赚一辆车
  4. 华为P50首发麒麟9000L:5nm EUV工艺打造 配置有所缩减
  5. 力压腾讯!《原神》连续5个月成中国手游海外收入冠军
  6. 拼多多市值超2100亿美元 黄峥成中国第二大富豪
  7. 微信红包封面向个人开放,1元定制!
  8. 索尼PS5游戏主机炒到8000元以上:相比之下iPhone 12不值一提
  9. 富士康欲进军电动汽车市场 目标占据市场10%份额
  10. 疫情之下的“催化剂”:在线经济崛起 房产数字化变革加速