diff --git a/lib/tests/group.rs b/lib/tests/group.rs index 1ea416fa..e92cb686 100644 --- a/lib/tests/group.rs +++ b/lib/tests/group.rs @@ -337,3 +337,125 @@ async fn select_multi_aggregate() -> Result<(), Error> { // Ok(()) } + +#[tokio::test] +async fn select_multi_aggregate_composed() -> Result<(), Error> { + let sql = " + CREATE test:1 SET group = 1, one = 1.7, two = 2.4; + CREATE test:2 SET group = 1, one = 4.7, two = 3.9; + CREATE test:3 SET group = 2, one = 3.2, two = 9.7; + CREATE test:4 SET group = 2, one = 4.4, two = 3.0; + SELECT group, math::sum(math::floor(one)) AS one, math::sum(math::floor(two)) AS two FROM test GROUP BY group; + SELECT group, math::sum(math::round(one)) AS one, math::sum(math::round(two)) AS two FROM test GROUP BY group; + SELECT group, math::sum(math::ceil(one)) AS one, math::sum(math::ceil(two)) AS two FROM test GROUP BY group; + "; + let dbs = Datastore::new("memory").await?; + let ses = Session::for_kv().with_ns("test").with_db("test"); + let res = &mut dbs.execute(&sql, &ses, None, false).await?; + assert_eq!(res.len(), 7); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:1, + group: 1, + one: 1.7, + two: 2.4, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:2, + group: 1, + one: 4.7, + two: 3.9, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:3, + group: 2, + one: 3.2, + two: 9.7, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:4, + group: 2, + one: 4.4, + two: 3.0, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + group: 1, + one: 5, + two: 5, + }, + { + group: 2, + one: 7, + two: 12, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + group: 1, + one: 7, + two: 6, + }, + { + group: 2, + one: 7, + two: 13, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + group: 1, + one: 7, + two: 7, + }, + { + group: 2, + one: 9, + two: 14, + } + ]", + ); + assert_eq!(tmp, val); + // + Ok(()) +}