0

图片有人可以帮我实现以下我目前陷入困境的2个要求:

  1. 仅当作业的状态为“进行中”且大于 SLA_TMLINE 时,我才需要在几分钟内计算和填充字段“DURATION_CROSSED_AFTER_SLA”的帮助。如果 SLA_TMLINE 为“NA”,则字段也将为“NA”。SLA_TMLINE 值仅在时间(EST)中给出,计算时将自动假定当前日期,例如:对于 JOB_ID 1373,SLA_TMLINE 给出为 - 06:00 AM,这意味着 '8/22/2020 06:00: 00'。
  2. 此外,如果作业的状态为“进行中”,并且如果当前时间戳(0)> SLA_TMLINE 为当天+“1”小时,那么我们需要将作业的状态(B.STATUS)显示为“长时间运行”,而不是'进行中'。

基本上,我们将有以下工作状态:

WAITING
IN PROGRESS
LONG RUNNING
COMPLETE
FAILED

从以上 5 个工作状态中,表中没有“LONG RUNNING”状态,但我们将根据第 5 点得出它。2 以上。

Query: SEL A.JOB_ID,A.SUBJECT_AREA,A.UC4JOB AS UC4_JOB,A."WORKFLOW/JOB" AS 
 INFA_WORKFLOW,B.STATUS,A.SCH_STRT_TIME,B.START_TIME,A.SLA_TMLINE,
 '??' AS DURATION_CROSSED_AFTER_SLA
 FROM NDW_PRCS_CNTRL_VIEWS.NDW_JOB_DETAIL A JOIN 
 NDW_PRCS_CNTRL_VIEWS.NDW_JOB_RUN_STATUS B 
 ON A.REF_ID = B.REF_ID 
 AND A.JOB_ID = B.JOB_ID 
 WHERE A.REF_ID IN (4171,977,997,1428,755,898,145) 
 AND B.DATA_DATE = DATE - 1;

            
Current Output we are getting:
JOB_ID  SUBJECT_AREA    UC4_JOB INFA_WORKFLOW   STATUS  SCH_STRT_TIME   START_TIME  SLA_TMLINE  DURATION_CROSSED_AFTER_SLA
1,373   Subs by Speed   NDW.EPC.SUBS_BY_SPEED_DATA_LOAD wf_EPC_SUBS_BY_SPEED    COMPLETE    6:00 AM 8/22/2020 06:01:24  6:00 AM ??
343 CSG Run 2   NDW.P1P2MIG.NDW_CCS_DATA_EXTRACT.WF_CSG_EXTRACT_EQP_MERGE_SA    wf_CSG_EXTRACT_EQP_MERGE_SA COMPLETE    23:00 PM    8/21/2020 23:00:24  23:04 PM    ??
906 Billing NDW.P2.IN.WF_ROSETTA_SEMANTIC_ACCOUNT_LEDGER_FACT   wf_ACCOUNT_LEDGER_FACT_INC  COMPLETE    04:00 AM    8/22/2020 02:39:35  06:00 AM    ??
539 iControl    NDW.XHBU.SPRINT1.INFA_WF_DEPENDENT.ICONTROL_STG_JRNL_LOAD   wf_XH_BU_ICONTROL_dly_inc   COMPLETE    05:00 AM    8/22/2020 05:01:25  NA  ??
668 XH BB/Cell Offline  NDW.XHBU.SPRINT2.INFA_WF_DEPENDENT.BB_CELL_OFFLINE_DLY  wf_XH_BB_CELL_OFFLINE_DLY   COMPLETE    06:00 AM    8/22/2020 07:19:49  NA  ??
2,042   NDW_XHBU    NDW_XH.JOBS.SPRINT2.INFA_WF_DEPENDENT.XH_EQUIPMENT_ORDER_DLY    Wf_XH_EQUIPEMENT_ORDER_ACT_DLY  WAITING NA  ?   NA  ??
4

1 回答 1

0

棘手的部分是存储为 VarChar 的时间和个位数的小时数。可以使用 RegEx 或 LPAD 添加缺少的前导零:

cast(lpad(nullif(SLA_TMLINE, 'NA'), 8, '0') as time(0) format 'hh:miBT')

当您将其投射到时间戳时,它默认为今天:

cast(cast(lpad(nullif(SLA_TMLINE, 'NA'), 8, '0') as time(0) format 'hh:miBT') as timestamp(0)) as SLA_TS

然后是

case
  when status = 'IN PROGRESS' 
   and SLA_TS < current_timestamp - interval '1' hour
  then 'LONG RUNNING'
  else status
end

case
  when status = 'IN PROGRESS' 
   and SLA_TS < current_timestamp
  then (current_timestamp(0) - SLA_TS minute(4))
end
于 2020-08-22T17:05:38.040 回答