-
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
Conversation
469fd34
to
a3301b9
Compare
return new DistinctOperation<>(assertNotNull(namespace), | ||
fieldName, codecRegistry.get(resultClass)) | ||
.retryReads(retryReads) | ||
.filter(filter == null ? null : filter.toBsonDocument(documentClass, codecRegistry)) | ||
.collation(collation) | ||
.comment(comment); | ||
.comment(comment) | ||
.hint(hint != null ? toBsonDocument(hint) : (hintString != null ? new BsonString(hintString) : null)); |
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 is fine to implement via one-liner, but I think the similar way in the above createFindOperation()
is cleaner and more readable.
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.
.hint(hint != null ? toBsonDocument(hint) : (hintString != null ? new BsonString(hintString) : null)); | |
DistinctOperation<TResult> operation = new DistinctOperation<>(assertNotNull(namespace), | |
fieldName, codecRegistry.get(resultClass)) | |
.retryReads(retryReads) | |
.filter(filter == null ? null : filter.toBsonDocument(documentClass, codecRegistry)) | |
.collation(collation) | |
.comment(comment); | |
if (hint != null) { | |
operation.hint(toBsonDocument(hint)); | |
} else if (hintString != null) { | |
operation.hintString(hintString); | |
} | |
return operation; |
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.
Thank you for the suggestion, will update!
this.hintString = hint; | ||
return this; | ||
} | ||
|
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.
I think hint
field suffices which is of BsonValue
type that will accomodate both BsonDocument
and BsonString
.
Similar scenario applies in FindOperation
within the same package which has a hint
field as well.
* @return this | ||
*/ | ||
public fun hintString(@Nullable hint: String?): DistinctFlow<T> = apply { wrapped.hintString(hint) } | ||
|
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 for hintString()
:
* Note: If [DistinctFlow.hint] is set that will be used instead of any hint string.
could we add this detail here as well?
* @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 comment
The 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 FindIterable.kt
?
* Note: If [DistinctIterable.hint] is set that will be used instead of any hint string.
} | ||
|
||
@Override | ||
public DistinctIterable<T> hintString(final String hint) { |
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.
seems a @Nullable
is missing above
* | ||
* @param hint the name of the index which should be used for the operation | ||
* @return this | ||
* @since 5.3 |
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.
again, we'd better add the following key detail in line with FindObservable
:
* @note if [[hint]] is set that will be used instead of any hint string.
* @return this | ||
* @since 5.3 | ||
*/ | ||
DistinctIterable<TResult> hintString(@Nullable String hint); |
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.
again, it would be great to add the following detail above:
* <p>Note: If {@link DistinctIterable#hint(Bson)} is set that will be used instead of any hint string.</p>
Ticket
JAVA-5686
Description
This PR adds index hint support for
distinct
command for java, kotlin, and scala. It also syncs CRUD unified spec tests to 77b1f78458cf25b525cde2274e33acd5db2581d2.Testing
./gradlew check
UnifiedCRUDTest.java