diff --git a/lib/src/fnc/array.rs b/lib/src/fnc/array.rs index 4c6a3ea5..533827d7 100644 --- a/lib/src/fnc/array.rs +++ b/lib/src/fnc/array.rs @@ -53,7 +53,7 @@ pub fn flatten((arg,): (Value,)) -> Result { pub fn group((arg,): (Value,)) -> Result { Ok(match arg { - Value::Array(v) => v.uniq().flatten().into(), + Value::Array(v) => v.flatten().uniq().into(), _ => Value::None, }) } diff --git a/lib/tests/function.rs b/lib/tests/function.rs index 709c80e2..b70e2c29 100644 --- a/lib/tests/function.rs +++ b/lib/tests/function.rs @@ -172,6 +172,33 @@ async fn function_array_flatten() -> Result<(), Error> { Ok(()) } +#[tokio::test] +async fn function_array_group() -> Result<(), Error> { + let sql = r#" + RETURN array::group([]); + RETURN array::group(3); + RETURN array::group([ [1,2,3,4], [3,4,5,6] ]); + "#; + 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(), 3); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[]"); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::None; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[1,2,3,4,5,6]"); + assert_eq!(tmp, val); + // + Ok(()) +} + #[tokio::test] async fn function_array_insert() -> Result<(), Error> { let sql = r#"