Skip to content

Commit

Permalink
test(i): Fix debug explain test-framework with similarity (#3473)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #3471 

## Description
- Add compile time check to ensure similarity node is explainable.
- Fix debug explain test-framework with similarity query
- Add a debug explain test

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?
CI
  • Loading branch information
shahzadlone authored Feb 20, 2025
1 parent 05f9fb1 commit 816e550
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 27 deletions.
1 change: 1 addition & 0 deletions internal/planner/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
_ explainablePlanNode = (*typeIndexJoin)(nil)
_ explainablePlanNode = (*updateNode)(nil)
_ explainablePlanNode = (*upsertNode)(nil)
_ explainablePlanNode = (*similarityNode)(nil)
)

const (
Expand Down
55 changes: 28 additions & 27 deletions tests/integration/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,34 @@ var (
"subType": {},

// These are all valid nodes.
"averageNode": {},
"countNode": {},
"createNode": {},
"dagScanNode": {},
"deleteNode": {},
"groupNode": {},
"limitNode": {},
"maxNode": {},
"minNode": {},
"multiScanNode": {},
"orderNode": {},
"parallelNode": {},
"pipeNode": {},
"scanNode": {},
"selectNode": {},
"selectTopNode": {},
"sumNode": {},
"topLevelNode": {},
"typeIndexJoin": {},
"typeJoinMany": {},
"typeJoinOne": {},
"updateNode": {},
"upsertNode": {},
"valuesNode": {},
"viewNode": {},
"lensNode": {},
"operationNode": {},
"averageNode": {},
"countNode": {},
"createNode": {},
"dagScanNode": {},
"deleteNode": {},
"groupNode": {},
"limitNode": {},
"maxNode": {},
"minNode": {},
"multiScanNode": {},
"orderNode": {},
"parallelNode": {},
"pipeNode": {},
"scanNode": {},
"selectNode": {},
"selectTopNode": {},
"sumNode": {},
"topLevelNode": {},
"typeIndexJoin": {},
"typeJoinMany": {},
"typeJoinOne": {},
"updateNode": {},
"upsertNode": {},
"valuesNode": {},
"viewNode": {},
"lensNode": {},
"operationNode": {},
"similarityNode": {},
}
)

Expand Down
70 changes: 70 additions & 0 deletions tests/integration/explain/debug/with_similarity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2025 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package test_explain_debug

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

var similarityPattern = dataMap{
"explain": dataMap{
"operationNode": []dataMap{
{
"selectTopNode": dataMap{
"similarityNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
},
}

func TestDebugExplainRequestWith_WithSimilarity(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with similarity.",

Actions: []any{
testUtils.SchemaUpdate{
Schema: `type User {
name: String
pointsList: [Float64!]
}`,
},
testUtils.CreateDoc{
DocMap: map[string]any{
"name": "John",
"pointsList": []float64{2, 4, 1},
},
},

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
User {
name
_similarity(pointsList: {vector: [1, 2, 0]})
}
}`,

ExpectedFullGraph: similarityPattern,
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

0 comments on commit 816e550

Please sign in to comment.