Skip to content

Commit

Permalink
fix: Explain of _group with dockeys filter to be []string (#1348)
Browse files Browse the repository at this point in the history
Fixes the bug in simple explain attribute of group node that was causing `"docKeys":(func() []string)0x132ea40`.
But we expected it to be `"docKeys": []string{"bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"}`.
Also add a test for it.
  • Loading branch information
shahzadlone authored Apr 13, 2023
1 parent 9ff3eb6 commit a5cf397
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
3 changes: 1 addition & 2 deletions planner/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ func (n *groupNode) simpleExplain() (map[string]any, error) {
c := child.Targetable

// Get targetable attribute(s) of this child.

if c.DocKeys.HasValue() {
childExplainGraph["docKeys"] = c.DocKeys.Value
childExplainGraph["docKeys"] = c.DocKeys.Value()
} else {
childExplainGraph["docKeys"] = nil
}
Expand Down
78 changes: 78 additions & 0 deletions tests/integration/explain/default/group_with_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,84 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestExplainQueryWithDockeysFilterOnInnerGroupBy(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Explain query with a dockeys filter on inner _group.",

Request: `query @explain {
author(
groupBy: [age]
) {
age
_group(dockeys: ["bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"]) {
name
}
}
}`,

Docs: map[int][]string{
//authors
2: {
// dockey: "bae-21a6ad4a-1cd8-5613-807c-a90c7c12f880"
`{
"name": "John Grisham",
"age": 12
}`,

// dockey: "bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"
`{
"name": "Cornelia Funke",
"age": 20
}`,

// dockey: "bae-4ea9d148-13f3-5a48-a0ef-9ffd344caeed"
`{
"name": "John's Twin",
"age": 65
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"groupNode": dataMap{
"childSelects": []dataMap{
{
"collectionName": "author",
"docKeys": []string{"bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"},
"filter": nil,
"groupBy": nil,
"limit": nil,
"orderBy": nil,
},
},
"groupByFields": []string{"age"},
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainQueryWithDockeyOnParentGroupBy(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Explain query with a dockey on parent groupBy.",
Expand Down

0 comments on commit a5cf397

Please sign in to comment.