forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Panic with filter on unique composite index on relation (sourcen…
…etwork#3020) ## Relevant issue(s) Resolves sourcenetwork#3016 ## Description Fix panic with filter on unique composite index on relation.
- Loading branch information
1 parent
dfee791
commit ea668a4
Showing
3 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/integration/index/query_with_unique_index_on_relation_filter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 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 index | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQueryWithUniqueCompositeIndex_WithFilterOnIndexedRelation_ShouldFilter(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type User { | ||
name: String | ||
devices: [Device] | ||
} | ||
type Device { | ||
manufacturer: String | ||
owner: User @index(unique: true, includes: [{name: "manufacturer"}]) | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
DocMap: map[string]any{ | ||
"name": "John", | ||
}, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
DocMap: map[string]any{ | ||
"manufacturer": "Apple", | ||
"owner_id": testUtils.NewDocIndex(0, 0), | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
User { | ||
name | ||
devices(filter: {owner_id: {_eq: "bae-1ef746f8-821e-586f-99b2-4cb1fb9b782f"}}) { | ||
manufacturer | ||
} | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"User": []map[string]any{ | ||
{ | ||
"name": "John", | ||
"devices": []map[string]any{ | ||
{"manufacturer": "Apple"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |