-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add index hint support for distinct command #1581
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
139 changes: 139 additions & 0 deletions
139
driver-core/src/test/resources/unified-test-format/crud/distinct-hint.json
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,139 @@ | ||
{ | ||
"description": "distinct-hint", | ||
"schemaVersion": "1.0", | ||
"runOnRequirements": [ | ||
{ | ||
"minServerVersion": "7.1.0" | ||
} | ||
], | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client0", | ||
"observeEvents": [ | ||
"commandStartedEvent" | ||
] | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database0", | ||
"client": "client0", | ||
"databaseName": "distinct-hint-tests" | ||
} | ||
}, | ||
{ | ||
"collection": { | ||
"id": "collection0", | ||
"database": "database0", | ||
"collectionName": "coll0" | ||
} | ||
} | ||
], | ||
"initialData": [ | ||
{ | ||
"collectionName": "coll0", | ||
"databaseName": "distinct-hint-tests", | ||
"documents": [ | ||
{ | ||
"_id": 1, | ||
"x": 11 | ||
}, | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
] | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "distinct with hint string", | ||
"operations": [ | ||
{ | ||
"name": "distinct", | ||
"object": "collection0", | ||
"arguments": { | ||
"fieldName": "x", | ||
"filter": { | ||
"_id": 1 | ||
}, | ||
"hint": "_id_" | ||
}, | ||
"expectResult": [ | ||
11 | ||
] | ||
} | ||
], | ||
"expectEvents": [ | ||
{ | ||
"client": "client0", | ||
"events": [ | ||
{ | ||
"commandStartedEvent": { | ||
"command": { | ||
"distinct": "coll0", | ||
"key": "x", | ||
"query": { | ||
"_id": 1 | ||
}, | ||
"hint": "_id_" | ||
}, | ||
"commandName": "distinct", | ||
"databaseName": "distinct-hint-tests" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "distinct with hint document", | ||
"operations": [ | ||
{ | ||
"name": "distinct", | ||
"object": "collection0", | ||
"arguments": { | ||
"fieldName": "x", | ||
"filter": { | ||
"_id": 1 | ||
}, | ||
"hint": { | ||
"_id": 1 | ||
} | ||
}, | ||
"expectResult": [ | ||
11 | ||
] | ||
} | ||
], | ||
"expectEvents": [ | ||
{ | ||
"client": "client0", | ||
"events": [ | ||
{ | ||
"commandStartedEvent": { | ||
"command": { | ||
"distinct": "coll0", | ||
"key": "x", | ||
"query": { | ||
"_id": 1 | ||
}, | ||
"hint": { | ||
"_id": 1 | ||
} | ||
}, | ||
"commandName": "distinct", | ||
"databaseName": "distinct-hint-tests" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ import com.mongodb.annotations.Reason | |
import com.mongodb.client.DistinctIterable as JDistinctIterable | ||
import com.mongodb.client.cursor.TimeoutMode | ||
import com.mongodb.client.model.Collation | ||
import com.mongodb.lang.Nullable | ||
import java.util.concurrent.TimeUnit | ||
import org.bson.BsonValue | ||
import org.bson.conversions.Bson | ||
|
@@ -99,4 +100,22 @@ public class DistinctIterable<T : Any?>(private val wrapped: JDistinctIterable<T | |
* @return this | ||
*/ | ||
public fun comment(comment: BsonValue?): DistinctIterable<T> = apply { wrapped.comment(comment) } | ||
|
||
/** | ||
* Sets the hint for which index to use. A null value means no hint is set. | ||
* | ||
* @param hint the hint | ||
* @return this | ||
*/ | ||
public fun hint(@Nullable hint: Bson?): DistinctIterable<T> = apply { wrapped.hint(hint) } | ||
|
||
/** | ||
* Sets the hint for which index to use. A null value means no hint is set. | ||
* | ||
* Note: If [DistinctFlow.hint] is set that will be used instead of any hint string. | ||
* | ||
* @param hint the name of the index which should be used for the operation | ||
* @return this | ||
*/ | ||
public fun hintString(@Nullable hint: String?): DistinctIterable<T> = apply { wrapped.hintString(hint) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, could we add the following detail to above to be consistent with
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the doc is consistent with the counterpart of
FindFlow.kt
, except for the following note forhintString()
:could we add this detail here as well?