Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make topLevelNode explainable #737

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions query/graphql/planner/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (n *topLevelNode) Source() planNode {
return nil
}

func (n *topLevelNode) Explain() (map[string]any, error) {
return map[string]any{}, nil
}

func (n *topLevelNode) Next() (bool, error) {
if n.isdone {
return false, nil
Expand Down
106 changes: 106 additions & 0 deletions tests/integration/query/explain/top_with_average_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 TestExplainTopLevelAverageQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level average query.",

Query: `query @explain {
_avg(
author: {
field: age
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 28
}`,
`{
"name": "Bob",
"verified": true,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelAverageQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level average query with filter.",
Query: `query @explain {
_avg(
author: {
field: age,
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": false,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}
102 changes: 102 additions & 0 deletions tests/integration/query/explain/top_with_count_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 TestExplainTopLevelCountQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level count query.",

Query: `query @explain {
_count(author: {})
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": true,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelCountQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level count query with filter.",

Query: `query @explain {
_count(
author: {
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": true,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}
107 changes: 107 additions & 0 deletions tests/integration/query/explain/top_with_sum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 TestExplainTopLevelSumQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level sum query.",

Query: `query @explain {
_sum(
author: {
field: age
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": true,
"age": 21
}`,
`{
"name": "Bob",
"verified": true,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelSumQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level sum query with filter.",

Query: `query @explain {
_sum(
author: {
field: age,
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": true,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}