public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( CosmosElement requestContinuation, Func <CosmosElement, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue) { GroupByContinuationToken groupByContinuationToken; if (requestContinuation != null) { if (!GroupByContinuationToken.TryParse(requestContinuation, out groupByContinuationToken)) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException($"Invalid {nameof(GroupByContinuationToken)}: '{requestContinuation}'"))); } } else { groupByContinuationToken = new GroupByContinuationToken( groupingTableContinuationToken: null, sourceContinuationToken: null); } TryCatch <IDocumentQueryExecutionComponent> tryCreateSource; if ((groupByContinuationToken.SourceContinuationToken is CosmosString sourceContinuationToken) && (sourceContinuationToken.Value == ComputeGroupByDocumentQueryExecutionComponent.DoneReadingGroupingsContinuationToken)) { tryCreateSource = TryCatch <IDocumentQueryExecutionComponent> .FromResult(DoneDocumentQueryExecutionComponent.Value); }
public static TryCatch <IQueryPipelineStage> MonadicCreate( CosmosElement requestContinuation, CancellationToken cancellationToken, MonadicCreatePipelineStage monadicCreatePipelineStage, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue, int pageSize) { GroupByContinuationToken groupByContinuationToken; if (requestContinuation != null) { if (!GroupByContinuationToken.TryParse(requestContinuation, out groupByContinuationToken)) { return(TryCatch <IQueryPipelineStage> .FromException( new MalformedContinuationTokenException( $"Invalid {nameof(GroupByContinuationToken)}: '{requestContinuation}'"))); } } else { groupByContinuationToken = new GroupByContinuationToken( groupingTableContinuationToken: null, sourceContinuationToken: null); } TryCatch <IQueryPipelineStage> tryCreateSource; if ((groupByContinuationToken.SourceContinuationToken is CosmosString sourceContinuationToken) && (sourceContinuationToken.Value == ComputeGroupByQueryPipelineStage.DoneReadingGroupingsContinuationToken)) { tryCreateSource = TryCatch <IQueryPipelineStage> .FromResult(EmptyQueryPipelineStage.Singleton); }
public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( string requestContinuation, Func <string, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue) { GroupByContinuationToken groupByContinuationToken; if (requestContinuation != null) { if (!GroupByContinuationToken.TryParse(requestContinuation, out groupByContinuationToken)) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException( new MalformedContinuationTokenException($"Invalid {nameof(GroupByContinuationToken)}: '{requestContinuation}'"))); } } else { groupByContinuationToken = new GroupByContinuationToken( groupingTableContinuationToken: null, sourceContinuationToken: null); } TryCatch <IDocumentQueryExecutionComponent> tryCreateSource; if (groupByContinuationToken.SourceContinuationToken == ComputeGroupByDocumentQueryExecutionComponent.DoneReadingGroupingsContinuationToken) { tryCreateSource = TryCatch <IDocumentQueryExecutionComponent> .FromResult(DoneDocumentQueryExecutionComponent.Value); } else { tryCreateSource = await tryCreateSourceAsync(groupByContinuationToken.SourceContinuationToken); } if (!tryCreateSource.Succeeded) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateSource.Exception)); } TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken( groupByAliasToAggregateType, orderedAliases, hasSelectValue, groupByContinuationToken.GroupingTableContinuationToken); if (!tryCreateGroupingTable.Succeeded) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateGroupingTable.Exception)); } return(TryCatch <IDocumentQueryExecutionComponent> .FromResult( new ComputeGroupByDocumentQueryExecutionComponent( tryCreateSource.Result, tryCreateGroupingTable.Result))); }
public static async Task <IDocumentQueryExecutionComponent> CreateAsync( CosmosQueryClient cosmosQueryClient, string requestContinuation, Func <string, Task <IDocumentQueryExecutionComponent> > createSourceCallback, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue) { GroupByContinuationToken groupByContinuationToken; if (requestContinuation != null) { if (!GroupByContinuationToken.TryParse(requestContinuation, out groupByContinuationToken)) { throw cosmosQueryClient.CreateBadRequestException( $"Invalid {nameof(GroupByContinuationToken)}: '{requestContinuation}'"); } } else { groupByContinuationToken = new GroupByContinuationToken( groupingTableContinuationToken: null, sourceContinuationToken: null); } IDocumentQueryExecutionComponent source; if (groupByContinuationToken.SourceContinuationToken == ComputeGroupByDocumentQueryExecutionComponent.DoneReadingGroupingsContinuationToken) { source = DoneDocumentQueryExecutionComponent.Value; } else { source = await createSourceCallback(groupByContinuationToken.SourceContinuationToken); } GroupingTable groupingTable = GroupingTable.CreateFromContinuationToken( cosmosQueryClient, groupByAliasToAggregateType, orderedAliases, hasSelectValue, groupByContinuationToken.GroupingTableContinuationToken); return(new ComputeGroupByDocumentQueryExecutionComponent( source, groupingTable)); }