@sasjs/core 4.63.0 → 4.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/base/mp_assert.sas +1 -0
- package/base/mp_assertscope.sas +2 -1
- package/base/mp_init.sas +2 -1
- package/package.json +1 -1
- package/viya/mfv_existsashdat.sas +8 -9
- package/viya/mfv_getcaslib.sas +37 -0
- package/viya/mv_castabload.sas +207 -0
- package/viya/mv_castabsave.sas +192 -0
- package/viya/mv_createfile.sas +7 -6
- package/viya/mv_getviyafileextparms.sas +31 -24
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
201
201
|
- All dataset references must be 2 level (eg `work.blah`, not `blah`). This is to avoid contention when options [DATASTMTCHK](https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000279064.htm)=ALLKEYWORDS is in effect, or the [USER](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n18m1vkqmeo4esn1moikt23zhp8s.htm) library is active.
|
|
202
202
|
- Avoid naming collisions! All macro variables should be local scope. Use system generated work tables where possible - eg `data ; set sashelp.class; run; data &output; set &syslast; run;`
|
|
203
203
|
- Where global macro variables are absolutely necessary, they should make use of `&sasjs_prefix` - see mp_init.sas
|
|
204
|
-
- The use of `quit;` for `proc sql` is
|
|
204
|
+
- The use of `quit;` for `proc sql` is essential, to avoid `WARNING: You cannot disconnect or terminate session XXXX until the procedure completes.` when terminating CAS sessions in Viya.
|
|
205
205
|
- Use [sasjs lint](https://github.com/sasjs/lint)!
|
|
206
206
|
|
|
207
207
|
## General Notes
|
package/base/mp_assert.sas
CHANGED
package/base/mp_assertscope.sas
CHANGED
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
from dictionary.macros
|
|
93
93
|
where scope="&scope" and upcase(name) not in (%mf_getquotedstr(&ilist))
|
|
94
94
|
order by name,offset;
|
|
95
|
+
quit;
|
|
95
96
|
%end;
|
|
96
97
|
%else %if &action=COMPARE %then %do;
|
|
97
98
|
|
|
@@ -129,7 +130,6 @@
|
|
|
129
130
|
%let test_comments=%str(Mod:(&mod) Add:(&add) Del:(&del));
|
|
130
131
|
%end;
|
|
131
132
|
|
|
132
|
-
|
|
133
133
|
data ;
|
|
134
134
|
length test_description $256 test_result $4 test_comments $256;
|
|
135
135
|
test_description=symget('desc');
|
|
@@ -142,6 +142,7 @@
|
|
|
142
142
|
run;
|
|
143
143
|
proc sql;
|
|
144
144
|
drop table &ds;
|
|
145
|
+
quit;
|
|
145
146
|
%end;
|
|
146
147
|
|
|
147
148
|
%mend mp_assertscope;
|
package/base/mp_init.sas
CHANGED
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
&prefix._INIT_NUM /* initialisation time as numeric */
|
|
42
42
|
&prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
|
|
43
43
|
&prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
|
|
44
|
+
&prefix.PROCESSMODE
|
|
45
|
+
&prefix._STPSRV_HEADER_LOC
|
|
44
46
|
;
|
|
45
|
-
|
|
46
47
|
%let sasjs_prefix=&prefix;
|
|
47
48
|
|
|
48
49
|
data _null_;
|
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
%if %mfv_existsashdat(libds=casuser.sometable) %then %put yes it does!;
|
|
7
7
|
|
|
8
8
|
The function uses `dosubl()` to run the `table.fileinfo` action, for the
|
|
9
|
-
specified library, filtering for `*.sashdat` tables.
|
|
10
|
-
in a WORK table (&outprefix._&lib). If that table already exists, it is
|
|
11
|
-
queried instead, to avoid the dosubl() performance hit.
|
|
9
|
+
specified library, filtering for `*.sashdat` tables.
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Results are cached in a WORK table (&outprefix._&lib). If that table
|
|
12
|
+
already exists it is queried directly to avoid the dosubl() overhead.
|
|
13
|
+
To force a rescan, use a new `&outprefix` value or delete the cache
|
|
14
|
+
table before calling.
|
|
15
15
|
|
|
16
16
|
@param [in] libds library.dataset
|
|
17
17
|
@param [out] outprefix= (work.mfv_existsashdat)
|
|
@@ -24,13 +24,12 @@
|
|
|
24
24
|
@author Mathieu Blauw
|
|
25
25
|
**/
|
|
26
26
|
|
|
27
|
-
%macro mfv_existsashdat(libds,outprefix=work.mfv_existsashdat
|
|
28
|
-
);
|
|
27
|
+
%macro mfv_existsashdat(libds,outprefix=work.mfv_existsashdat);
|
|
29
28
|
%local rc dsid name lib ds;
|
|
30
29
|
%let lib=%upcase(%scan(&libds,1,'.'));
|
|
31
30
|
%let ds=%upcase(%scan(&libds,-1,'.'));
|
|
32
31
|
|
|
33
|
-
/* if table does not exist,
|
|
32
|
+
/* if cache table does not exist, build it */
|
|
34
33
|
%if %sysfunc(exist(&outprefix._&lib)) ne 1 %then %do;
|
|
35
34
|
%let rc=%sysfunc(dosubl(%nrstr(
|
|
36
35
|
/* Read in table list (once per &lib per session) */
|
|
@@ -41,7 +40,7 @@
|
|
|
41
40
|
quit;
|
|
42
41
|
/* Only keep name, without file extension */
|
|
43
42
|
data &outprefix._&lib;
|
|
44
|
-
set &outprefix._&lib(where=(Name like '%.
|
|
43
|
+
set &outprefix._&lib(where=(upcase(Name) like '%.SASHDAT') keep=Name);
|
|
45
44
|
Name=upcase(scan(Name,1,'.'));
|
|
46
45
|
run;
|
|
47
46
|
)));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mfv_getcaslib.sas
|
|
3
|
+
@brief Returns the CAS caslib name for a given SAS libref
|
|
4
|
+
@details Pure macro function. Reads sashelp.vlibnam and returns
|
|
5
|
+
the sysvalue where sysname='Caslib' for the given libref. This
|
|
6
|
+
is useful when the caslib name and libref name may differ.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
|
|
10
|
+
%put %mfv_getcaslib(lib=PUBLIC);
|
|
11
|
+
|
|
12
|
+
@param [in] lib SAS libref for which to return the CAS caslib name
|
|
13
|
+
|
|
14
|
+
@return Returns the CAS caslib name, or empty string if not found
|
|
15
|
+
|
|
16
|
+
**/
|
|
17
|
+
|
|
18
|
+
%macro mfv_getcaslib(lib);
|
|
19
|
+
|
|
20
|
+
%local dsid rc result;
|
|
21
|
+
|
|
22
|
+
%let dsid=%sysfunc(open(sashelp.vlibnam(
|
|
23
|
+
where=(libname="%upcase(&lib)" and sysname="Caslib")
|
|
24
|
+
)));
|
|
25
|
+
|
|
26
|
+
%if &dsid %then %do;
|
|
27
|
+
%let rc=%sysfunc(fetch(&dsid));
|
|
28
|
+
%if &rc=0 %then
|
|
29
|
+
%let result=%sysfunc(
|
|
30
|
+
getvarc(&dsid,%sysfunc(varnum(&dsid,SYSVALUE)))
|
|
31
|
+
);
|
|
32
|
+
%let rc=%sysfunc(close(&dsid));
|
|
33
|
+
%end;
|
|
34
|
+
|
|
35
|
+
&result
|
|
36
|
+
|
|
37
|
+
%mend mfv_getcaslib;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mv_castabload.sas
|
|
3
|
+
@brief Checks if a CAS table is loaded; if not, loads and promotes it
|
|
4
|
+
@details Runs in SPRE against an active CAS session. Accepts a
|
|
5
|
+
SAS libref, derives the CAS caslib and session UUID from
|
|
6
|
+
sashelp.vlibnam, then checks whether the table is already
|
|
7
|
+
in-memory. If not, locates the owning CAS server via the
|
|
8
|
+
casManagement REST API, queries the table endpoint to discover
|
|
9
|
+
the source file and caslib, then loads and promotes the table.
|
|
10
|
+
|
|
11
|
+
A CAS session must already be established by the caller, eg:
|
|
12
|
+
|
|
13
|
+
cas mysess;
|
|
14
|
+
libname mylib cas caslib=Public;
|
|
15
|
+
%mv_castabload(lib=mylib, table=BASEBALL)
|
|
16
|
+
|
|
17
|
+
@param [in] lib= SAS libref for the CAS caslib
|
|
18
|
+
@param [in] table= Name of the CAS table to load
|
|
19
|
+
@param [in] mdebug= (0) Set to 1 to enable verbose logging:
|
|
20
|
+
- echoes resolved parameters
|
|
21
|
+
- prints tableExists result
|
|
22
|
+
- enables mprint/notes during PROC calls
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mf_getplatform.sas
|
|
26
|
+
@li mf_getuniquefileref.sas
|
|
27
|
+
@li mf_getuniquelibref.sas
|
|
28
|
+
@li mp_abort.sas
|
|
29
|
+
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mv_castabload(
|
|
33
|
+
lib=
|
|
34
|
+
,table=
|
|
35
|
+
,mdebug=0
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
%local _sysopts base_uri caslib uuid server
|
|
39
|
+
srcfile srccaslib fname1 libref1 ftmp i _svcount _exists;
|
|
40
|
+
%let _sysopts=%sysfunc(getoption(mprint)) %sysfunc(getoption(notes));
|
|
41
|
+
|
|
42
|
+
/* ---- input validation -------------------------------------------------- */
|
|
43
|
+
%mp_abort(
|
|
44
|
+
iftrue=("&lib"="" or "&table"=""),
|
|
45
|
+
msg=%str(lib= and table= are required)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
%if &mdebug=1 %then %do;
|
|
49
|
+
%put &=lib;
|
|
50
|
+
%put &=table;
|
|
51
|
+
options mprint notes;
|
|
52
|
+
%end;
|
|
53
|
+
|
|
54
|
+
/* ---- derive caslib and session UUID from sashelp.vlibnam --------------- */
|
|
55
|
+
data _null_;
|
|
56
|
+
set sashelp.vlibnam(
|
|
57
|
+
where=(libname="%upcase(&lib)"
|
|
58
|
+
and sysname in ("Caslib","Session UUID"))
|
|
59
|
+
);
|
|
60
|
+
if sysname="Caslib" then call symputx('caslib',sysvalue,'L');
|
|
61
|
+
else call symputx('uuid',sysvalue,'L');
|
|
62
|
+
%if &mdebug=1 %then %do;
|
|
63
|
+
putlog sysname sysvalue;
|
|
64
|
+
%end;
|
|
65
|
+
run;
|
|
66
|
+
|
|
67
|
+
%mp_abort(
|
|
68
|
+
iftrue=("&caslib"=""),
|
|
69
|
+
msg=%str(&lib is not an assigned CAS libref)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
%mp_abort(
|
|
73
|
+
iftrue=("&uuid"=""),
|
|
74
|
+
msg=%str(No session UUID found for libref &lib)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
/* ---- existence check --------------------------------------------------- */
|
|
78
|
+
proc cas;
|
|
79
|
+
table.tableExists result=r /
|
|
80
|
+
caslib="&caslib"
|
|
81
|
+
name="&table";
|
|
82
|
+
%if &mdebug=1 %then %do;
|
|
83
|
+
print r;
|
|
84
|
+
%end;
|
|
85
|
+
if r.exists > 0 then call symputx('_exists', '1', 'L');
|
|
86
|
+
else call symputx('_exists', '0', 'L');
|
|
87
|
+
quit;
|
|
88
|
+
|
|
89
|
+
/* ---- already loaded: skip ---------------------------------------------- */
|
|
90
|
+
%if &_exists=1 %then %do;
|
|
91
|
+
%put NOTE: Table &caslib..&table already loaded - skipping;
|
|
92
|
+
%return;
|
|
93
|
+
%end;
|
|
94
|
+
|
|
95
|
+
/* ---- get list of CAS servers ----------------------------------------- */
|
|
96
|
+
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
97
|
+
%let fname1=%mf_getuniquefileref();
|
|
98
|
+
%let libref1=%mf_getuniquelibref();
|
|
99
|
+
|
|
100
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
101
|
+
url="&base_uri/casManagement/servers";
|
|
102
|
+
run;
|
|
103
|
+
|
|
104
|
+
%mp_abort(
|
|
105
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
106
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
libname &libref1 JSON fileref=&fname1;
|
|
110
|
+
|
|
111
|
+
data _null_;
|
|
112
|
+
set &libref1..items;
|
|
113
|
+
call symputx(cats('_sv_', _n_), name, 'L');
|
|
114
|
+
call symputx('_svcount', _n_, 'L');
|
|
115
|
+
run;
|
|
116
|
+
|
|
117
|
+
libname &libref1 clear;
|
|
118
|
+
filename &fname1 clear;
|
|
119
|
+
|
|
120
|
+
/* ---- find which server owns this session ------------------------------ */
|
|
121
|
+
%do i=1 %to &_svcount;
|
|
122
|
+
%if "&server"="" %then %do;
|
|
123
|
+
%if &mdebug=1 %then %put checking server: &&_sv_&i;
|
|
124
|
+
%let ftmp=%mf_getuniquefileref();
|
|
125
|
+
proc http method='GET' out=&ftmp oauth_bearer=sas_services
|
|
126
|
+
url="&base_uri/casManagement/servers/&&_sv_&i/sessions/&uuid";
|
|
127
|
+
run;
|
|
128
|
+
%if &SYS_PROCHTTP_STATUS_CODE=200
|
|
129
|
+
%then %let server=&&_sv_&i;
|
|
130
|
+
filename &ftmp clear;
|
|
131
|
+
%end;
|
|
132
|
+
%end;
|
|
133
|
+
|
|
134
|
+
%mp_abort(
|
|
135
|
+
iftrue=("&server"=""),
|
|
136
|
+
msg=%str(Could not find owning server for CAS session &uuid)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
%if &mdebug=1 %then %put &=server;
|
|
140
|
+
|
|
141
|
+
/* ---- discover source file from REST endpoint -------------------------- */
|
|
142
|
+
%let fname1=%mf_getuniquefileref();
|
|
143
|
+
%let libref1=%mf_getuniquelibref();
|
|
144
|
+
|
|
145
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
146
|
+
url="&base_uri/casManagement/servers/&server/caslibs/&caslib/tables/&table";
|
|
147
|
+
run;
|
|
148
|
+
|
|
149
|
+
%if &mdebug=1 %then %do;
|
|
150
|
+
%put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
151
|
+
data _null_;
|
|
152
|
+
infile &fname1;
|
|
153
|
+
input;
|
|
154
|
+
putlog _infile_;
|
|
155
|
+
run;
|
|
156
|
+
%end;
|
|
157
|
+
|
|
158
|
+
%mp_abort(
|
|
159
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
|
|
160
|
+
msg=%str(&caslib..&table not found - is a source file registered?)
|
|
161
|
+
)
|
|
162
|
+
%mp_abort(
|
|
163
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
164
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
libname &libref1 JSON fileref=&fname1;
|
|
168
|
+
|
|
169
|
+
data _null_;
|
|
170
|
+
set &libref1..tablereference;
|
|
171
|
+
call symputx('srcfile', sourceTableName, 'L');
|
|
172
|
+
call symputx('srccaslib', sourceCaslibName, 'L');
|
|
173
|
+
stop;
|
|
174
|
+
run;
|
|
175
|
+
|
|
176
|
+
libname &libref1 clear;
|
|
177
|
+
filename &fname1 clear;
|
|
178
|
+
|
|
179
|
+
%mp_abort(
|
|
180
|
+
iftrue=("&srcfile"="" or "&srccaslib"=""),
|
|
181
|
+
msg=%str(No sourceTableName/sourceCaslibName for &caslib..&table)
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
%if &mdebug=1 %then %put &=srcfile &=srccaslib;
|
|
185
|
+
|
|
186
|
+
/* ---- load from discovered source -------------------------------------- */
|
|
187
|
+
proc casutil;
|
|
188
|
+
load casdata="&srcfile"
|
|
189
|
+
incaslib="&srccaslib"
|
|
190
|
+
casout="&table"
|
|
191
|
+
outcaslib="&caslib"
|
|
192
|
+
promote;
|
|
193
|
+
quit;
|
|
194
|
+
|
|
195
|
+
%mp_abort(
|
|
196
|
+
iftrue=(&syscc ne 0),
|
|
197
|
+
msg=%str(Load failed for &caslib..&table)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
%put NOTE: Table &caslib..&table loaded and promoted from &srcfile;
|
|
201
|
+
|
|
202
|
+
/* ---- restore options --------------------------------------------------- */
|
|
203
|
+
%if &mdebug=1 %then %do;
|
|
204
|
+
options &_sysopts;
|
|
205
|
+
%end;
|
|
206
|
+
|
|
207
|
+
%mend mv_castabload;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mv_castabsave.sas
|
|
3
|
+
@brief Saves an in-memory CAS table back to persistent storage
|
|
4
|
+
@details Runs in SPRE against an active CAS session. Accepts a
|
|
5
|
+
SAS libref, derives the CAS caslib and session UUID from
|
|
6
|
+
sashelp.vlibnam, locates the owning CAS server via the
|
|
7
|
+
casManagement REST API, then queries the table endpoint to
|
|
8
|
+
discover the original source file and saves back to that path.
|
|
9
|
+
CASUTIL infers the file type from the output file extension.
|
|
10
|
+
|
|
11
|
+
A CAS session must already be established by the caller, eg:
|
|
12
|
+
|
|
13
|
+
cas mysess;
|
|
14
|
+
libname mylib cas caslib=Public;
|
|
15
|
+
%mv_castabsave(lib=mylib, table=BASEBALL)
|
|
16
|
+
|
|
17
|
+
@param [in] lib= SAS libref for the CAS caslib
|
|
18
|
+
@param [in] table= Name of the in-memory CAS table to save
|
|
19
|
+
@param [in] mdebug= (0) Set to 1 to enable verbose logging:
|
|
20
|
+
- echoes resolved parameters
|
|
21
|
+
- prints HTTP response body
|
|
22
|
+
- enables mprint/notes during PROC calls
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mf_getplatform.sas
|
|
26
|
+
@li mf_getuniquefileref.sas
|
|
27
|
+
@li mf_getuniquelibref.sas
|
|
28
|
+
@li mp_abort.sas
|
|
29
|
+
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mv_castabsave(
|
|
33
|
+
lib=
|
|
34
|
+
,table=
|
|
35
|
+
,mdebug=0
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
%local _sysopts base_uri caslib uuid server
|
|
39
|
+
srcfile srccaslib fname1 libref1 ftmp i _svcount;
|
|
40
|
+
%let _sysopts=%sysfunc(getoption(mprint)) %sysfunc(getoption(notes));
|
|
41
|
+
|
|
42
|
+
/* ---- input validation -------------------------------------------------- */
|
|
43
|
+
%mp_abort(
|
|
44
|
+
iftrue=("&lib"="" or "&table"=""),
|
|
45
|
+
msg=%str(lib= and table= are required)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
%if &mdebug=1 %then %do;
|
|
49
|
+
%put &=lib;
|
|
50
|
+
%put &=table;
|
|
51
|
+
options mprint notes;
|
|
52
|
+
%end;
|
|
53
|
+
|
|
54
|
+
/* ---- derive caslib and session UUID from sashelp.vlibnam --------------- */
|
|
55
|
+
data _null_;
|
|
56
|
+
set sashelp.vlibnam(
|
|
57
|
+
where=(libname="%upcase(&lib)"
|
|
58
|
+
and sysname in ("Caslib","Session UUID"))
|
|
59
|
+
);
|
|
60
|
+
if sysname="Caslib" then call symputx('caslib',sysvalue,'L');
|
|
61
|
+
else call symputx('uuid',sysvalue,'L');
|
|
62
|
+
run;
|
|
63
|
+
|
|
64
|
+
%mp_abort(
|
|
65
|
+
iftrue=("&caslib"=""),
|
|
66
|
+
msg=%str(&lib is not an assigned CAS libref)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
%mp_abort(
|
|
70
|
+
iftrue=("&uuid"=""),
|
|
71
|
+
msg=%str(No session UUID found for libref &lib)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
%if &mdebug=1 %then %do;
|
|
75
|
+
%put &=caslib;
|
|
76
|
+
%put &=uuid;
|
|
77
|
+
%end;
|
|
78
|
+
|
|
79
|
+
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
80
|
+
|
|
81
|
+
/* ---- get list of CAS servers ------------------------------------------- */
|
|
82
|
+
%let fname1=%mf_getuniquefileref();
|
|
83
|
+
%let libref1=%mf_getuniquelibref();
|
|
84
|
+
|
|
85
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
86
|
+
url="&base_uri/casManagement/servers";
|
|
87
|
+
run;
|
|
88
|
+
|
|
89
|
+
%mp_abort(
|
|
90
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
91
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
libname &libref1 JSON fileref=&fname1;
|
|
95
|
+
|
|
96
|
+
data _null_;
|
|
97
|
+
set &libref1..items;
|
|
98
|
+
call symputx(cats('_sv_', _n_), name, 'L');
|
|
99
|
+
call symputx('_svcount', _n_, 'L');
|
|
100
|
+
run;
|
|
101
|
+
|
|
102
|
+
libname &libref1 clear;
|
|
103
|
+
filename &fname1 clear;
|
|
104
|
+
|
|
105
|
+
/* ---- find which server owns this session ------------------------------- */
|
|
106
|
+
%do i=1 %to &_svcount;
|
|
107
|
+
%if "&server"="" %then %do;
|
|
108
|
+
%if &mdebug=1 %then %put checking server: &&_sv_&i;
|
|
109
|
+
%let ftmp=%mf_getuniquefileref();
|
|
110
|
+
proc http method='GET' out=&ftmp oauth_bearer=sas_services
|
|
111
|
+
url="&base_uri/casManagement/servers/&&_sv_&i/sessions/&uuid";
|
|
112
|
+
run;
|
|
113
|
+
%if &SYS_PROCHTTP_STATUS_CODE=200
|
|
114
|
+
%then %let server=&&_sv_&i;
|
|
115
|
+
filename &ftmp clear;
|
|
116
|
+
%end;
|
|
117
|
+
%end;
|
|
118
|
+
|
|
119
|
+
%mp_abort(
|
|
120
|
+
iftrue=("&server"=""),
|
|
121
|
+
msg=%str(Could not find owning server for CAS session &uuid)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
%if &mdebug=1 %then %put &=server;
|
|
125
|
+
|
|
126
|
+
/* ---- discover srcfile from REST endpoint ------------------------------- */
|
|
127
|
+
%let fname1=%mf_getuniquefileref();
|
|
128
|
+
%let libref1=%mf_getuniquelibref();
|
|
129
|
+
|
|
130
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
131
|
+
url="&base_uri/casManagement/servers/&server/caslibs/&caslib/tables/&table";
|
|
132
|
+
run;
|
|
133
|
+
|
|
134
|
+
%if &mdebug=1 %then %do;
|
|
135
|
+
%put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
136
|
+
data _null_;
|
|
137
|
+
infile &fname1;
|
|
138
|
+
input;
|
|
139
|
+
putlog _infile_;
|
|
140
|
+
run;
|
|
141
|
+
%end;
|
|
142
|
+
|
|
143
|
+
%mp_abort(
|
|
144
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
|
|
145
|
+
msg=%str(&caslib..&table not found - is it loaded in memory?)
|
|
146
|
+
)
|
|
147
|
+
%mp_abort(
|
|
148
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
149
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
libname &libref1 JSON fileref=&fname1;
|
|
153
|
+
|
|
154
|
+
data _null_;
|
|
155
|
+
set &libref1..tablereference;
|
|
156
|
+
call symputx('srcfile', sourceTableName, 'L');
|
|
157
|
+
call symputx('srccaslib', sourceCaslibName, 'L');
|
|
158
|
+
stop;
|
|
159
|
+
run;
|
|
160
|
+
|
|
161
|
+
libname &libref1 clear;
|
|
162
|
+
filename &fname1 clear;
|
|
163
|
+
|
|
164
|
+
%mp_abort(
|
|
165
|
+
iftrue=("&srcfile"="" or "&srccaslib"=""),
|
|
166
|
+
msg=%str(No sourceTableName/sourceCaslibName for &caslib..&table)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
%if &mdebug=1 %then %put &=srcfile;
|
|
170
|
+
|
|
171
|
+
/* ---- save to disk ------------------------------------------------------- */
|
|
172
|
+
proc casutil;
|
|
173
|
+
save casdata="&table"
|
|
174
|
+
incaslib="&caslib"
|
|
175
|
+
casout="&srcfile"
|
|
176
|
+
outcaslib="&srccaslib"
|
|
177
|
+
replace;
|
|
178
|
+
quit;
|
|
179
|
+
|
|
180
|
+
%mp_abort(
|
|
181
|
+
iftrue=(&syscc ne 0),
|
|
182
|
+
msg=%str(Save failed for &caslib..&table)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
%put NOTE: Table &caslib..&table saved to &srcfile;
|
|
186
|
+
|
|
187
|
+
/* ---- restore options --------------------------------------------------- */
|
|
188
|
+
%if &mdebug=1 %then %do;
|
|
189
|
+
options &_sysopts;
|
|
190
|
+
%end;
|
|
191
|
+
|
|
192
|
+
%mend mv_castabsave;
|
package/viya/mv_createfile.sas
CHANGED
|
@@ -204,9 +204,10 @@ run;
|
|
|
204
204
|
|
|
205
205
|
/* Get Viya file-extension details into some macro variables */
|
|
206
206
|
%mv_getViyaFileExtParms(&ext
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
,propertiesVar=viyaProperties
|
|
208
|
+
,typeDefNameVar=viyaTypeDefName
|
|
209
|
+
,mdebug=&mdebug
|
|
210
|
+
)
|
|
210
211
|
|
|
211
212
|
/* fetch job info */
|
|
212
213
|
%local fname1;
|
|
@@ -274,9 +275,9 @@ run;
|
|
|
274
275
|
|
|
275
276
|
/* If properties were found then patch the file to include them */
|
|
276
277
|
%if not %mf_isBlank(%superq(viyaProperties)) %then %do;
|
|
277
|
-
/* Wrap the properties object in a root object also containing the
|
|
278
|
+
/* Wrap the properties object in a root object also containing the filename */
|
|
278
279
|
%local viyapatch;
|
|
279
|
-
%let viyapatch
|
|
280
|
+
%let viyapatch=%sysfunc(pathname(work))/%mf_getuniquename(prefix=patch_json_);
|
|
280
281
|
data _null_;
|
|
281
282
|
length line $32767;
|
|
282
283
|
file "&viyapatch" lrecl=32767;
|
|
@@ -296,7 +297,7 @@ run;
|
|
|
296
297
|
run;
|
|
297
298
|
%end;
|
|
298
299
|
|
|
299
|
-
/*
|
|
300
|
+
/* Apply the properties to the newly created file, using the PATCH method */
|
|
300
301
|
%let fref=%mf_getuniquefileref();
|
|
301
302
|
filename &fref "&viyapatch";
|
|
302
303
|
%let url=&base_uri&fileuri;
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
@li mf_existds.sas
|
|
24
24
|
@li mf_getplatform.sas
|
|
25
25
|
@li mf_getuniquefileref.sas
|
|
26
|
+
@li mf_getuniquelibref.sas
|
|
26
27
|
@li mf_getuniquename.sas
|
|
27
28
|
@li mf_getvalue.sas
|
|
28
29
|
@li mf_getvarlist.sas
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
iftrue=(%mf_isBlank(&ext))
|
|
49
50
|
,msg=%str(No file extension provided.)
|
|
50
51
|
,mac=MV_GETVIYAFILEEXTPARMS
|
|
51
|
-
)
|
|
52
|
+
)
|
|
52
53
|
|
|
53
54
|
%mp_abort(
|
|
54
55
|
iftrue=(%mf_isBlank(&typeDefNameVar) and
|
|
@@ -56,13 +57,13 @@
|
|
|
56
57
|
%mf_isBlank(&mediaTypeVar))
|
|
57
58
|
,msg=%str(MV_GETVIYAFILEEXTPARMS - No parameter was requested.)
|
|
58
59
|
,mac=MV_GETVIYAFILEEXTPARMS
|
|
59
|
-
)
|
|
60
|
+
)
|
|
60
61
|
|
|
61
62
|
%mp_abort(
|
|
62
63
|
iftrue=(%mf_isBlank(&viyaFileExtRespLibDs))
|
|
63
64
|
,msg=%str(No <libname.>dataset name provided to cache inital response.)
|
|
64
65
|
,mac=MV_GETVIYAFILEEXTPARMS
|
|
65
|
-
)
|
|
66
|
+
)
|
|
66
67
|
|
|
67
68
|
/* Declare requested parameters as global macro vars and initialize blank */
|
|
68
69
|
%if not %mf_isBlank(&typeDefNameVar) %then %do;
|
|
@@ -79,9 +80,7 @@
|
|
|
79
80
|
%end;
|
|
80
81
|
|
|
81
82
|
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
82
|
-
%if &mdebug=1 %then %
|
|
83
|
-
%put DEBUG: &=base_uri;
|
|
84
|
-
%end;
|
|
83
|
+
%if &mdebug=1 %then %put DEBUG: &=base_uri;
|
|
85
84
|
|
|
86
85
|
%let ext=%lowcase(&ext);
|
|
87
86
|
|
|
@@ -105,7 +104,7 @@
|
|
|
105
104
|
|
|
106
105
|
%if (&SYS_PROCHTTP_STATUS_CODE ne 200) %then %do;
|
|
107
106
|
/* To avoid a breaking change, exit early if the request failed.
|
|
108
|
-
|
|
107
|
+
The calling process will proceed with empty macro variables. */
|
|
109
108
|
%put INFO: &sysmacroname File extension details were not retrieved.;
|
|
110
109
|
filename &viyatypedefs clear;
|
|
111
110
|
%return;
|
|
@@ -126,11 +125,12 @@
|
|
|
126
125
|
/* Convert the content of that JSON into SAS datasets */
|
|
127
126
|
/* First prepare a new WORK-based folder to receive the datasets */
|
|
128
127
|
%local jsonworkfolder jsonlib opt_dlcreatedir;
|
|
129
|
-
%let jsonworkfolder=%sysfunc(pathname(work))/%mf_getuniquename(prefix=
|
|
128
|
+
%let jsonworkfolder=%sysfunc(pathname(work))/%mf_getuniquename(prefix=jsn_);
|
|
130
129
|
%let jsonlib=%mf_getuniquelibref(prefix=json);
|
|
131
|
-
|
|
130
|
+
/* And point a libname at it */
|
|
132
131
|
%let opt_dlcreatedir = %sysfunc(getoption(dlcreatedir));
|
|
133
|
-
options dlcreatedir; libname &jsonlib "&jsonworkfolder";
|
|
132
|
+
options dlcreatedir; libname &jsonlib "&jsonworkfolder";
|
|
133
|
+
options &opt_dlcreatedir;
|
|
134
134
|
|
|
135
135
|
/* Read the json output once and copy datasets to its work folder */
|
|
136
136
|
%local libref1;
|
|
@@ -159,20 +159,22 @@
|
|
|
159
159
|
|
|
160
160
|
%end; /* If initial filetype query response didn't exist */
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
%if &mdebug %then %put DEBUG: Find the row-group for extension &ext;
|
|
163
163
|
%local itemRowGroup;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
);
|
|
164
|
+
data _null_;
|
|
165
|
+
set &viyaFileExtRespLibDs;
|
|
166
|
+
where p1='items' and p2='extensions' and value="&ext";
|
|
167
|
+
call symputx('itemRowGroup',_viyaItemIdx,'l');
|
|
168
|
+
%if &mdebug %then %do;
|
|
169
|
+
putlog (_all_)(=);
|
|
170
|
+
%end;
|
|
171
|
+
run;
|
|
170
172
|
|
|
171
173
|
%if &mdebug %then %put DEBUG: &=itemRowGroup;
|
|
172
174
|
|
|
173
175
|
%if %mf_isBlank(&itemRowGroup) %then %do;
|
|
174
176
|
/* extension was not found */
|
|
175
|
-
%if
|
|
177
|
+
%if &mdebug %then %put DEBUG: No type details found for extension "&ext";
|
|
176
178
|
%return;
|
|
177
179
|
%end;
|
|
178
180
|
|
|
@@ -186,14 +188,17 @@
|
|
|
186
188
|
|
|
187
189
|
/* Populate typeDefName, if requested */
|
|
188
190
|
%if (not %mf_isBlank(&typeDefNameVar)) %then %do;
|
|
189
|
-
%let &typeDefNameVar = %mf_getvalue(
|
|
190
|
-
|
|
191
|
+
%let &typeDefNameVar = %mf_getvalue(
|
|
192
|
+
&dsItems,value,filter=%quote(p1="items" and p2="name"));
|
|
193
|
+
%if &mdebug %then
|
|
194
|
+
%put DEBUG: &=typeDefNameVar &typeDefNameVar=&&&typeDefNameVar;
|
|
191
195
|
%end;
|
|
192
196
|
|
|
193
197
|
/* Populate mediaType, if requested */
|
|
194
198
|
%if (not %mf_isBlank(&mediaTypeVar)) %then %do;
|
|
195
|
-
%let &mediaTypeVar = %mf_getvalue(
|
|
196
|
-
|
|
199
|
+
%let &mediaTypeVar = %mf_getvalue(
|
|
200
|
+
&dsItems,value,filter=%quote(p1="items" and p2="mediaType"));
|
|
201
|
+
%if &mdebug %then %put DEBUG: &=mediaTypeVar &mediaTypeVar=&&&mediaTypeVar;
|
|
197
202
|
%end;
|
|
198
203
|
|
|
199
204
|
/* Populate properties macro variable, if requested */
|
|
@@ -210,7 +215,8 @@
|
|
|
210
215
|
/* Check for 1+ properties */
|
|
211
216
|
%if ( %mf_nobs(&dsProperties) = 0 ) %then %do;
|
|
212
217
|
%let &propertiesVar = %str();
|
|
213
|
-
%if &mdebug
|
|
218
|
+
%if &mdebug %then %put DEBUG: &SYSMACRONAME - No Viya properties %trim(
|
|
219
|
+
)found for file suffix %str(%')&ext%str(%');
|
|
214
220
|
%end;
|
|
215
221
|
%else %do;
|
|
216
222
|
/* Properties potentially span multiple rows in the input table */
|
|
@@ -240,7 +246,8 @@
|
|
|
240
246
|
end;
|
|
241
247
|
run;
|
|
242
248
|
|
|
243
|
-
%if &mdebug
|
|
249
|
+
%if &mdebug %then
|
|
250
|
+
%put DEBUG: &=propertiesVar &propertiesVar=&&&propertiesVar;
|
|
244
251
|
%end;
|
|
245
252
|
|
|
246
253
|
%end;
|