-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow summation of aggregates (#341)
* 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
1 parent
6a8f990
commit f7e98cf
Showing
6 changed files
with
529 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.