来自WHEN函数的意外结果

huangapple go评论99阅读模式
英文:

Unexpected results from a WHEN function

问题

在我执行这个函数时(在开发过程中),它运行得很正常:我得到了排序/去重后的文件,并且已经写入了审计记录。但当我尝试从FUNCTIONMACRO中执行这个FUNCTION时,只有排序/去重后的文件被返回,审计记录没有被写入(并且需要该审计记录的FUNCTIONMACRO失败)。当我查看执行的代码时,触发器(sdd_ds文件的存在)似乎存在,因为它被返回了,但似乎没有触发auditRec操作。

"WHEN"部分是否有问题,或者我应该以不同的方式来处理这个问题?

英文:

I have a BWR that executes a FUNCTIONMACRO. Within the FUNCTIONMACRO I execute a FUNCTION that reads a dataset, sorts and deduplicates that dataset and returns the results. Before it is returned, I want to write out an audit record.

EXPORT FN_Read_Batch_File( string pFileName ) := FUNCTION
  rLayout := RECORD
     STRING field_01;
	 STRING field_02;
  END;
  
  rAudRec := RECORD
     INTEGER06 raw_ds_cnt;
	 INTEGER06 final_ds_cnt;
  END;
  
  // process the file
  ds                     := dataset(data_services.foreign_prod + pFileName, rLayout, THOR, OPT);
  INTEGER06 raw_ds_cnt   := COUNT(ds);
  
  sdd_ds                 := DEDUP( SORT( ds, field_01), field_01);
  INTEGER06 final_ds_cnt := COUNT(sdd_ds);
  
  // write the audit record
  auditRec               := output(  dataset([  {raw_ds_cnt; final_ds_cnt}
                                             ], rAudRec)
					    )
				   , ,'~temp::audit::record', compressed, overwrite, expire(1)
				  );
  RETURN  **WHEN(sdd_ds, auditRec)**;
END;

When I execute the function from within a BWR (during development), it worked just fine: I have the sorted/deduped file returned and the audit record was written. When I attempt to execute the FUNCTION from the FUNCTIONMACRO, I only get the sorted/deduped file returned - the audit record is not written (and the FUNCTIONMACRO that is expecting that audit record fails). When I look at the executed code, it seems like the trigger (the presence of the sdd_ds file) is there because it gets returned, but it doesn't seem to be triggering the auditRec action.

Am I missing something with "WHEN" or should I be doing this differently?

答案1

得分: 1

根据您的问题描述,我测试了这段代码,它可以正常工作。所以也许你应该尝试这样做,并在不起作用时扩展您的问题。

MyFunc(STRING s) := FUNCTION
  mod := RANDOM() % 7 + 2: INDEPENDENT;
  rec := RECORD
    STRING f1;
    STRING f2;
  END;
  ds := DATASET(50,
                TRANSFORM(rec,
                          SELF.f1 := 'F1-' + RANDOM() % mod,
                          SELF.f2 := s + '-' + COUNTER));	

// 写入审核记录
rAudRec := RECORD
   INTEGER06 raw_ds_cnt;
   INTEGER06 final_ds_cnt;
END;
// 处理文件
INTEGER06 raw_ds_cnt   := COUNT(ds);

sdd_ds                 := DEDUP( SORT( ds, f1), f1);
INTEGER06 final_ds_cnt := COUNT(sdd_ds);

auditRec := OUTPUT(DATASET([{raw_ds_cnt; final_ds_cnt}], rAudRec),,
                   '~temp::audit::record'+s, COMPRESSED, EXPIRE(1));  
RETURN WHEN(sdd_ds, auditRec);
END;

MyFnMac(s) := FUNCTIONMACRO
  res := MyFunc(s);
  RETURN res;
ENDMACRO;

MyFnMac(WORKUNIT);

我已经移除了OUTPUT的OVERWRITE选项,因为我传入了唯一标识符(WORKUNIT id),不需要担心它执行的次数,因为EXPIRE(1)会在一天后删除审核文件。

英文:

Based on your problem description, I tested this code, which works correctly. So perhaps you should try this and expand on your question if it doesn't work for you.

    MyFunc(STRING s) := FUNCTION
      mod := RANDOM() % 7 + 2: INDEPENDENT;
      rec := RECORD
        STRING f1;
        STRING f2;
      END;
      ds := DATASET(50,
                    TRANSFORM(rec,
                              SELF.f1 := 'F1-' + RANDOM() % mod,
                              SELF.f2 := s + '-' + COUNTER));	

  // write the audit record
  rAudRec := RECORD
     INTEGER06 raw_ds_cnt;
     INTEGER06 final_ds_cnt;
  END;
  // process the file
  INTEGER06 raw_ds_cnt   := COUNT(ds);
  
  sdd_ds                 := DEDUP( SORT( ds, f1), f1);
  INTEGER06 final_ds_cnt := COUNT(sdd_ds);
 	
  auditRec := OUTPUT(DATASET([{raw_ds_cnt; final_ds_cnt}], rAudRec),,
                     '~temp::audit::record'+s, COMPRESSED, EXPIRE(1));  
  RETURN WHEN(sdd_ds, auditRec);
END;

MyFnMac(s) := FUNCTIONMACRO
  res := MyFunc(s);
	RETURN res;
ENDMACRO;

MyFnMac(WORKUNIT);

I removed the OVERWRITE option on the OUTPUT since I'm passing in a unique identifier (the WORKUNIT id) and there's no need to worry about the number of times it executes because the EXPIRE(1) will cause the audit files to be deleted after a day.

huangapple
  • 本文由 发表于 2023年6月29日 23:14:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定