select t2.input_table, t1.inst_id, replace(replace(t1.output_tables,"[",""),"]","") as output_table from information_schema.tasks_history t1 left join ( select ---去除表开始和结尾的[ ] trans_array(1,",",inst_id, replace(replace(input_tables,"[",""),"]","")) as (inst_id,input_table) from information_schema.tasks_history where ds = 20190902 )t2 on t1.inst_id = t2.inst_id where (replace(replace(t1.output_tables,"[",""),"]","")) <> "" order by t2.input_table limit 1000;


CREATE TABLE IF NOT EXISTS dim_meta_tasks_history_a ( stat_date STRING COMMENT '统计日期', project_name STRING COMMENT '项目名称', task_id STRING COMMENT '作业ID', start_time STRING COMMENT '开始时间', end_time STRING COMMENT '结束时间', input_table STRING COMMENT '输入表', output_table STRING COMMENT '输出表', etl_date STRING COMMENT 'ETL运行时间' );
SELECT
'${yesterday}' AS stat_date
,'project_name' AS project_name
,a.inst_id AS task_id
,start_time AS start_time
,end_time AS end_time
,a.input_table AS input_table
,a.output_table AS output_table
,GETDATE() AS etl_date
FROM (
SELECT
t2.input_table
,t1.inst_id
,replace(replace(t1.input_tables,"[",""),"]","") AS output_table
,start_time
,end_time
FROM (
SELECT
*
,ROW_NUMBER() OVER(PARTITION BY output_tables ORDER BY end_time DESC) AS rows
FROM information_schema.tasks_history
WHERE operation_text LIKE 'INSERT OVERWRITE TABLE%'
AND (
start_time >= TO_DATE('${yesterday}','yyyy-mm-dd')
and
end_time <= DATEADD(TO_DATE('${yesterday}','yyyy-mm-dd'),8,'hh')
)
AND(replace(replace(output_tables,"[",""),"]",""))<>""
AND ds = CONCAT(SUBSTR('${yesterday}',1,4),SUBSTR('${yesterday}',6,2),SUBSTR('${yesterday}',9,2))
)t1
LEFT JOIN(
SELECT TRANS_ARRAY(1,",",inst_id,replace(replace(input_tables,"[",""),"]","")) AS (inst_id,input_table)
FROM information_schema.tasks_history
WHERE ds = CONCAT(SUBSTR('${yesterday}',1,4),SUBSTR('${yesterday}',6,2),SUBSTR('${yesterday}',9,2))
)t2
ON t1.inst_id = t2.inst_id
where t1.rows = 1
) a
WHERE a.input_table is not null
;



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69947441/viewspace-2669990/ ,如需转载,请注明出处,否则将追究法律责任。