<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.purui.prims.headless.server.persistence.mapper.MetricLineageCustomDOMapper">
    <resultMap id="BaseResultMap"
               type="com.purui.prims.headless.server.persistence.dataobject.MetricLineageDO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="metric_id" jdbcType="BIGINT" property="metricId"/>
        <result column="metric_name" jdbcType="VARCHAR" property="metricName"/>
        <result column="metric_type" jdbcType="VARCHAR" property="metricType"/>
        <result column="source_metric_id" jdbcType="BIGINT" property="sourceMetricId"/>
        <result column="aggregate_type" jdbcType="VARCHAR" property="aggregateType"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
    </resultMap>

    <select id="getMetricLineage" resultMap="BaseResultMap">
        SELECT
            m2.id,
            m2.metric_type AS metric_type,
            m2.metric_name AS metric_name,
            m2.metric_id as metric_id,
            m2.aggregate_type AS aggregate_type,
            m2.description AS description
        FROM
            pr_metric_lineage m1
                LEFT JOIN
            pr_metric_lineage m2 ON m1.source_metric_id = m2.metric_id
        <where>
            <if test="metricId != null">
                m1.metric_id = #{metricId} and  m2.id is not null
            </if>
        </where>
    </select>

</mapper>
