@@ -11,151 +11,6 @@ use chrono_tz::Tz;
1111use cubenativeutils:: CubeError ;
1212use std:: rc:: Rc ;
1313
14- #[ cfg( test) ]
15- mod tests {
16- use super :: * ;
17- use crate :: test_fixtures:: cube_bridge:: MockSchema ;
18-
19- #[ test]
20- fn test_yaml_filter_parsing ( ) {
21- use indoc:: indoc;
22-
23- let yaml = indoc ! { "
24- filters:
25- - or:
26- - dimension: visitors.count
27- operator: gt
28- values:
29- - \" 1\"
30- - dimension: visitors.source
31- operator: equals
32- values:
33- - google
34- - dimension: visitors.created_at
35- operator: gte
36- values:
37- - \" 2024-01-01\"
38- " } ;
39- let parsed: YamlBaseQueryOptions = serde_yaml:: from_str ( yaml) . unwrap ( ) ;
40- let filters = parsed. filters . unwrap ( ) ;
41-
42- println ! ( "Filter count: {}" , filters. len( ) ) ;
43- for ( i, filter) in filters. iter ( ) . enumerate ( ) {
44- println ! ( "Filter {}: {:?}" , i, filter) ;
45- }
46-
47- assert_eq ! ( filters. len( ) , 2 ) ;
48- }
49-
50- #[ test]
51- fn test_create_query_options_from_yaml ( ) {
52- use indoc:: indoc;
53-
54- let schema = MockSchema :: from_yaml_file ( "common/visitors.yaml" ) ;
55- let ctx = TestContext :: new ( schema) . unwrap ( ) ;
56-
57- let yaml = indoc ! { "
58- measures:
59- - visitors.count
60- dimensions:
61- - visitors.source
62- order:
63- - id: visitors.count
64- desc: true
65- filters:
66- - or:
67- - dimension: visitors.count
68- operator: gt
69- values:
70- - \" 1\"
71- - dimension: visitors.source
72- operator: equals
73- values:
74- - google
75- - dimension: visitors.created_at
76- operator: gte
77- values:
78- - \" 2024-01-01\"
79- limit: \" 100\"
80- offset: \" 20\"
81- ungrouped: true
82- " } ;
83-
84- let options = ctx. create_query_options_from_yaml ( yaml) ;
85-
86- // Verify measures
87- let measures = options. measures ( ) . unwrap ( ) . unwrap ( ) ;
88- assert_eq ! ( measures. len( ) , 1 ) ;
89-
90- // Verify dimensions
91- let dimensions = options. dimensions ( ) . unwrap ( ) . unwrap ( ) ;
92- assert_eq ! ( dimensions. len( ) , 1 ) ;
93-
94- // Verify order and filters from static_data
95- let static_data = options. static_data ( ) ;
96-
97- let order = static_data. order . as_ref ( ) . unwrap ( ) ;
98- assert_eq ! ( order. len( ) , 1 ) ;
99- assert_eq ! ( order[ 0 ] . id, "visitors.count" ) ;
100- assert_eq ! ( order[ 0 ] . is_desc( ) , true ) ;
101-
102- let filters = static_data. filters . as_ref ( ) . unwrap ( ) ;
103- assert_eq ! ( filters. len( ) , 2 , "Should have 2 filters" ) ;
104-
105- assert ! ( filters[ 0 ] . or. is_some( ) , "First filter should have 'or'" ) ;
106- assert ! (
107- filters[ 0 ] . and. is_none( ) ,
108- "First filter should not have 'and'"
109- ) ;
110-
111- assert ! (
112- filters[ 1 ] . or. is_none( ) ,
113- "Second filter should not have 'or': {:?}" ,
114- filters[ 1 ] . or
115- ) ;
116- assert ! (
117- filters[ 1 ] . and. is_none( ) ,
118- "Second filter should not have 'and': {:?}" ,
119- filters[ 1 ] . and
120- ) ;
121- assert ! (
122- filters[ 1 ] . dimension. is_some( ) ,
123- "Second filter: member={:?}, dimension={:?}, operator={:?}, values={:?}" ,
124- filters[ 1 ] . member,
125- filters[ 1 ] . dimension,
126- filters[ 1 ] . operator,
127- filters[ 1 ] . values
128- ) ;
129-
130- // Verify other fields
131- assert_eq ! ( static_data. limit, Some ( "100" . to_string( ) ) ) ;
132- assert_eq ! ( static_data. offset, Some ( "20" . to_string( ) ) ) ;
133- assert_eq ! ( static_data. ungrouped, Some ( true ) ) ;
134- }
135-
136- #[ test]
137- fn test_create_query_options_minimal ( ) {
138- let schema = MockSchema :: from_yaml_file ( "common/visitors.yaml" ) ;
139- let ctx = TestContext :: new ( schema) . unwrap ( ) ;
140-
141- let yaml = r#"
142- measures:
143- - visitors.count
144- "# ;
145-
146- let options = ctx. create_query_options_from_yaml ( yaml) ;
147- let measures = options. measures ( ) . unwrap ( ) . unwrap ( ) ;
148- assert_eq ! ( measures. len( ) , 1 ) ;
149-
150- // All other fields should be None/empty
151- assert ! ( options. dimensions( ) . unwrap( ) . is_none( ) ) ;
152-
153- let static_data = options. static_data ( ) ;
154- assert ! ( static_data. order. is_none( ) ) ;
155- assert ! ( static_data. filters. is_none( ) ) ;
156- }
157- }
158-
15914/// Test context providing query tools and symbol creation helpers
16015pub struct TestContext {
16116 query_tools : Rc < QueryTools > ,
@@ -324,3 +179,148 @@ impl TestContext {
324179 )
325180 }
326181}
182+
183+ #[ cfg( test) ]
184+ mod tests {
185+ use super :: * ;
186+ use crate :: test_fixtures:: cube_bridge:: MockSchema ;
187+
188+ #[ test]
189+ fn test_yaml_filter_parsing ( ) {
190+ use indoc:: indoc;
191+
192+ let yaml = indoc ! { "
193+ filters:
194+ - or:
195+ - dimension: visitors.count
196+ operator: gt
197+ values:
198+ - \" 1\"
199+ - dimension: visitors.source
200+ operator: equals
201+ values:
202+ - google
203+ - dimension: visitors.created_at
204+ operator: gte
205+ values:
206+ - \" 2024-01-01\"
207+ " } ;
208+ let parsed: YamlBaseQueryOptions = serde_yaml:: from_str ( yaml) . unwrap ( ) ;
209+ let filters = parsed. filters . unwrap ( ) ;
210+
211+ println ! ( "Filter count: {}" , filters. len( ) ) ;
212+ for ( i, filter) in filters. iter ( ) . enumerate ( ) {
213+ println ! ( "Filter {}: {:?}" , i, filter) ;
214+ }
215+
216+ assert_eq ! ( filters. len( ) , 2 ) ;
217+ }
218+
219+ #[ test]
220+ fn test_create_query_options_from_yaml ( ) {
221+ use indoc:: indoc;
222+
223+ let schema = MockSchema :: from_yaml_file ( "common/visitors.yaml" ) ;
224+ let ctx = TestContext :: new ( schema) . unwrap ( ) ;
225+
226+ let yaml = indoc ! { "
227+ measures:
228+ - visitors.count
229+ dimensions:
230+ - visitors.source
231+ order:
232+ - id: visitors.count
233+ desc: true
234+ filters:
235+ - or:
236+ - dimension: visitors.count
237+ operator: gt
238+ values:
239+ - \" 1\"
240+ - dimension: visitors.source
241+ operator: equals
242+ values:
243+ - google
244+ - dimension: visitors.created_at
245+ operator: gte
246+ values:
247+ - \" 2024-01-01\"
248+ limit: \" 100\"
249+ offset: \" 20\"
250+ ungrouped: true
251+ " } ;
252+
253+ let options = ctx. create_query_options_from_yaml ( yaml) ;
254+
255+ // Verify measures
256+ let measures = options. measures ( ) . unwrap ( ) . unwrap ( ) ;
257+ assert_eq ! ( measures. len( ) , 1 ) ;
258+
259+ // Verify dimensions
260+ let dimensions = options. dimensions ( ) . unwrap ( ) . unwrap ( ) ;
261+ assert_eq ! ( dimensions. len( ) , 1 ) ;
262+
263+ // Verify order and filters from static_data
264+ let static_data = options. static_data ( ) ;
265+
266+ let order = static_data. order . as_ref ( ) . unwrap ( ) ;
267+ assert_eq ! ( order. len( ) , 1 ) ;
268+ assert_eq ! ( order[ 0 ] . id, "visitors.count" ) ;
269+ assert ! ( order[ 0 ] . is_desc( ) ) ;
270+
271+ let filters = static_data. filters . as_ref ( ) . unwrap ( ) ;
272+ assert_eq ! ( filters. len( ) , 2 , "Should have 2 filters" ) ;
273+
274+ assert ! ( filters[ 0 ] . or. is_some( ) , "First filter should have 'or'" ) ;
275+ assert ! (
276+ filters[ 0 ] . and. is_none( ) ,
277+ "First filter should not have 'and'"
278+ ) ;
279+
280+ assert ! (
281+ filters[ 1 ] . or. is_none( ) ,
282+ "Second filter should not have 'or': {:?}" ,
283+ filters[ 1 ] . or
284+ ) ;
285+ assert ! (
286+ filters[ 1 ] . and. is_none( ) ,
287+ "Second filter should not have 'and': {:?}" ,
288+ filters[ 1 ] . and
289+ ) ;
290+ assert ! (
291+ filters[ 1 ] . dimension. is_some( ) ,
292+ "Second filter: member={:?}, dimension={:?}, operator={:?}, values={:?}" ,
293+ filters[ 1 ] . member,
294+ filters[ 1 ] . dimension,
295+ filters[ 1 ] . operator,
296+ filters[ 1 ] . values
297+ ) ;
298+
299+ // Verify other fields
300+ assert_eq ! ( static_data. limit, Some ( "100" . to_string( ) ) ) ;
301+ assert_eq ! ( static_data. offset, Some ( "20" . to_string( ) ) ) ;
302+ assert_eq ! ( static_data. ungrouped, Some ( true ) ) ;
303+ }
304+
305+ #[ test]
306+ fn test_create_query_options_minimal ( ) {
307+ let schema = MockSchema :: from_yaml_file ( "common/visitors.yaml" ) ;
308+ let ctx = TestContext :: new ( schema) . unwrap ( ) ;
309+
310+ let yaml = r#"
311+ measures:
312+ - visitors.count
313+ "# ;
314+
315+ let options = ctx. create_query_options_from_yaml ( yaml) ;
316+ let measures = options. measures ( ) . unwrap ( ) . unwrap ( ) ;
317+ assert_eq ! ( measures. len( ) , 1 ) ;
318+
319+ // All other fields should be None/empty
320+ assert ! ( options. dimensions( ) . unwrap( ) . is_none( ) ) ;
321+
322+ let static_data = options. static_data ( ) ;
323+ assert ! ( static_data. order. is_none( ) ) ;
324+ assert ! ( static_data. filters. is_none( ) ) ;
325+ }
326+ }
0 commit comments