Skip to content

Commit

Permalink
feat: Update countNode explanation to be consistent. (#600)
Browse files Browse the repository at this point in the history
Resolves #599 

- Description: Rename `sourceProperty` to `fieldName` to be consistent with `sumNode` and more in harmony with the post document restructure changes.
  • Loading branch information
shahzadlone authored Jul 9, 2022
1 parent e6b41d7 commit 16084c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions query/graphql/planner/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ func (n *countNode) Explain() (map[string]interface{}, error) {
explainerMap[filterLabel] = source.Filter.ExternalConditions
}

// Add the source property.
explainerMap["sourceProperty"] = source.Field.Name
// Add the main field name.
explainerMap[fieldNameLabel] = source.Field.Name

sourceExplanations[i] = explainerMap
}

return map[string]interface{}{
"sources": sourceExplanations,
sourcesLabel: sourceExplanations,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions query/graphql/planner/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ var (
)

const (
childFieldNameLabel = "childFieldName"
collectionIDLabel = "collectionID"
collectionNameLabel = "collectionName"
dataLabel = "data"
fieldNameLabel = "fieldName"
filterLabel = "filter"
idsLabel = "ids"
sourcesLabel = "sources"
spansLabel = "spans"
)

Expand Down
8 changes: 4 additions & 4 deletions query/graphql/planner/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,20 @@ func (n *sumNode) Explain() (map[string]interface{}, error) {
}

// Add the main field name.
explainerMap["fieldName"] = source.Field.Name
explainerMap[fieldNameLabel] = source.Field.Name

// Add the child field name if it exists.
if source.ChildTarget.HasValue {
explainerMap["childFieldName"] = source.ChildTarget.Name
explainerMap[childFieldNameLabel] = source.ChildTarget.Name
} else {
explainerMap["childFieldName"] = nil
explainerMap[childFieldNameLabel] = nil
}

sourceExplanations[i] = explainerMap
}

return map[string]interface{}{
"sources": sourceExplanations,
sourcesLabel: sourceExplanations,
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions tests/integration/query/explain/with_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func TestExplainQueryOneToManyWithACount(t *testing.T) {
},
},

// ----> selectTopNode (explainable but no-attributes)
// ----> countNode (explainable)
// ----> selectNode (explainable)
// ----> selectTopNode (explainable but no-attributes)
// ----> countNode (explainable)
// ----> selectNode (explainable)
// ----> typeIndexJoin (explainable)
// ----> typeJoinMany (non-explainable)
// ----> scanNode (explainable)
Expand All @@ -104,8 +104,8 @@ func TestExplainQueryOneToManyWithACount(t *testing.T) {
"countNode": dataMap{
"sources": []dataMap{
{
"filter": nil,
"sourceProperty": "books",
"filter": nil,
"fieldName": "books",
},
},
"selectNode": dataMap{
Expand Down

0 comments on commit 16084c8

Please sign in to comment.