【hadoop】hadoop 血缘解析
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 血缘解析相关推荐
- Hadoop源码解析之: TextInputFormat如何处理跨split的行
Hadoop源码解析之: TextInputFormat如何处理跨split的行 转载于:https://blog.51cto.com/taikongren/1742425
- Hive SQL血缘解析
Druid可以直接获得所有的列 http://t.csdn.cn/mO4TX 利用Hive提供的LineageLogger与Execution Hooks机制做血缘 https://blog.csdn ...
- Hadoop -- hadoop介绍
Hadoop hadoop介绍 hadoop核心组件 hadoop特性优点 hadoop发展 hadoop介绍 hadoop底层是Java语言实现 是Apache软件基金会的一款开源软件 允许用户使用 ...
- linux如何授权HADOOP,hadoop用户权限管理
在上一篇博文我描述了在单机linux上安装hadoop,网址:http://my.oschina.net/hetiangui/blog/142897,这里我主要描述下hadoop的用户权限管理. 上篇 ...
- [设计] Doris血缘解析流程
一.背景 1.1 元数据概述 元数据是凌久中台重要功能模块,是数据治理的重要一环,元数据治理是一切数据治理的基础,主要分为元数据管理和表血缘管理: 元数据管理主要用来做数据地图.数据资产等: 血缘治理 ...
- Hadoop常见错误解析
1:Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out Answer: 程序里面需要打开多个文件,进行分析,系统一般默认数量 ...
- Hadoop中Partition解析
1.解析Partition Map的结果,会通过partition分发到Reducer上,Reducer做完Reduce操作后,通过OutputFormat,进行输出,下面我们就来分析参与这个过程的类 ...
- Hadoop源码解析
一.hadoop的Job 提交流程源码 流程图: 1.从我们编写的mapreduce的代码中进入job提交源码 支线一:进入connect(); 2.支线二:进入submitter.submitJob ...
- 超详细单机版搭建hadoop环境图文解析
转自:http://weixiaolu.iteye.com/blog/1401931 安装过程: 一.安装Linux操作系统 二.在Ubuntu下创建hadoop用户组和用户 三.在Ubuntu下安装 ...
最新文章
- Ubuntu 14.04 64位上配置JDK操作步骤
- python【数据结构与算法】完全背包(附代码)
- pacman安装php的位置,PacMan 01——地图的搭建
- flutter AppBar
- MyBatis1:MyBatis入门
- 使用正则表达式模拟读写INI文件
- [vue] 有在vue中使用过echarts吗?踩过哪些坑?如何解决的?
- HTTP与HTTPS的安全性讨论
- lt;备份gt;10月12日 内核编译与日志
- react接收后端文件_React如何从后端获取数据并渲染到前端?
- Nginx启动报[10013]错误
- 二类查询(中兴笔试)
- Python自动化模拟键盘操作
- 微信小程序上传silk格式录音并转码为mp3
- 《人工智能——从小白到大神》,张亚勤院士与百度陈尚义理事长联袂推荐
- 推荐 :35个国内外社会科学数据网站资源汇总(附链接)
- 【181225】VC++控制文字横向打印和纵向打印的方向源代码
- 计算机的4个主要功能,计算机的四个基本功能
- twelveth-alien_invasion-alien_invasion.py
- jsp公共自行车租赁系统
热门文章
- 特斯拉将国产Model 3和Model Y后轮驱动版价格上调4752元
- 刚刚,“国民”APP微信崩了!官方致歉:已经逐步恢复
- 涨疯了!国产鞋被爆炒,原价1499元卖48889元,有人几天赚一辆车
- 华为P50首发麒麟9000L:5nm EUV工艺打造 配置有所缩减
- 力压腾讯!《原神》连续5个月成中国手游海外收入冠军
- 拼多多市值超2100亿美元 黄峥成中国第二大富豪
- 微信红包封面向个人开放,1元定制!
- 索尼PS5游戏主机炒到8000元以上:相比之下iPhone 12不值一提
- 富士康欲进军电动汽车市场 目标占据市场10%份额
- 疫情之下的“催化剂”:在线经济崛起 房产数字化变革加速