Skip to content

Adding timeoutMS for explain helpers #1770

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ data class SyncAggregateIterable<T : Any>(val wrapped: AggregateFlow<T>) :
override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity): E = runBlocking {
wrapped.explain(explainResultClass, verbosity)
}

override fun explain(timeoutMS: Long): Document = runBlocking { wrapped.explain(timeoutMS) }

override fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = runBlocking {
wrapped.explain(verbosity, timeoutMS)
}

override fun <E : Any> explain(explainResultClass: Class<E>, timeoutMS: Long): E = runBlocking {
wrapped.explain(explainResultClass, timeoutMS)
}

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity, timeoutMS: Long): E =
runBlocking {
wrapped.explain(explainResultClass, verbosity, timeoutMS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,19 @@ data class SyncFindIterable<T : Any>(val wrapped: FindFlow<T>) : JFindIterable<T
override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity): E = runBlocking {
wrapped.explain(explainResultClass, verbosity)
}

override fun explain(timeoutMS: Long): Document = runBlocking { wrapped.explain(timeoutMS) }

override fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = runBlocking {
wrapped.explain(verbosity, timeoutMS)
}

override fun <E : Any> explain(explainResultClass: Class<E>, timeoutMS: Long): E = runBlocking {
wrapped.explain(explainResultClass, timeoutMS)
}

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity, timeoutMS: Long): E =
runBlocking {
wrapped.explain(explainResultClass, verbosity, timeoutMS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ public class AggregateFlow<T : Any>(private val wrapped: AggregatePublisher<T>)
*/
public fun let(variables: Bson?): AggregateFlow<T> = apply { wrapped.let(variables) }

/**
* Requests [AggregateFlow] to start streaming data according to the specified aggregation pipeline.
* - If the aggregation pipeline ends with an `$out` or `$merge` stage, then finds all documents in the affected
* namespace and emits them. You may want to use [toCollection] instead.
* - Otherwise, emits no values.
*/
public override suspend fun collect(collector: FlowCollector<T>): Unit = wrapped.asFlow().collect(collector)

/**
* Explain the execution plan for this operation with the given verbosity level
*
Expand Down Expand Up @@ -217,10 +225,47 @@ public class AggregateFlow<T : Any>(private val wrapped: AggregatePublisher<T>)
explain(R::class.java, verbosity)

/**
* Requests [AggregateFlow] to start streaming data according to the specified aggregation pipeline.
* - If the aggregation pipeline ends with an `$out` or `$merge` stage, then finds all documents in the affected
* namespace and emits them. You may want to use [toCollection] instead.
* - Otherwise, emits no values.
* Explain the execution plan for this operation.
*
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public override suspend fun collect(collector: FlowCollector<T>): Unit = wrapped.asFlow().collect(collector)
public suspend inline fun <reified R : Any> explain(timeoutMS: Long): R = explain(R::class.java, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param verbosity the verbosity of the explanation.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend inline fun <reified R : Any> explain(verbosity: ExplainVerbosity, timeoutMS: Long): R =
explain(R::class.java, verbosity, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class.
* @param resultClass the document class to decode into.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend fun <R : Any> explain(resultClass: Class<R>, timeoutMS: Long): R =
wrapped.explain(resultClass, timeoutMS).awaitSingle()

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class.
* @param resultClass the document class to decode into.
* @param verbosity the verbosity of the explanation.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend fun <R : Any> explain(resultClass: Class<R>, verbosity: ExplainVerbosity, timeoutMS: Long): R =
wrapped.explain(resultClass, verbosity, timeoutMS).awaitSingle()
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,51 @@ public class FindFlow<T : Any>(private val wrapped: FindPublisher<T>) : Flow<T>
public suspend inline fun <reified R : Any> explain(verbosity: ExplainVerbosity? = null): R =
explain(R::class.java, verbosity)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend inline fun <reified R : Any> explain(timeoutMS: Long): R = explain(R::class.java, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param verbosity the verbosity of the explanation.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend inline fun <reified R : Any> explain(verbosity: ExplainVerbosity, timeoutMS: Long): R =
explain(R::class.java, verbosity, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class.
* @param resultClass the document class to decode into.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend fun <R : Any> explain(resultClass: Class<R>, timeoutMS: Long): R =
wrapped.explain(resultClass, timeoutMS).awaitSingle()

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class.
* @param resultClass the document class to decode into.
* @param verbosity the verbosity of the explanation.
* @param timeoutMS the timeout in milliseconds for the explain operation.
* @return the execution plan.
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public suspend fun <R : Any> explain(resultClass: Class<R>, verbosity: ExplainVerbosity, timeoutMS: Long): R =
wrapped.explain(resultClass, verbosity, timeoutMS).awaitSingle()

public override suspend fun collect(collector: FlowCollector<T>): Unit = wrapped.asFlow().collect(collector)
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ internal class SyncAggregateIterable<T : Any>(val wrapped: AggregateIterable<T>)

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity): E =
wrapped.explain(explainResultClass, verbosity)

override fun explain(timeoutMS: Long): Document = wrapped.explain(timeoutMS)

override fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = wrapped.explain(verbosity, timeoutMS)

override fun <E : Any> explain(explainResultClass: Class<E>, timeoutMS: Long): E =
wrapped.explain(explainResultClass, timeoutMS)

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity, timeoutMS: Long): E =
wrapped.explain(explainResultClass, verbosity, timeoutMS)
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ internal class SyncFindIterable<T : Any>(val wrapped: FindIterable<T>) :

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity): E =
wrapped.explain(explainResultClass, verbosity)

override fun explain(timeoutMS: Long): Document = wrapped.explain(timeoutMS)

override fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = wrapped.explain(verbosity, timeoutMS)

override fun <E : Any> explain(explainResultClass: Class<E>, timeoutMS: Long): E =
wrapped.explain(explainResultClass, timeoutMS)

override fun <E : Any> explain(explainResultClass: Class<E>, verbosity: ExplainVerbosity, timeoutMS: Long): E =
wrapped.explain(explainResultClass, verbosity, timeoutMS)
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,71 @@ public class AggregateIterable<T : Any>(private val wrapped: JAggregateIterable<
*/
public fun let(variables: Bson?): AggregateIterable<T> = apply { wrapped.let(variables) }

/**
* Explain the execution plan for this operation.
*
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun explain(timeoutMS: Long): Document = wrapped.explain(timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = wrapped.explain(verbosity, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param resultClass the result document type.
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun <R : Any> explain(resultClass: Class<R>, timeoutMS: Long): R = wrapped.explain(resultClass, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param resultClass the result document type.
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun <R : Any> explain(resultClass: Class<R>, verbosity: ExplainVerbosity, timeoutMS: Long): R =
wrapped.explain(resultClass, verbosity, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public inline fun <reified R : Any> explain(timeoutMS: Long): R = explain(R::class.java, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public inline fun <reified R : Any> explain(verbosity: ExplainVerbosity, timeoutMS: Long): R =
explain(R::class.java, verbosity, timeoutMS)

/**
* Explain the execution plan for this operation with the given verbosity level
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,49 @@ public class FindIterable<T : Any>(private val wrapped: JFindIterable<T>) : Mong
public fun <R : Any> explain(resultClass: Class<R>, verbosity: ExplainVerbosity? = null): R =
if (verbosity == null) wrapped.explain(resultClass) else wrapped.explain(resultClass, verbosity)

/**
* Explain the execution plan for this operation.
*
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun explain(timeoutMS: Long): Document = wrapped.explain(timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun explain(verbosity: ExplainVerbosity, timeoutMS: Long): Document = wrapped.explain(verbosity, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param resultClass the result document type.
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun <R : Any> explain(resultClass: Class<R>, timeoutMS: Long): R = wrapped.explain(resultClass, timeoutMS)

/**
* Explain the execution plan for this operation.
*
* @param R the type of the document class
* @param resultClass the result document type.
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @see [Explain command](https://www.mongodb.com/docs/manual/reference/command/explain/)
*/
public fun <R : Any> explain(resultClass: Class<R>, verbosity: ExplainVerbosity, timeoutMS: Long): R =
wrapped.explain(resultClass, verbosity, timeoutMS)

/**
* Explain the execution plan for this operation with the given verbosity level
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,54 @@ public interface AggregatePublisher<TResult> extends Publisher<TResult> {
* @mongodb.server.release 3.6
*/
<E> Publisher<E> explain(Class<E> explainResultClass, ExplainVerbosity verbosity);

/**
* Explain the execution plan for this operation.
*
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @since 5.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

All these should be 5.6.

* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher<Document> explain(long timeoutMS);

/**
* Explain the execution plan for this operation.
*
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @since 5.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
Publisher<Document> explain(ExplainVerbosity verbosity, long timeoutMS);

/**
* Explain the execution plan for this operation.
*
* @param <E> the type of the document class
* @param explainResultClass the document class to decode into
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @since 5.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
<E> Publisher<E> explain(Class<E> explainResultClass, long timeoutMS);

/**
* Explain the execution plan for this operation.
*
* @param <E> the type of the document class
* @param explainResultClass the document class to decode into
* @param verbosity the verbosity of the explanation
* @param timeoutMS the timeout in milliseconds for the explain operation
* @return the execution plan
* @since 5.2
* @mongodb.driver.manual reference/command/explain/
* @mongodb.server.release 3.6
*/
<E> Publisher<E> explain(Class<E> explainResultClass, ExplainVerbosity verbosity, long timeoutMS);
}
Loading