Skip to content

Commit

Permalink
test: Convert and move out of place explain tests (sourcenetwork#1878)
Browse files Browse the repository at this point in the history
## Relevant issue(s)
Resolves sourcenetwork#1547 

## Description
- Move some explain tests that should have been under the explain
directory, they seemed to have been missed converting to the new explain
setup.
  • Loading branch information
shahzadlone authored Sep 14, 2023
1 parent 94790ef commit 4c88313
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 325 deletions.
46 changes: 46 additions & 0 deletions tests/integration/explain/default/with_average_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,49 @@ func TestDefaultExplainRequestWithAverageOnMultipleJoinedFieldsWithFilter(t *tes

explainUtils.ExecuteTestCase(t, test)
}

// This test asserts that only a single index join is used (not parallelNode) because the
// _avg reuses the rendered join as they have matching filters (average adds a ne nil filter).
func TestDefaultExplainRequestOneToManyWithAverageAndChildNeNilFilterSharesJoinField(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (default) 1-to-M relation request from many side with average filter shared.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain {
Author {
name
_avg(books: {field: rating})
books(filter: {rating: {_ne: null}}){
name
}
}
}`,

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"averageNode": dataMap{
"countNode": dataMap{
"sumNode": dataMap{
"selectNode": dataMap{
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
},
},
},
},
},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
91 changes: 91 additions & 0 deletions tests/integration/explain/default/with_count_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,94 @@ func TestDefaultExplainRequestWithCountOnOneToManyJoinedFieldWithManySources(t *

explainUtils.ExecuteTestCase(t, test)
}

// This test asserts that only a single index join is used (not parallelNode) because the
// _count reuses the rendered join as they have matching filters.
func TestDefaultExplainRequestOneToManyWithCountWithFilterAndChildFilterSharesJoinField(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (default) 1-to-M relation request from many side with count filter shared.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain {
Author {
name
_count(books: {filter: {rating: {_ne: null}}})
books(filter: {rating: {_ne: null}}){
name
}
}
}`,

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"countNode": dataMap{
"selectNode": dataMap{
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
},
},
},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

// This test asserts that two joins are used (with parallelNode) because _count cannot
// reuse the rendered join as they dont have matching filters.
func TestDefaultExplainRequestOneToManyWithCountAndChildFilterDoesNotShareJoinField(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (default) 1-to-M relation request from many side with count filter not shared.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain {
Author {
name
_count(books: {})
books(filter: {rating: {_ne: null}}){
name
}
}
}`,

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"countNode": dataMap{
"selectNode": dataMap{
"parallelNode": []dataMap{
{
"typeIndexJoin": normalTypeJoinPattern,
},
{
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
},
},
},
},
},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
1 change: 1 addition & 0 deletions tests/integration/explain/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var SchemaForExplainTests = testUtils.SchemaUpdate{
type Book {
name: String
author: Author
rating: Float
pages: Int
chapterPages: [Int!]
}
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/query/one_to_many/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

type dataMap = map[string]any

var bookAuthorGQLSchema = (`
type Book {
name: String
Expand Down
116 changes: 0 additions & 116 deletions tests/integration/query/one_to_many/with_average_filter_test.go

This file was deleted.

Loading

0 comments on commit 4c88313

Please sign in to comment.