Loading...
Searching...
No Matches
viewdata.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing public/viewdata service for filtered rowcount
4 @details We had a situation where the row count for a filtered view was
5 the count for the entire table, not the filtered view.
6
7 This test first makes a filter, then applies to to a table, and checks the
8 rowcount.
9
10 <h4> SAS Macros </h4>
11 @li mp_assert.sas
12 @li mx_execute.sas
13 @li mf_existds.sas
14 @li mf_getuniquefileref.sas
15 @li mp_filterstore.sas
16
17 @sasjslint {"maxLineLength": 100}
18
19**/
20
21/* first, ensure the table has the 3 records we need */
22proc sql;
23delete from &dclib..mpe_x_test where PRIMARY_KEY_FIELD in (1,2,3);
24data work.append;
25 set &dclib..mpe_x_test;
26 do PRIMARY_KEY_FIELD=1,2,3;
27 output;
28 end;
29 stop;
30run;
31proc append base=&dclib..mpe_x_test data=work.append;
32run;
33
34/* now, validate the filter and get the RK */
35%let _program=&appLoc/services/public/validatefilter;
36
37/* create filter */
38%let f1=%mf_getuniquefileref();
39data _null_;
40 file &f1 termstr=crlf;
41 put 'filter_table:$41.';
42 put "&dclib..MPE_X_TEST";
43run;
44%let f2=%mf_getuniquefileref();
45data _null_;
46 file &f2 termstr=crlf;
47 infile datalines4 dsd;
48 input;
49 put _infile_;
50datalines4;
51GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32. OPERATOR_NM:$10. RAW_VALUE:$4000.
52AND,AND,1,PRIMARY_KEY_FIELD,IN,"(1,2,3)"
53;;;;
54run;
55%mx_execute(&_program,
56 viyacontext=&defaultcontext,
57 inputfiles=&f1:iwant &f2:filterquery,
58 outlib=web1
59)
60data result;
61 set web1.result;
62 putlog (_all_)(=);
63 call symputx('filter_rk',filter_rk);
64run;
65
66
67/* now use this to filter a viewtable for three records */
68
69%let _program=&appLoc/services/public/viewdata;
70
71/* filter for one record */
72%let f3=%mf_getuniquefileref();
73data _null_;
74 file &f3 termstr=crlf;
75 put 'LIBDS:$char19. FILTER_RK:best.';
76 put "&dclib..MPE_X_TEST,&filter_rk";
77run;
78
79%mx_execute(&_program,
80 viyacontext=&defaultcontext,
81 inputfiles=&f3:SASControlTable ,
82 outlib=web2,
83 outref=rawfile,
84 mdebug=1
85)
86%let nobs=0;
87data sasparams;
88 set web2.sasparams;
89 putlog (_all_)(=);
90 call symputx('nobs',nobs);
91run;
92
93%mp_assert(
94 iftrue=(&nobs=3),
95 desc=Checking the view table has 3 records returned,
96 outds=work.test_results
97)
98
99%put viewdata raw:;
100data _null_;
101 infile rawfile;
102 input;
103 putlog _infile_;
104run;
105
106
107
108/**
109 * A truncated comparison is a data step operator with no colon form in SQL,
110 * so the count query has to be answered with its SQL spelling (EQT / NET).
111 * A missing character value is blanks, so it is carried by ^=: and not by =:
112 * - that is the pair the two cases below pin.
113 */
114data &dclib..vd_trunc;
115 length name $8;
116 name=''; output;
117 name='this is'; output;
118 name='other'; output;
119run;
120
121/**
122 * Filter the scratch table with a truncated operator and read NOBS back
123 * @param [in] op The operator to store (=: or ^=:)
124 * @param [in] expect The row count the data step rule produces
125 * @param [in] outlib The libref to receive the response
126 * @param [in] desc Assertion description
127 */
128%macro vd_trunc(op,expect,outlib,desc);
129 %local fref nobs;
130 data work.inquery;
131 length GROUP_LOGIC $3 SUBGROUP_LOGIC $3 SUBGROUP_ID 8
132 VARIABLE_NM $32 OPERATOR_NM $10 RAW_VALUE $4000;
133 GROUP_LOGIC='AND';
134 SUBGROUP_LOGIC='AND';
135 SUBGROUP_ID=1;
136 VARIABLE_NM='NAME';
137 OPERATOR_NM="&op";
138 RAW_VALUE="'this'";
139 output;
140 run;
141 %mp_filterstore(
142 libds=&dclib..VD_TRUNC,
143 filter_summary=&dc_libref..mpe_filteranytable,
144 filter_detail=&dc_libref..mpe_filtersource,
145 lock_table=&dc_libref..mpe_lockanytable,
146 maxkeytable=&dc_libref..mpe_maxkeyvalues,
147 queryds=work.inquery,
148 outresult=work.vdresult,
149 outquery=work.vdquery
150 )
151 data _null_;
152 set work.vdresult;
153 call symputx('vd_rk',filter_rk,'G');
154 run;
155
156 %let fref=%mf_getuniquefileref();
157 data _null_;
158 file &fref termstr=crlf;
159 put 'LIBDS:$char19. FILTER_RK:best.';
160 put "&dclib..VD_TRUNC,&vd_rk";
161 run;
162 %mx_execute(&_program,
163 viyacontext=&defaultcontext,
164 inputfiles=&fref:SASControlTable,
165 outlib=&outlib,
166 mdebug=1
167 )
168
169 %let nobs=0;
170 %if %mf_existds(&outlib..sasparams) %then %do;
171 data _null_;
172 set &outlib..sasparams;
173 call symputx('nobs',nobs,'l');
174 run;
175 %end;
176 %mp_assert(
177 iftrue=(&nobs=&expect),
178 desc=&desc - NOBS=&nobs expect=&expect,
179 outds=work.test_results
180 )
181%mend vd_trunc;
182
183%vd_trunc(=:,1,web3,Test 2 - =: counts and returns its truncated match)
184%vd_trunc(^=:,2,web4,Test 3 - ^=: counts and returns the complement)