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.
feat: Support for descending fields CLI index creation (sourcenetwork…
…#3237) ## Relevant issue(s) Resolves sourcenetwork#2460 ## Description Using the HTTP endpoint, it was possible to create a collection index, with each field being either descending or ascending. This was possible because one of the parameters was a boolean field called "Descending." However, this functionality was not present in the CLI equivalent. This feature adds support for creating descending fields. For example, the following sorts name in ascending order, because ascension is the default `defradb client index create -c User --fields name` The following sorts it in descending order: `defradb client index create -c User --fields name:DESC` And the following sorts multiple fields, in different combinations of descending and ascending order: `defradb client index create -c User --fields name:ASC,score:DESC` ## Tasks - [x] I made sure the code is well commented, particularly hard-to-understand areas. - [x] I made sure the pull request title adheres to the conventional commit style ## How has this been tested? Specify the platform(s) on which this was tested: - Windows
- Loading branch information
Showing
5 changed files
with
142 additions
and
9 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
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
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 |
---|---|---|
|
@@ -178,3 +178,79 @@ func TestUniqueCompositeIndexCreate_IfFieldValuesAreUnique_Succeed(t *testing.T) | |
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestUniqueCompositeIndexCreate_IfFieldValuesAreOrdered_Succeed(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "create unique composite index if all docs have unique fields combinations", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type User { | ||
name: String | ||
age: Int | ||
email: String | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: ` | ||
{ | ||
"name": "John", | ||
"age": 21, | ||
"email": "[email protected]" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: ` | ||
{ | ||
"name": "John", | ||
"age": 35, | ||
"email": "[email protected]" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: ` | ||
{ | ||
"name": "Andy", | ||
"age": 35, | ||
"email": "[email protected]" | ||
}`, | ||
}, | ||
testUtils.CreateIndex{ | ||
CollectionID: 0, | ||
Fields: []testUtils.IndexedField{{Name: "name", Descending: true}, {Name: "age", Descending: false}, {Name: "email"}}, | ||
IndexName: "name_age_unique_index", | ||
Unique: true, | ||
}, | ||
testUtils.GetIndexes{ | ||
CollectionID: 0, | ||
ExpectedIndexes: []client.IndexDescription{ | ||
{ | ||
Name: "name_age_unique_index", | ||
ID: 1, | ||
Unique: true, | ||
Fields: []client.IndexedFieldDescription{ | ||
{ | ||
Name: "name", | ||
Descending: true, | ||
}, | ||
{ | ||
Name: "age", | ||
Descending: false, | ||
}, | ||
{ | ||
Name: "email", | ||
Descending: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |