Skip to content
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 2 commits into from
Dec 12, 2024

Conversation

joykim1005
Copy link
Contributor

@joykim1005 joykim1005 commented Dec 11, 2024

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

  • ran ./gradlew check
  • local testing - ran UnifiedCRUDTest.java

@joykim1005 joykim1005 changed the title Java 5686 Add index hint support for distinct command Dec 11, 2024
@joykim1005 joykim1005 requested review from a team and NathanQingyangXu and removed request for a team December 11, 2024 22:00
@joykim1005 joykim1005 marked this pull request as ready for review December 11, 2024 22:01
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));
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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;

Copy link
Contributor Author

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;
}

Copy link
Contributor

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) }

Copy link
Contributor

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) }
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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>

@joykim1005 joykim1005 merged commit 08ec2fc into mongodb:main Dec 12, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants