Loading...
Searching...
No Matches
viewdata.test.3.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing public/viewdata service full table search semantics
4 @details The viewer's search box runs a full table search through
5 %mp_searchdata. A character search is a partial (CONTAINS) match against
6 every character column of the table and is case sensitive; a numeric search
7 is an exact match against every numeric column.
8
9 The fixture below holds both cases of the same substring so the assertions
10 can show the behaviour in both directions - a value with a capital letter is
11 not found by a lowercase search and vice versa.
12
13 <h4> SAS Macros </h4>
14 @li mf_getuniquefileref.sas
15 @li mf_getuniquelibref.sas
16 @li mp_assert.sas
17 @li mx_execute.sas
18
19 @sasjslint {"maxLineLength": 133}
20
21**/
22
23%let _program=&appLoc/services/public/viewdata;
24
25/* deterministic fixture - mixed case, and a value that only exists in the
26 second character column, so the search must cover every character column */
27data &dclib..mpe_x_search;
28 length NAME $32 NOTES $64;
29 name='Selkie'; qty=12345; notes='grey seal folklore'; output;
30 name='Vampire squid'; qty=23456; notes='deep sea cephalopod'; output;
31 name='siphonophore'; qty=34567; notes='colonial organism'; output;
32 name='Smithson'; qty=45678; notes='capital S surname'; output;
33 name='Goldsmith'; qty=56789; notes='lowercase substring'; output;
34run;
35
36/**
37 * Run one full table search and assert the row count the viewer would show.
38 */
39%macro search(searchtype,searchval,expected,desc);
40%local f1 outlib nobs;
41%let f1=%mf_getuniquefileref();
42%let outlib=%mf_getuniquelibref(prefix=web);
43data _null_;
44 file &f1 termstr=crlf;
45 put 'LIBDS:$char41. FILTER_RK:best. SEARCHTYPE:$char4. SEARCHVAL:$char100.';
46 put "&dclib..MPE_X_SEARCH,-1,&searchtype,&searchval";
47run;
48%mx_execute(&_program,
49 viyacontext=&defaultcontext,
50 inputfiles=&f1:SASControlTable ,
51 outlib=&outlib,
52 mdebug=&sasjs_mdebug
53)
54%let nobs=0;
55data _null_;
56 set &outlib..sasparams;
57 putlog (_all_)(=);
58 call symputx('nobs',nobs);
59run;
60%mp_assert(
61 iftrue=(&nobs=&expected),
62 desc=%str(&desc (&searchtype "%superq(searchval)" returned &nobs rows, expected &expected)),
63 outds=work.test_results
64)
65%mend search;
66
67/* a character search matches part of a value, in the same case */
68%search(CHAR,Selkie,1,Checking a same-case partial match returns the row)
69%search(CHAR,quid,1,Checking a partial match on the middle of a value)
70%search(CHAR,seal,1,Checking the search covers every character column)
71
72/* the same term in another case does not match */
73%search(CHAR,selkie,0,Checking a lowercase search does not match a capital S)
74%search(CHAR,SELKIE,0,Checking an uppercase search does not match mixed case)
75%search(CHAR,Quid,0,Checking a capital Q does not match a lowercase value)
76
77/* a search in the case the value is stored in finds it, whether the match
78 starts the value or sits inside it */
79%search(CHAR,Smith,1,Checking Smith finds Smithson)
80%search(CHAR,smith,1,Checking smith finds Goldsmith)
81
82/* a numeric search is an exact match, not a partial one */
83%search(NUM,12345,1,Checking an exact numeric search returns the row)
84%search(NUM,1234,0,Checking a partial numeric search returns nothing)
85
86/* a search that matches more rows than the web view cap returns the cap,
87 and reports the same number of rows as it returns */
88data &dclib..mpe_x_cap;
89 length txt $24;
90 do i=1 to 600;
91 txt='needle'!!cats(i);
92 output;
93 end;
94run;
95
96%let f1=%mf_getuniquefileref();
97%let outlib=%mf_getuniquelibref(prefix=web);
98data _null_;
99 file &f1 termstr=crlf;
100 put 'LIBDS:$char41. FILTER_RK:best. SEARCHTYPE:$char4. SEARCHVAL:$char100.';
101 put "&dclib..MPE_X_CAP,-1,CHAR,needle";
102run;
103%mx_execute(&_program,
104 viyacontext=&defaultcontext,
105 inputfiles=&f1:SASControlTable ,
106 outlib=&outlib,
107 mdebug=&sasjs_mdebug
108)
109%let capnobs=0;
110%let capmax=0;
111data _null_;
112 set &outlib..sasparams;
113 putlog (_all_)(=);
114 call symputx('capnobs',nobs);
115 call symputx('capmax',maxrows);
116run;
117%let caprows=0;
118proc sql noprint;
119 select count(*) into :caprows from &outlib..viewdata;
120quit;
121%mp_assert(
122 iftrue=(&caprows=&capnobs and &capnobs gt 0 and &capnobs le &capmax),
123 desc=%str(Checking a search beyond the cap returns as many rows as it reports (&capnobs reported, &caprows returned, cap &capmax)),
124 outds=work.test_results
125)