1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-15 08:14:34 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Allan Bowe
53865a3909 feat: Postgres support for getddl macro 2020-07-29 12:32:54 +02:00
Allan Bowe
98a0d185ff fix: compatibility with compute sessions 2020-07-15 09:58:48 +02:00
6 changed files with 176 additions and 32 deletions

96
all.sas
View File

@@ -3863,6 +3863,64 @@ proc sql
%mp_binarycopy(inloc="&inloc",outref=_webout) %mp_binarycopy(inloc="&inloc",outref=_webout)
%mend;/**
@file mp_testwritespeedlibrary.sas
@brief Tests the write speed of a new table in a SAS library
@details Will create a new table of a certain size in an
existing SAS library. The table will have one column,
and will be subsequently deleted.
%mp_testwritespeedlibrary(
lib=work
,size=0.5
,outds=work.results
)
@param lib= (WORK) The library in which to create the table
@param size= (0.1) The size in GB of the table to create
@param outds= (WORK.RESULTS) The output dataset to be created.
<h4> Dependencies </h4>
@li mf_getuniquename.sas
@li mf_existds.sas
@version 9.4
@author Allan Bowe
**/
%macro mp_testwritespeedlibrary(lib=WORK
,outds=work.results
,size=0.1
)/*/STORE SOURCE*/;
%local ds start;
/* find an unused, unique name for the new table */
%let ds=%mf_getuniquename();
%do %until(%mf_existds(&lib..&ds)=0);
%let ds=%mf_getuniquename();
%end;
%let start=%sysfunc(datetime());
data &lib..&ds(compress=no keep=x);
header=128*1024;
size=(1073741824/8 * &size) - header;
do x=1 to size;
output;
end;
run;
proc sql;
drop table &lib..&ds;
data &outds;
lib="&lib";
start_dttm=put(&start,datetime19.);
end_dttm=put(datetime(),datetime19.);
duration_seconds=end_dttm-start_dttm;
run;
%mend;/** %mend;/**
@file mp_unzip.sas @file mp_unzip.sas
@brief Unzips a zip file @brief Unzips a zip file
@@ -9937,7 +9995,7 @@ data _null_;
put '%mend; '; put '%mend; ';
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); '; put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name '; put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
put ' sasjs_tables; '; put ' sasjs_tables SYS_JES_JOB_URI; ';
put '%if %index("&_debug",log) %then %let _debug=131; '; put '%if %index("&_debug",log) %then %let _debug=131; ';
put ' '; put ' ';
put '%local i tempds; '; put '%local i tempds; ';
@@ -10040,8 +10098,13 @@ data _null_;
put '%else %if &action=OPEN %then %do; '; put '%else %if &action=OPEN %then %do; ';
put ' /* setup webout */ '; put ' /* setup webout */ ';
put ' OPTIONS NOBOMFILE; '; put ' OPTIONS NOBOMFILE; ';
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" '; put ' %if "X&SYS_JES_JOB_URI.X"="XX" %then %do; ';
put ' name="_webout.json" lrecl=999999 mod; '; put ' filename _webout temp lrecl=999999 mod; ';
put ' %end; ';
put ' %else %do; ';
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
put ' name="_webout.json" lrecl=999999 mod; ';
put ' %end; ';
put ' '; put ' ';
put ' /* setup temp ref */ '; put ' /* setup temp ref */ ';
put ' %if %upcase(&fref) ne _WEBOUT %then %do; '; put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
@@ -10071,13 +10134,13 @@ data _null_;
put ' i+1; '; put ' i+1; ';
put ' call symputx(''wt''!!left(i),name); '; put ' call symputx(''wt''!!left(i),name); ';
put ' call symputx(''wtcnt'',i); '; put ' call symputx(''wtcnt'',i); ';
put ' data _null_; file &fref; put ",""WORK"":{"; '; put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
put ' %do i=1 %to &wtcnt; '; put ' %do i=1 %to &wtcnt; ';
put ' %let wt=&&wt&i; '; put ' %let wt=&&wt&i; ';
put ' proc contents noprint data=&wt '; put ' proc contents noprint data=&wt ';
put ' out=_data_ (keep=name type length format:); '; put ' out=_data_ (keep=name type length format:); ';
put ' run;%let tempds=%scan(&syslast,2,.); '; put ' run;%let tempds=%scan(&syslast,2,.); ';
put ' data _null_; file &fref; '; put ' data _null_; file &fref mod; ';
put ' dsid=open("WORK.&wt",''is''); '; put ' dsid=open("WORK.&wt",''is''); ';
put ' nlobs=attrn(dsid,''NLOBS''); '; put ' nlobs=attrn(dsid,''NLOBS''); ';
put ' nvars=attrn(dsid,''NVARS''); '; put ' nvars=attrn(dsid,''NVARS''); ';
@@ -10088,9 +10151,9 @@ data _null_;
put ' put '',"nvars":'' nvars; '; put ' put '',"nvars":'' nvars; ';
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) '; put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) '; put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
put ' data _null_; file &fref;put "}"; '; put ' data _null_; file &fref mod;put "}"; ';
put ' %end; '; put ' %end; ';
put ' data _null_; file &fref;put "}";run; '; put ' data _null_; file &fref mod;put "}";run; ';
put ' %end; '; put ' %end; ';
put ' '; put ' ';
put ' /* close off json */ '; put ' /* close off json */ ';
@@ -11960,7 +12023,7 @@ filename &fref1 clear;
**/ **/
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); %macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name %global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
sasjs_tables; sasjs_tables SYS_JES_JOB_URI;
%if %index("&_debug",log) %then %let _debug=131; %if %index("&_debug",log) %then %let _debug=131;
%local i tempds; %local i tempds;
@@ -12063,8 +12126,13 @@ filename &fref1 clear;
%else %if &action=OPEN %then %do; %else %if &action=OPEN %then %do;
/* setup webout */ /* setup webout */
OPTIONS NOBOMFILE; OPTIONS NOBOMFILE;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" %if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
name="_webout.json" lrecl=999999 mod; filename _webout temp lrecl=999999 mod;
%end;
%else %do;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
name="_webout.json" lrecl=999999 mod;
%end;
/* setup temp ref */ /* setup temp ref */
%if %upcase(&fref) ne _WEBOUT %then %do; %if %upcase(&fref) ne _WEBOUT %then %do;
@@ -12094,13 +12162,13 @@ filename &fref1 clear;
i+1; i+1;
call symputx('wt'!!left(i),name); call symputx('wt'!!left(i),name);
call symputx('wtcnt',i); call symputx('wtcnt',i);
data _null_; file &fref; put ",""WORK"":{"; data _null_; file &fref mod; put ",""WORK"":{";
%do i=1 %to &wtcnt; %do i=1 %to &wtcnt;
%let wt=&&wt&i; %let wt=&&wt&i;
proc contents noprint data=&wt proc contents noprint data=&wt
out=_data_ (keep=name type length format:); out=_data_ (keep=name type length format:);
run;%let tempds=%scan(&syslast,2,.); run;%let tempds=%scan(&syslast,2,.);
data _null_; file &fref; data _null_; file &fref mod;
dsid=open("WORK.&wt",'is'); dsid=open("WORK.&wt",'is');
nlobs=attrn(dsid,'NLOBS'); nlobs=attrn(dsid,'NLOBS');
nvars=attrn(dsid,'NVARS'); nvars=attrn(dsid,'NVARS');
@@ -12111,9 +12179,9 @@ filename &fref1 clear;
put ',"nvars":' nvars; put ',"nvars":' nvars;
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
data _null_; file &fref;put "}"; data _null_; file &fref mod;put "}";
%end; %end;
data _null_; file &fref;put "}";run; data _null_; file &fref mod;put "}";run;
%end; %end;
/* close off json */ /* close off json */

View File

@@ -217,7 +217,72 @@ run;
run; run;
%end; %end;
%end; %end;
%else %if &flavour=PGSQL %then %do;
/* if schema does not exist, set to be same as libref */
%local schemaactual;
proc sql noprint;
select sysvalue into: schemaactual
from dictionary.libnames
where libname="&libref" and engine='POSTGRES';
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
%do x=1 %to %sysfunc(countw(&dsnlist));
%let curds=%scan(&dsnlist,&x);
data _null_;
file &fref mod;
put "/* Postgres Flavour DDL for &schema..&curds */";
data _null_;
file &fref mod;
set &colinfo (where=(upcase(memname)="&curds")) end=last;
length fmt $32;
if _n_=1 then do;
if memtype='DATA' then do;
put "CREATE TABLE &schema..&curds (";
end;
else do;
put "CREATE VIEW &schema..&curds (";
end;
put " "@@;
end;
else put " ,"@@;
format=upcase(format);
if 1=0 then; /* dummy if */
%if &applydttm=YES %then %do;
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
%end;
else if type='num' then fmt=' DOUBLE PRECISION';
else fmt='VARCHAR('!!cats(length)!!')';
if notnull='yes' then notnul=' NOT NULL';
put name fmt notnul;
run;
data _null_;
length ds $128;
set &idxinfo (where=(memname="&curds"));
file &fref mod;
by idxusage indxname;
if unique='yes' then uniq=' unique';
ds=cats(libname,'.',memname);
if first.indxname then do;
if unique='yes' and nomiss='yes' then do;
put ' ,PRIMARY KEY ';
end;
else if unique='yes' then do;
/* add nonclustered in case of multiple unique indexes */
put ' ,UNIQUE ';
end;
put ' (' name ;
end;
else put ' ,' name ;
if last.indxname then do;
put ' )';
end;
run;
data _null_;
file &fref mod;
put ');';
run;
%end;
%end;
%if &showlog=YES %then %do; %if &showlog=YES %then %do;
options ps=max; options ps=max;
data _null_; data _null_;

View File

@@ -30,7 +30,7 @@ doxygen Doxyfile
# refresh github pages site # refresh github pages site
git clone git@github.com:sasjs/core.github.io.git git clone git@github.com:sasjs/core.github.io.git
cd core.github.io cd core.github.io
git rm -r * rm -r *
mv $BUILD_FOLDER/out/doxy/* . mv $BUILD_FOLDER/out/doxy/* .
echo 'core.sasjs.io' > CNAME echo 'core.sasjs.io' > CNAME
git add * git add *

View File

@@ -1,17 +1,18 @@
/** /**
@file @file mm_adduser2group.sas
@brief Adds a user to a group @brief Adds a user to a group
@details Adds a user to a metadata group. The macro first checks whether the @details Adds a user to a metadata group. The macro first checks whether the
user is in that group, and if not, the user is added. user is in that group, and if not, the user is added.
Usage: Usage:
%mm_adduser2group(user=sasdemo %mm_adduser2group(user=sasdemo
,group=someGroup) ,group=someGroup)
@param user= the user name (not displayname) @param user= the user name (not displayname)
@param group= the group to which to add the user @param group= the group to which to add the user
@param mdebug= set to 1 to show debug info in log
@warning the macro does not check inherited group memberships - it looks at @warning the macro does not check inherited group memberships - it looks at
direct members only direct members only

View File

@@ -338,7 +338,7 @@ data _null_;
put '%mend; '; put '%mend; ';
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); '; put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name '; put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
put ' sasjs_tables; '; put ' sasjs_tables SYS_JES_JOB_URI; ';
put '%if %index("&_debug",log) %then %let _debug=131; '; put '%if %index("&_debug",log) %then %let _debug=131; ';
put ' '; put ' ';
put '%local i tempds; '; put '%local i tempds; ';
@@ -441,8 +441,13 @@ data _null_;
put '%else %if &action=OPEN %then %do; '; put '%else %if &action=OPEN %then %do; ';
put ' /* setup webout */ '; put ' /* setup webout */ ';
put ' OPTIONS NOBOMFILE; '; put ' OPTIONS NOBOMFILE; ';
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" '; put ' %if "X&SYS_JES_JOB_URI.X"="XX" %then %do; ';
put ' name="_webout.json" lrecl=999999 mod; '; put ' filename _webout temp lrecl=999999 mod; ';
put ' %end; ';
put ' %else %do; ';
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
put ' name="_webout.json" lrecl=999999 mod; ';
put ' %end; ';
put ' '; put ' ';
put ' /* setup temp ref */ '; put ' /* setup temp ref */ ';
put ' %if %upcase(&fref) ne _WEBOUT %then %do; '; put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
@@ -472,13 +477,13 @@ data _null_;
put ' i+1; '; put ' i+1; ';
put ' call symputx(''wt''!!left(i),name); '; put ' call symputx(''wt''!!left(i),name); ';
put ' call symputx(''wtcnt'',i); '; put ' call symputx(''wtcnt'',i); ';
put ' data _null_; file &fref; put ",""WORK"":{"; '; put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
put ' %do i=1 %to &wtcnt; '; put ' %do i=1 %to &wtcnt; ';
put ' %let wt=&&wt&i; '; put ' %let wt=&&wt&i; ';
put ' proc contents noprint data=&wt '; put ' proc contents noprint data=&wt ';
put ' out=_data_ (keep=name type length format:); '; put ' out=_data_ (keep=name type length format:); ';
put ' run;%let tempds=%scan(&syslast,2,.); '; put ' run;%let tempds=%scan(&syslast,2,.); ';
put ' data _null_; file &fref; '; put ' data _null_; file &fref mod; ';
put ' dsid=open("WORK.&wt",''is''); '; put ' dsid=open("WORK.&wt",''is''); ';
put ' nlobs=attrn(dsid,''NLOBS''); '; put ' nlobs=attrn(dsid,''NLOBS''); ';
put ' nvars=attrn(dsid,''NVARS''); '; put ' nvars=attrn(dsid,''NVARS''); ';
@@ -489,9 +494,9 @@ data _null_;
put ' put '',"nvars":'' nvars; '; put ' put '',"nvars":'' nvars; ';
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) '; put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) '; put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
put ' data _null_; file &fref;put "}"; '; put ' data _null_; file &fref mod;put "}"; ';
put ' %end; '; put ' %end; ';
put ' data _null_; file &fref;put "}";run; '; put ' data _null_; file &fref mod;put "}";run; ';
put ' %end; '; put ' %end; ';
put ' '; put ' ';
put ' /* close off json */ '; put ' /* close off json */ ';

View File

@@ -37,7 +37,7 @@
**/ **/
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); %macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name %global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
sasjs_tables; sasjs_tables SYS_JES_JOB_URI;
%if %index("&_debug",log) %then %let _debug=131; %if %index("&_debug",log) %then %let _debug=131;
%local i tempds; %local i tempds;
@@ -140,8 +140,13 @@
%else %if &action=OPEN %then %do; %else %if &action=OPEN %then %do;
/* setup webout */ /* setup webout */
OPTIONS NOBOMFILE; OPTIONS NOBOMFILE;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" %if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
name="_webout.json" lrecl=999999 mod; filename _webout temp lrecl=999999 mod;
%end;
%else %do;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
name="_webout.json" lrecl=999999 mod;
%end;
/* setup temp ref */ /* setup temp ref */
%if %upcase(&fref) ne _WEBOUT %then %do; %if %upcase(&fref) ne _WEBOUT %then %do;
@@ -171,13 +176,13 @@
i+1; i+1;
call symputx('wt'!!left(i),name); call symputx('wt'!!left(i),name);
call symputx('wtcnt',i); call symputx('wtcnt',i);
data _null_; file &fref; put ",""WORK"":{"; data _null_; file &fref mod; put ",""WORK"":{";
%do i=1 %to &wtcnt; %do i=1 %to &wtcnt;
%let wt=&&wt&i; %let wt=&&wt&i;
proc contents noprint data=&wt proc contents noprint data=&wt
out=_data_ (keep=name type length format:); out=_data_ (keep=name type length format:);
run;%let tempds=%scan(&syslast,2,.); run;%let tempds=%scan(&syslast,2,.);
data _null_; file &fref; data _null_; file &fref mod;
dsid=open("WORK.&wt",'is'); dsid=open("WORK.&wt",'is');
nlobs=attrn(dsid,'NLOBS'); nlobs=attrn(dsid,'NLOBS');
nvars=attrn(dsid,'NVARS'); nvars=attrn(dsid,'NVARS');
@@ -188,9 +193,9 @@
put ',"nvars":' nvars; put ',"nvars":' nvars;
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
data _null_; file &fref;put "}"; data _null_; file &fref mod;put "}";
%end; %end;
data _null_; file &fref;put "}";run; data _null_; file &fref mod;put "}";run;
%end; %end;
/* close off json */ /* close off json */