Skip to content

Commit

Permalink
PR: Add the explain tests converted to new setup
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Sep 14, 2023
1 parent 9d1af8b commit dfc2d24
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 0 deletions.
127 changes: 127 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,130 @@ 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,
},
},
},
},
},
},
},
},

ExpectedFullGraph: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"averageNode": dataMap{
"countNode": dataMap{
"sources": []dataMap{
{
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"fieldName": "books",
},
},
"sumNode": dataMap{
"sources": []dataMap{
{
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"fieldName": "books",
"childFieldName": "rating",
},
},
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"filter": nil,
"collectionID": "3",
"collectionName": "Author",
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
"subTypeName": "books",
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"scanNode": dataMap{
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"collectionID": "2",
"collectionName": "Book",
"spans": []dataMap{
{
"start": "/2",
"end": "/3",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
262 changes: 262 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,265 @@ 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,
},
},
},
},
},
},

ExpectedFullGraph: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"countNode": dataMap{
"sources": []dataMap{
{
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"fieldName": "books",
},
},
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"filter": nil,
"collectionID": "3",
"collectionName": "Author",
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
"subTypeName": "books",
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"scanNode": dataMap{
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"collectionID": "2",
"collectionName": "Book",
"spans": []dataMap{
{
"start": "/2",
"end": "/3",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}

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,
},
},
},
},
},
},
},
},

ExpectedFullGraph: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"countNode": dataMap{
"sources": []dataMap{
{
"fieldName": "books",
"filter": nil,
},
},
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"parallelNode": []dataMap{
{
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "Author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
"subTypeName": "books",
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"scanNode": dataMap{
"collectionID": "2",
"collectionName": "Book",
"filter": dataMap{
"rating": dataMap{
"_ne": nil,
},
},
"spans": []dataMap{
{
"start": "/2",
"end": "/3",
},
},
},
},
},
},
},
},
{
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "Author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
"subTypeName": "books",
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"_keys": nil,
"filter": nil,
"scanNode": dataMap{
"collectionID": "2",
"collectionName": "Book",
"filter": nil,
"spans": []dataMap{
{
"start": "/2",
"end": "/3",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
Loading

0 comments on commit dfc2d24

Please sign in to comment.