Skip to content

Commit

Permalink
wip: Add tests for groupBy explain cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Jul 23, 2022
1 parent dd80b97 commit 98a5d89
Show file tree
Hide file tree
Showing 6 changed files with 1,829 additions and 0 deletions.
161 changes: 161 additions & 0 deletions tests/integration/query/explain/group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// 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 test_explain

import (
"testing"

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

func TestExplainSimpleGroupByOnParent(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain a grouping on parent.",
Query: `query @explain {
author (groupBy: [age]) {
age
_group {
name
}
}
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John Grisham",
"age": 65
}`,

`{
"name": "Cornelia Funke",
"age": 62
}`,

`{
"name": "John's Twin",
"age": 65
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"groupNode": dataMap{
"groupByFields": []string{"age"},
"childSelects": []dataMap{
{
"collectionName": "author",
"docKeys": nil,
"groupBy": nil,
"limit": nil,
"orderBy": nil,
"filter": nil,
},
},
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainGroupByTwoFieldsOnParent(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain a grouping by two fields.",
Query: `query @explain {
author (groupBy: [age, name]) {
age
_group {
name
}
}
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John Grisham",
"age": 65
}`,

`{
"name": "Cornelia Funke",
"age": 62
}`,

`{
"name": "John's Twin",
"age": 65
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"groupNode": dataMap{
"groupByFields": []string{"age", "name"},
"childSelects": []dataMap{
{
"collectionName": "author",
"docKeys": nil,
"groupBy": nil,
"limit": nil,
"orderBy": nil,
"filter": nil,
},
},
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
},
},
},
},
}

executeTestCase(t, test)
}
Loading

0 comments on commit 98a5d89

Please sign in to comment.