大数据

hive字段级别血缘实现

2021-02-18  本文已影响0人  烂泥_119c

背## 背景

准备工作

这个钩子类将血缘关系以日志的形式输出,为了拿到这里的血缘关系,首先我们要准备log4j的配置文件。

status = INFO
name = HiveLog4j2
packages = org.apache.hadoop.hive.ql.log

property.hive.log.level = INFO
property.hive.root.loggr = DRFA
property.hive.log.dir = .
property.hive.log.file = hive.log

appenders = console, DRFA, lineage

# 这里省略 console, DRFA的配置 都是些常规配置
# ......
loggers = LineageLogger

# lineage
logger.lineageLogger.name = org.apache.hadoop.hive.ql.hooks.lineageLogger
logger.lineageLogger.level = INFO
logger.lineageLogger.additivity = false
logger.lineageLogger.appenderRefs = lineage
appender.lineage.type = RollingRandomAccessFile
appender.lineage.fileName = ${sys:hive.log.dir}/hive_lineage.log
appender.lineage.filePattern = ${sys:hive.log.dir}/hive_lineage.log.%d{yyyy-MM-dd}
appender.lineage.layout.type = PatternLayout
appender.lineage.layout.pattern = %m%n
set hive.log4j.file=hive-log4j2.properties
set hive.exec.post.hooks=org.apache.hadoop.hive.ql.hooks.LineageLogger

运行

举例

CREATE TABLE tmp_zone_info AS
SELECT z.zoneid AS zone_id,
         z.zonename AS zone_name,
         c.cityid AS city_id,
         c.cityname AS city_name
FROM dict_zoneinfo z
LEFT JOIN dict_cityinfo c
    ON z.cityid = c.cityid
        AND z.dt='20210218'
        AND c.dt='20210218'
WHERE z.dt='20210218'
        AND c.dt='20210218';
{
    "version": "1.0",
    "user": "hadoop",
    "timestamp": 1510307578,
    "duration": 30629,
    "jobIds": [
        "job_1509088410884_16739"
    ],
    "engine": "mr",
    "database": "cxy7_dw",
    "hash": "4484378cebc5e2b0b55fb34368d861b0",
    "queryText": "CREATE TABLE tmp_zone_info AS SELECT z.zoneid AS zone_id,z.zonename AS zone_name, c.cityid AS city_id, c.cityname AS city_name FROM dict_zoneinfo z LEFT JOIN dict_cityinfo c ON z.cityid = c.cityid AND z.dt='20171109' AND c.dt='20171109' WHERE z.dt='20171109' AND c.dt='20171109'",
    "edges": [
        {
            "sources": [
                4
            ],
            "targets": [
                0
            ],
            "edgeType": "PROJECTION"
        },
        {
            "sources": [
                5
            ],
            "targets": [
                1
            ],
            "edgeType": "PROJECTION"
        },
        {
            "sources": [
                6
            ],
            "targets": [
                2
            ],
            "edgeType": "PROJECTION"
        },
        {
            "sources": [
                7
            ],
            "targets": [
                3
            ],
            "edgeType": "PROJECTION"
        },
        {
            "sources": [
                8,
                6
            ],
            "targets": [
                0,
                1,
                2,
                3
            ],
            "expression": "(z.cityid = c.cityid)",
            "edgeType": "PREDICATE"
        },
        {
            "sources": [
                9
            ],
            "targets": [
                0,
                1,
                2,
                3
            ],
            "expression": "(c.dt = '20171109')",
            "edgeType": "PREDICATE"
        },
        {
            "sources": [
                10,
                9
            ],
            "targets": [
                0,
                1,
                2,
                3
            ],
            "expression": "((z.dt = '20171109') and (c.dt = '20171109'))",
            "edgeType": "PREDICATE"
        }
    ],
    "vertices": [
        {
            "id": 0,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.tmp_zone_info.zone_id"
        },
        {
            "id": 1,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.tmp_zone_info.zone_name"
        },
        {
            "id": 2,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.tmp_zone_info.city_id"
        },
        {
            "id": 3,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.tmp_zone_info.city_name"
        },
        {
            "id": 4,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_zoneinfo.zoneid"
        },
        {
            "id": 5,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_zoneinfo.zonename"
        },
        {
            "id": 6,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_cityinfo.cityid"
        },
        {
            "id": 7,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_cityinfo.cityname"
        },
        {
            "id": 8,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_zoneinfo.cityid"
        },
        {
            "id": 9,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_cityinfo.dt"
        },
        {
            "id": 10,
            "vertexType": "COLUMN",
            "vertexId": "cxy7_dw.dict_zoneinfo.dt"
        }
    ]
}
上一篇下一篇

猜你喜欢

热点阅读