fix: enabling closeouts for UPDATE in CAS tables
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
@li mp_abort.sas
|
||||
@li mf_existvar.sas
|
||||
@li mf_getattrn.sas
|
||||
@li mf_getengine.sas
|
||||
@li mf_getuser.sas
|
||||
@li mf_getvartype.sas
|
||||
@li mp_lockanytable.sas
|
||||
@@ -70,13 +71,16 @@
|
||||
* perform basic checks
|
||||
*/
|
||||
/* do tables exist? */
|
||||
%if not %sysfunc(exist(&base_lib..&base_dsn)) %then %do;
|
||||
%mp_abort(msg=&base_lib..&base_dsn does not exist)
|
||||
%end;
|
||||
%else %if %sysfunc(exist(&append_lib..&append_dsn))=0
|
||||
and %sysfunc(exist(&append_lib..&append_dsn,VIEW))=0 %then %do;
|
||||
%mp_abort(msg=&append_lib..&append_dsn does not exist)
|
||||
%end;
|
||||
%mp_abort(
|
||||
iftrue=(%sysfunc(exist(&base_lib..&base_dsn)) ne 1),
|
||||
msg=&base_lib..&base_dsn does not exist
|
||||
)
|
||||
%mp_abort(
|
||||
iftrue=(%sysfunc(exist(&append_lib..&append_dsn))=0
|
||||
and %sysfunc(exist(&append_lib..&append_dsn,VIEW))=0 ),
|
||||
msg=&append_lib..&append_dsn does not exist
|
||||
)
|
||||
|
||||
/* do TX columns exist? */
|
||||
%if &loadtype ne UPDATE %then %do;
|
||||
%if not %mf_existvar(&base_lib..&base_dsn,&tech_from) %then %do;
|
||||
@@ -111,55 +115,83 @@ data _null_;
|
||||
gap=intck('HOURS',now,datetime());
|
||||
call symputx('gap',gap,'l');
|
||||
run;
|
||||
%mf_abort(
|
||||
%mp_abort(
|
||||
iftrue=(&gap > 24),
|
||||
msg=NOW variable (&now) is not within a 24hr tolerance
|
||||
)
|
||||
|
||||
/* have any warnings / errs occurred thus far? If so, abort */
|
||||
%mf_abort(
|
||||
%mp_abort(
|
||||
iftrue=(&syscc>0),
|
||||
msg=Aborted due to SYSCC=&SYSCC status
|
||||
)
|
||||
|
||||
/**
|
||||
* Create closeout statements. These are sent as individual SQL statements
|
||||
* Create closeout statements. If UPDATE approach and CAS engine, use the
|
||||
* DeleteRows action (as regular SQL deletes are not supported).
|
||||
* Otherwise, the deletions are sent as individual SQL statements
|
||||
* to ensure pass-through utilisation. The update_cnt variable monitors
|
||||
* how many records were actually updated on the target table.
|
||||
*/
|
||||
%local update_cnt;
|
||||
%local update_cnt etype;
|
||||
%let update_cnt=0;
|
||||
%let etype=%mf_getengine(&base_lib);
|
||||
%put &=etype;
|
||||
filename tmp temp;
|
||||
data _null_;
|
||||
set ___closeout1;
|
||||
file tmp;
|
||||
if _n_=1 then put 'proc sql noprint;' ;
|
||||
length string $32767.;
|
||||
%if &loadtype=UPDATE %then %do;
|
||||
put "delete from &base_lib..&base_dsn where 1";
|
||||
%end;
|
||||
%else %do;
|
||||
now=symget('now');
|
||||
put "update &base_lib..&base_dsn set &tech_to= " now @;
|
||||
%if %mf_existvar(&base_lib..&base_dsn,PROCESSED_DTTM) %then %do;
|
||||
put " ,PROCESSED_DTTM=" now @;
|
||||
%end;
|
||||
put " where " now " lt &tech_to ";
|
||||
%end;
|
||||
%do x=1 %to %sysfunc(countw(&PK));
|
||||
%let var=%scan(&pk,&x,%str( ));
|
||||
%if %mf_getvartype(&base_lib..&base_dsn,&var)=C %then %do;
|
||||
/* use single quotes to avoid ampersand resolution in data */
|
||||
string=" & &var='"!!trim(prxchange("s/'/''/",-1,&var))!!"'";
|
||||
%if &loadtype=UPDATE and &etype=CAS %then %do;
|
||||
/* create temp table for deletions */
|
||||
%local delds;%let delds=%mf_getuniquename(prefix=DC);
|
||||
data casuser.&delds;
|
||||
set work.___closeout1;
|
||||
run;
|
||||
/* build the proc */
|
||||
data _null_;
|
||||
file tmp;
|
||||
put 'proc cas;table.deleteRows result=r/ table={' ;
|
||||
put " caslib='&base_lib',name='&base_dsn',where='1=1',";
|
||||
put " whereTable={caslib='CASUSER',name='&delds'}";
|
||||
put "};";
|
||||
put "call symputx('update_cnt',r.RowsDeleted);";
|
||||
put "quit;";
|
||||
put '%put &=update_cnt;';
|
||||
put "proc sql;drop table CASUSER.&delds;";
|
||||
stop;
|
||||
run;
|
||||
|
||||
%end;
|
||||
%else %do;
|
||||
data _null_;
|
||||
set ___closeout1;
|
||||
file tmp;
|
||||
if _n_=1 then put 'proc sql noprint;' ;
|
||||
length string $32767.;
|
||||
%if &loadtype=UPDATE %then %do;
|
||||
put "delete from &base_lib..&base_dsn where 1";
|
||||
%end;
|
||||
%else %do;
|
||||
string=cats(" & &var=",&var);
|
||||
now=symget('now');
|
||||
put "update &base_lib..&base_dsn set &tech_to= " now @;
|
||||
%if %mf_existvar(&base_lib..&base_dsn,PROCESSED_DTTM) %then %do;
|
||||
put " ,PROCESSED_DTTM=" now @;
|
||||
%end;
|
||||
put " where " now " lt &tech_to ";
|
||||
%end;
|
||||
put string;
|
||||
%end;
|
||||
put "&filter ;";
|
||||
put '%let update_cnt=%eval(&update_cnt+&sqlobs);%put update_cnt=&update_cnt;';
|
||||
run;
|
||||
%do x=1 %to %sysfunc(countw(&PK));
|
||||
%let var=%scan(&pk,&x,%str( ));
|
||||
%if %mf_getvartype(&base_lib..&base_dsn,&var)=C %then %do;
|
||||
/* use single quotes to avoid ampersand resolution in data */
|
||||
string=" & &var='"!!trim(prxchange("s/'/''/",-1,&var))!!"'";
|
||||
%end;
|
||||
%else %do;
|
||||
string=cats(" & &var=",&var);
|
||||
%end;
|
||||
put string;
|
||||
%end;
|
||||
put "&filter ;";
|
||||
put '%let update_cnt=%eval(&update_cnt+&sqlobs);';
|
||||
put '%put update_cnt=&update_cnt;';
|
||||
run;
|
||||
%end;
|
||||
|
||||
data _null_;
|
||||
infile tmp;
|
||||
|
||||
Reference in New Issue
Block a user