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

test: Convert and move out of place explain tests #1878

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