MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / array_agg_aggregate

Function array_agg_aggregate

nodedb/tests/executor_tests/test_array_ops.rs:193–235  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191
192#[test]
193fn array_agg_aggregate() {
194 let (mut core, mut tx, mut rx, _dir) = make_core();
195 seed(&mut core, &mut tx, &mut rx);
196
197 // GROUP BY brand, ARRAY_AGG(color).
198 let payload = send_ok(
199 &mut core,
200 &mut tx,
201 &mut rx,
202 PhysicalPlan::Query(QueryOp::Aggregate {
203 collection: "products".into(),
204 group_by: vec!["brand".into()],
205 aggregates: vec![AggregateSpec {
206 function: "array_agg".into(),
207 alias: "array_agg_color".into(),
208 user_alias: None,
209 field: "color".into(),
210 expr: None,
211 }],
212 filters: Vec::new(),
213 having: Vec::new(),
214 limit: 100,
215 sub_group_by: Vec::new(),
216 sub_aggregates: Vec::new(),
217 grouping_sets: Vec::new(),
218 sort_keys: Vec::new(),
219 }),
220 );
221
222 let v = payload_value(&payload);
223 let rows: Vec<serde_json::Value> = if let serde_json::Value::Array(arr) = v {
224 arr
225 } else {
226 serde_json::from_str(&payload_json(&payload)).unwrap_or_default()
227 };
228
229 // Nike has 2 products: colors ["red", "blue"].
230 let nike = rows.iter().find(|r| r["brand"] == "Nike").unwrap();
231 let colors = nike["array_agg_color"].as_array().unwrap();
232 assert_eq!(colors.len(), 2);
233 assert!(colors.contains(&serde_json::json!("red")));
234 assert!(colors.contains(&serde_json::json!("blue")));
235}
236
237#[test]
238fn array_length_function() {

Callers

nothing calls this directly

Calls 9

seedFunction · 0.85
QueryClass · 0.85
payload_valueFunction · 0.85
as_arrayMethod · 0.80
make_coreFunction · 0.70
send_okFunction · 0.70
payload_jsonFunction · 0.70
findMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected