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: Add ability to explain sumNode attribute(s). #559

Merged
merged 3 commits into from
Jun 30, 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
29 changes: 28 additions & 1 deletion query/graphql/planner/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,34 @@ func (n *sumNode) Source() planNode { return n.plan }
// Explain method returns a map containing all attributes of this node that
// are to be explained, subscribes / opts-in this node to be an explainablePlanNode.
func (n *sumNode) Explain() (map[string]interface{}, error) {
return map[string]interface{}{}, nil
sourceExplanations := make([]map[string]interface{}, len(n.aggregateMapping))

for i, source := range n.aggregateMapping {
explainerMap := map[string]interface{}{}

// Add the filter attribute if it exists.
if source.Filter == nil || source.Filter.ExternalConditions == nil {
explainerMap[filterLabel] = nil
} else {
explainerMap[filterLabel] = source.Filter.ExternalConditions
}

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought (non-blocking): I'm not sure this should be present - it should only reach here if summing an inline array, which doesn't have this prop available in the query syntax. Your call though, no strong feelings.

}

sourceExplanations[i] = explainerMap
}

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

func (n *sumNode) Next() (bool, error) {
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/query/explain/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ var bookAuthorGQLSchema = (`
type article {
name: String
author: author
pages: Int
}

type book {
name: String
author: author
pages: Int
chapterPages: [Int]
}

type author {
Expand Down
Loading