feat(versions): getting list of versions (plus test)

This commit is contained in:
^ 2024-03-20 21:37:13 +00:00
parent c3af97ef57
commit 8003da94e6
8 changed files with 174 additions and 27 deletions

View File

@ -0,0 +1,33 @@
/**
@file
@brief Get previous versions of a table
@details Used to fetch version data for a particular table
Delivered as part of this issue: https://git.datacontroller.io/dc/dc/issues/84
@param [in] dclib The DC libref
@param [in] lib The library of the dataset for which to fetch versions
@param [in] ds The dataset to fetch versions for
@param [out] outds= (work.mpe_getversions) the DS to create
**/
%macro mpe_getversions(dclib,libref,ds,outds=work.mpe_getversions);
proc sql;
create table &outds as
select csv_dir as LOAD_REF,
user_nm ,
duration ,
processed_dttm as VERSION_DTTM,
reason_txt as VERSION_DESC
from &dclib..mpe_loads
where status='SUCCESS'
and csv_dir in (
select table_id
from &dclib..mpe_review
where base_table="&libref..&ds"
)
order by processed_dttm desc;
%mend mpe_getversions;

View File

@ -0,0 +1,84 @@
/**
@file
@brief Testing mpe_getversions macro
@details Checking functionality of mpe_getversions.sas macro
<h4> SAS Macros </h4>
@li mf_nobs.sas
@li mp_assert.sas
@li mp_assertscope.sas
@li mpe_getversions.sas
@li mpe_targetloader.sas
**/
/* run the macro*/
%mp_assertscope(SNAPSHOT)
%mpe_getversions(&mpelib,&mpelib,MPE_DATADICTIONARY, outds=ds0)
%mp_assertscope(COMPARE,
desc=Checking macro variables against previous snapshot
)
/* now stage some data */
%let f1=%mf_getuniquefileref();
data _null_;
file &f1 termstr=crlf;
put 'ACTION:$char4. MESSAGE:$char40. LIBDS:$char38.';
put "LOAD,staging some data,&dclib..MPE_DATADICTIONARY";
run;
data work.jsdata;
set &mpelib..MPE_DATADICTIONARY;
_____DELETE__THIS__RECORD_____='No';
dd_source=cats(ranuni(0));
output;
stop;
run;
%mx_testservice(&appLoc/services/editors/stagedata,
viyacontext=&defaultcontext,
inputfiles=&f1:sascontroltable,
inputdatasets=jsdata,
outlib=web1,
mdebug=&sasjs_mdebug
)
%let status=0;
data work.sasparams;
set web1.sasparams;
putlog (_all_)(=);
if status='SUCCESS' then call symputx('status',1);
call symputx('dsid',dsid);
run;
%mp_assert(
iftrue=(&status=1),
desc=Checking staged data component,
outds=work.test_results
)
/* now approve the data so the change is applied */
data work.sascontroltable;
ACTION='APPROVE_TABLE';
TABLE="&dsid";
DIFFTIME="%sysfunc(datetime(),datetime19.)";
output;
stop;
run;
%mx_testservice(&appLoc/services/auditors/postdata,
viyacontext=&defaultcontext,
inputdatasets=work.sascontroltable,
outlib=web2,
outref=wbout,
mdebug=&sasjs_mdebug
)
/* finally - check that we have an extra version! */
%mpe_getversions(&mpelib,&mpelib,MPE_DATADICTIONARY, outds=ds1)
%mp_assert(
iftrue=(%mf_nobs(ds0) = %mf_nobs(ds1)-1),
desc=Checking one extra version was created
)

View File

@ -300,28 +300,6 @@ create table vars_csv2 as
on a.name=b.name
order by a.varnum;
/* make sure that the variables we are importing, actually
exist on the target table */
/** edit - extra variables are now simply ignored
%local very_bad_vars;
select name into: very_bad_vars separated by ' '
from vars_csv1
where name not in (select name from vars)
and name ne "_____DELETE__THIS__RECORD_____";
%if %length(&very_bad_vars) > 0 %then %do;
%let msg=%str(WARNING: The following vars are not defined in %trim(
)&libref..&ds, yet they exist in &csv_dir/&ds..csv: &very_bad_vars);
%mpe_loadfail(
status=FAILED
,now=&now
,mperef=&mperef
,reason_txt=%quote(&msg)
,dc_dttmtfmt=&dc_dttmtfmt.
)
%return;
%end;
**/
/* now build input statement */
data final_check;

View File

@ -33,7 +33,7 @@
,CLOSE_VARS= /* provide close vars to override defaults */
,dclib=NOTPROVIDED
,mdebug=0
,dc_dttmtfmt=E8601DT26.6
,dc_dttmtfmt=%sysfunc(datetime())
);
%local lib ds nobs;
@ -219,7 +219,7 @@ run;
)
%end;
%else %do;
%put WARNING: LOADTYPE &LOADTYPE not supported;
%put %str(WARN)ING: LOADTYPE &LOADTYPE not supported;
%let syscc=4;
%mp_abort(msg=LOADTYPE &LOADTYPE not supported,mac=mpe_targetloader.sas)
%end;

View File

@ -59,6 +59,7 @@ data _null_;
call symputx('LOAD_REF',TABLE);
/* DIFFTIME is when the DIFF was generated on the frontend */
call symputx('DIFFTIME',DIFFTIME);
putlog (_all_)(=);
run;
%global action is_err err_msg msg;
@ -101,7 +102,7 @@ data APPROVE1;
putlog (_all_)(=);
/* convert provided string DIFFTIME back to a numeric SAS datetime */
if "&action" ne "SHOW_DIFFS" then do;
call symputx('DIFFTIME',input(symget('DIFFTIME'),anydtdtm18.));
call symputx('DIFFTIME',input(cats(symget('DIFFTIME')),anydtdtm18.));
end;
length difftime $32;
DIFFTIME=put(&sastime,datetime19.2);
@ -190,7 +191,7 @@ run;
and REVIEW_STATUS_ID ne "SUBMITTED";
%let authcheck=%mf_getattrn(work.authAPP,NLOBS);
%if &authcheck=0 or &prev_upload_check=1 %then %do;
%put WARNING: authcheck=&authcheck prev_upload_check=&prev_upload_check;
%put %str(WARN)ING: &=authcheck &=prev_upload_check;
data apPARAMS;
AUTHORISED=&authcheck;
PREV_UPLOAD_CHECK=&prev_upload_check;

View File

@ -0,0 +1,48 @@
/**
@file getversion.sas
@brief get a specific (previous) version of a particular table
@details Used to fetch a version of a table as at a previous point in time
Delivered as part of this issue: https://git.datacontroller.io/dc/dc/issues/84
<h4> Service Inputs </h4>
<h5> getversion_input </h5>
|LIBREF:$char8.|DS:$char32.|TS: 8.|
|---|---|---|
|SOMELIB|SOMEDS|1341344.804|
<h4> Service Outputs </h4>
<h5> work.getversion_output </h5>
The data for a particular version
<h4> SAS Macros </h4>
@li mf_getuser.sas
@li mpeinit.sas
@li mpe_getvars.sas
@version 9.2
@author 4GL Apps Ltd
**/
%mpeinit()
%global LIBREF DS;
/* load parameters */
%mpe_getvars(getversion_input, getversion_input)
%mp_abort(iftrue= (&syscc ne 0 )
,mac=&_program
,msg=%str(Issue on startup)
)
/* todo */
%webout(OPEN)
%webout(OBJ,getversion_output)
%webout(CLOSE)
%mpeterm()

View File

@ -32,7 +32,7 @@ data groups
a=1;
grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
if grpassn in (-3,-4) then do;
putlog "WARNING: No groups found for ";
putlog "%str(WARN)ING: No groups found for ";
end;
else do while (grpassn > 0);
rc=metadata_getattr(groupuri, "Name", groupname);

View File

@ -9,12 +9,15 @@
@li mf_getplatform.sas
@li mpeinit2.sas
@li mp_abort.sas
@li mp_init.sas
@li mp_testservice.sas
REMOVE THAT LAST MACRO
**/
%mp_init()
%let syscc=0;
%global apploc _program dclib defaultcontext _debug sasjs_mdebug dc_dttmtfmt;