Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow summation of aggregates #341

Merged
merged 7 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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