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