Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle limit and offset in sub groups (#440)
- Loading branch information
1 parent
d36ffc8
commit 5e3a3b8
Showing
4 changed files
with
358 additions
and
0 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 TestQuerySimpleWithGroupByNumberWithGroupLimitAndOffset(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number, no children, rendered, limited and offset group", | ||
Query: `query { | ||
users(groupBy: [Age]) { | ||
Age | ||
_group(limit: 1, offset: 1) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(32), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "John", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"Age": uint64(19), | ||
"_group": []map[string]interface{}{}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQuerySimpleWithGroupByNumberWithLimitAndOffsetAndWithGroupLimitAndOffset(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number with limit and offset, no children, rendered, limited and offset group", | ||
Query: `query { | ||
users(groupBy: [Age], limit: 1, offset: 1) { | ||
Age | ||
_group(limit: 1, offset: 1) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(19), | ||
"_group": []map[string]interface{}{}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
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,228 @@ | ||
// 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 TestQuerySimpleWithGroupByNumberWithGroupLimit(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number, no children, rendered, limited group", | ||
Query: `query { | ||
users(groupBy: [Age]) { | ||
Age | ||
_group(limit: 1) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(32), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "Bob", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"Age": uint64(19), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "Alice", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQuerySimpleWithGroupByNumberWithMultipleGroupsWithDifferentLimits(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number, no children, multiple rendered, limited groups", | ||
Query: `query { | ||
users(groupBy: [Age]) { | ||
Age | ||
G1: _group(limit: 1) { | ||
Name | ||
} | ||
G2: _group(limit: 2) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(32), | ||
"G1": []map[string]interface{}{ | ||
{ | ||
"Name": "Bob", | ||
}, | ||
}, | ||
"G2": []map[string]interface{}{ | ||
{ | ||
"Name": "Bob", | ||
}, | ||
{ | ||
"Name": "John", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"Age": uint64(19), | ||
"G1": []map[string]interface{}{ | ||
{ | ||
"Name": "Alice", | ||
}, | ||
}, | ||
"G2": []map[string]interface{}{ | ||
{ | ||
"Name": "Alice", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQuerySimpleWithGroupByNumberWithLimitAndGroupWithHigherLimit(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number and limit, no children, rendered, limited group", | ||
Query: `query { | ||
users(groupBy: [Age], limit: 1) { | ||
Age | ||
_group(limit: 2) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(32), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "Bob", | ||
}, | ||
{ | ||
"Name": "John", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQuerySimpleWithGroupByNumberWithLimitAndGroupWithLowerLimit(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "Simple query with group by number and limit, no children, rendered, limited group", | ||
Query: `query { | ||
users(groupBy: [Age], limit: 2) { | ||
Age | ||
_group(limit: 1) { | ||
Name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
0: { | ||
(`{ | ||
"Name": "John", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Bob", | ||
"Age": 32 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 19 | ||
}`), | ||
(`{ | ||
"Name": "Alice", | ||
"Age": 42 | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Age": uint64(32), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "Bob", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"Age": uint64(42), | ||
"_group": []map[string]interface{}{ | ||
{ | ||
"Name": "Alice", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
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
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