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 explaination of spans for scanNode. #492

Merged
merged 2 commits into from
Jun 3, 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
2 changes: 1 addition & 1 deletion query/graphql/planner/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
dataLabel = "data"
filterLabel = "filter"
idsLabel = "ids"
// spansLabel = "spans"
spansLabel = "spans"
)

// buildExplainGraph builds the explainGraph from the given top level plan.
Expand Down
19 changes: 16 additions & 3 deletions query/graphql/planner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ func (n *scanNode) Close() error {

func (n *scanNode) Source() planNode { return nil }

// explainSpans explains the spans attribute.
func (n *scanNode) explainSpans() []map[string]interface{} {
spansExplainer := []map[string]interface{}{}
for _, span := range n.spans {
spanExplainer := map[string]interface{}{
"start": span.Start().ToString(),
"end": span.End().ToString(),
}

spansExplainer = append(spansExplainer, spanExplainer)
}

return spansExplainer
}

// 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 *scanNode) Explain() (map[string]interface{}, error) {
Expand All @@ -127,10 +142,8 @@ func (n *scanNode) Explain() (map[string]interface{}, error) {
explainerMap[collectionNameLabel] = n.desc.Name
explainerMap[collectionIDLabel] = n.desc.IDString()

// @TODO: {defradb/issues/474} Add explain attributes.
// Add the spans attribute.
// explainerMap[spansLabel] = n.spans
// Add the index attribute.
explainerMap[spansLabel] = n.explainSpans()

return explainerMap, nil
}
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/query/explain/with_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func TestExplainQueryOneToManyWithACount(t *testing.T) {
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
Expand Down Expand Up @@ -186,6 +192,12 @@ func TestExplainQueryOneToManyMultipleWithCounts(t *testing.T) {
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
Expand All @@ -195,6 +207,12 @@ func TestExplainQueryOneToManyMultipleWithCounts(t *testing.T) {
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
Expand Down
Loading