-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Cosmos Paged flux initial POC implementation v4 #7839
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
Merged
kushagraThapar
merged 13 commits into
Azure:feature/cosmos/v4
from
kushagraThapar:paged_flux_implementation_v4
Feb 4, 2020
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d37beb2
Updated pom files
kushagraThapar 4dddcd3
Merge branch 'feature/cosmos/v4' into paged_flux_implementation_v4
kushagraThapar f89a22b
Added CosmosContinuablePagedFlux initial impelmentation and POC for q…
kushagraThapar 46dd6f2
Merged latest feature/cosmos/v4 changes
kushagraThapar 3ecd26a
Changed constructor to package level. Updated mixed benchmark to take…
kushagraThapar 4b92edc
Experimenting Schedulers for elastic pool
kushagraThapar d53d439
Reverted flux experiments
kushagraThapar 32a8539
Removed azure-core unwanted dependencies
kushagraThapar 8e4fb2d
Moved azure-core dependency to parent pom and used same version in az…
kushagraThapar 9a25283
Moved CosmosPagedFluxOptions to implementation package
kushagraThapar 815b308
Added back pressure tests for CosmosContinuablePagedFlux subscribe call
kushagraThapar 1b83822
Merged latest feature/cosmos/v4
kushagraThapar 7943935
Updated queryItems sync API to return IterableStream
kushagraThapar 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
85 changes: 85 additions & 0 deletions
85
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosContinuablePagedFlux.java
This file contains hidden or 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,85 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.cosmos; | ||
|
|
||
| import com.azure.core.util.IterableStream; | ||
| import com.azure.core.util.paging.ContinuablePagedFlux; | ||
| import reactor.core.CoreSubscriber; | ||
| import reactor.core.publisher.Flux; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Cosmos implementation of {@link ContinuablePagedFlux}. | ||
| * <p> | ||
| * This type is a Flux that provides the ability to operate on pages of type {@link FeedResponse} | ||
| * and individual items in such pages. This type supports {@link String} type continuation tokens, | ||
| * allowing for restarting from a previously-retrieved continuation token. | ||
| * <p> | ||
| * For more information on the base type, refer {@link ContinuablePagedFlux} | ||
| * | ||
| * @param <T> The type of elements in a {@link com.azure.core.util.paging.ContinuablePage} | ||
| * @see com.azure.core.util.paging.ContinuablePage | ||
| * @see CosmosPagedFluxOptions | ||
| * @see FeedResponse | ||
| */ | ||
| public class CosmosContinuablePagedFlux<T> extends ContinuablePagedFlux<String, T, FeedResponse<T>> { | ||
|
|
||
| private final Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> optionsFluxFunction; | ||
|
|
||
| public CosmosContinuablePagedFlux(Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> optionsFluxFunction) { | ||
|
kushagraThapar marked this conversation as resolved.
Outdated
|
||
| this.optionsFluxFunction = optionsFluxFunction; | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<FeedResponse<T>> byPage() { | ||
| CosmosPagedFluxOptions cosmosPagedFluxOptions = new CosmosPagedFluxOptions(); | ||
|
|
||
| return this.optionsFluxFunction.apply(cosmosPagedFluxOptions); | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<FeedResponse<T>> byPage(String continuationToken) { | ||
| CosmosPagedFluxOptions cosmosPagedFluxOptions = new CosmosPagedFluxOptions(); | ||
| cosmosPagedFluxOptions.setRequestContinuation(continuationToken); | ||
|
|
||
| return this.optionsFluxFunction.apply(cosmosPagedFluxOptions); | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<FeedResponse<T>> byPage(int preferredPageSize) { | ||
| CosmosPagedFluxOptions cosmosPagedFluxOptions = new CosmosPagedFluxOptions(); | ||
| cosmosPagedFluxOptions.setMaxItemCount(preferredPageSize); | ||
|
|
||
| return this.optionsFluxFunction.apply(cosmosPagedFluxOptions); | ||
| } | ||
|
|
||
| @Override | ||
| public Flux<FeedResponse<T>> byPage(String continuationToken, int preferredPageSize) { | ||
| CosmosPagedFluxOptions cosmosPagedFluxOptions = new CosmosPagedFluxOptions(); | ||
| cosmosPagedFluxOptions.setRequestContinuation(continuationToken); | ||
| cosmosPagedFluxOptions.setMaxItemCount(preferredPageSize); | ||
|
|
||
| return this.optionsFluxFunction.apply(cosmosPagedFluxOptions); | ||
| } | ||
|
|
||
| /** | ||
| * Subscribe to consume all items of type {@code T} in the sequence respectively. | ||
| * This is recommended for most common scenarios. This will seamlessly fetch next | ||
| * page when required and provide with a {@link Flux} of items. | ||
| * | ||
| * @param coreSubscriber The subscriber for this {@link CosmosContinuablePagedFlux} | ||
| */ | ||
| @Override | ||
| public void subscribe(CoreSubscriber<? super T> coreSubscriber) { | ||
| Flux<FeedResponse<T>> pagedResponse = this.byPage(); | ||
| pagedResponse.flatMap(tFeedResponse -> { | ||
|
kushagraThapar marked this conversation as resolved.
|
||
| IterableStream<T> elements = tFeedResponse.getElements(); | ||
| if (elements == null) { | ||
| return Flux.empty(); | ||
| } | ||
| return Flux.fromIterable(elements); | ||
| }).subscribe(coreSubscriber); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.