()
| 191 | |
| 192 | #[test] |
| 193 | fn 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] |
| 238 | fn array_length_function() { |
nothing calls this directly
no test coverage detected