Skip to content

Commit

Permalink
feat: Allow summation of aggregates (#341)
Browse files Browse the repository at this point in the history
* Remove previously done todo

* Refactor source collection var

* Refactor source property

* Remove strange variable aliasing

* Refactor isFloat property

* Add summation of aggregates support

* Remove else clause (PR request)
  • Loading branch information
AndrewSisley authored Apr 20, 2022
1 parent 6a8f990 commit f7e98cf
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 50 deletions.
99 changes: 99 additions & 0 deletions db/tests/query/simple/with_group_count_sum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/db/tests"
)

func TestQuerySimpleWithGroupByStringWithInnerGroupBooleanAndSumOfCount(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with group by string, with child group by boolean, and sum of count",
Query: `query {
users(groupBy: [Name]) {
Name
_sum(field: {_group: _count})
_group (groupBy: [Verified]){
Verified
_count(field: _group)
}
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 25,
"Verified": true
}`),
(`{
"Name": "John",
"Age": 32,
"Verified": true
}`),
(`{
"Name": "John",
"Age": 34,
"Verified": false
}`),
(`{
"Name": "Carlo",
"Age": 55,
"Verified": true
}`),
(`{
"Name": "Alice",
"Age": 19,
"Verified": false
}`)},
},
Results: []map[string]interface{}{
{
"Name": "John",
"_sum": int64(3),
"_group": []map[string]interface{}{
{
"Verified": true,
"_count": int(2),
},
{
"Verified": false,
"_count": int(1),
},
},
},
{
"Name": "Alice",
"_sum": int64(1),
"_group": []map[string]interface{}{
{
"Verified": false,
"_count": int(1),
},
},
},
{
"Name": "Carlo",
"_sum": int64(1),
"_group": []map[string]interface{}{
{
"Verified": true,
"_count": int(1),
},
},
},
},
}

executeTestCase(t, test)
}
Loading

0 comments on commit f7e98cf

Please sign in to comment.