From 649707aa9a825a0818729ff3158664bed08c5710 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Thu, 13 Apr 2023 21:05:34 +0500 Subject: [PATCH] fix: Explain of _group with dockeys filter to be []string (#1348) 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. --- planner/group.go | 3 +- .../explain/default/group_with_dockey_test.go | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/planner/group.go b/planner/group.go index 1405998545..e87d753d14 100644 --- a/planner/group.go +++ b/planner/group.go @@ -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 } diff --git a/tests/integration/explain/default/group_with_dockey_test.go b/tests/integration/explain/default/group_with_dockey_test.go index 6c6eb9c3c8..d4cd816f36 100644 --- a/tests/integration/explain/default/group_with_dockey_test.go +++ b/tests/integration/explain/default/group_with_dockey_test.go @@ -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.",