使用LineageInfo分析Hive HQL(HSQL)获取血缘关系

Hive源码的一个类可以用来分析Hive表的关系:
org.apache.hadoop.hive.ql.tools.LineageInfo

#/bin/bash
java -cp .:/usr/hadoop/hive/lib/*:/user/hadoop/exec/lib/*  org.apache.hadoop.hive.ql.tools.LineageInfo "$1"

如上在classpath中加入各种依赖的jar包,然后咱们就开始执行:

hadoop@ms1$ ./LItest.sh "insert into table1 (id,name) select id,name from table2"
InputTable=table2
OutputTable=table1

hadoop@ms1$ ./LItest.sh "select * from table1 join (select * from table2 where id like '%superX%') temp on table1.id = temp.id" 
InputTable=table1
InputTable=table2

不过Create table as select 语句不能正常分析出血缘关系:

hadoop@ms1$ ./LItest.sh "create table table1 as select * from table2"
InputTable=table2

 

你可能感兴趣的:(技术,hive,血缘分析,HQL,sql)