public static TryCatch <IQueryPipelineStage> MonadicCreate( CosmosElement requestContinuation, CancellationToken cancellationToken, MonadicCreatePipelineStage monadicCreatePipelineStage, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue, int pageSize) { TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken( groupByAliasToAggregateType, orderedAliases, hasSelectValue, continuationToken: null); if (tryCreateGroupingTable.Failed) { return(TryCatch <IQueryPipelineStage> .FromException(tryCreateGroupingTable.Exception)); } TryCatch <IQueryPipelineStage> tryCreateSource = monadicCreatePipelineStage(requestContinuation, cancellationToken); if (tryCreateSource.Failed) { return(tryCreateSource); } IQueryPipelineStage stage = new ClientGroupByQueryPipelineStage( tryCreateSource.Result, cancellationToken, tryCreateGroupingTable.Result, pageSize); return(TryCatch <IQueryPipelineStage> .FromResult(stage)); }
public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync( CosmosElement requestContinuation, Func <CosmosElement, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSource, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue) { TryCatch <GroupingTable> tryCreateGroupingTable = GroupingTable.TryCreateFromContinuationToken( groupByAliasToAggregateType, orderedAliases, hasSelectValue, continuationToken: null); if (!tryCreateGroupingTable.Succeeded) { return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateGroupingTable.Exception)); } return((await tryCreateSource(requestContinuation)).Try <IDocumentQueryExecutionComponent>(source => { return new ClientGroupByDocumentQueryExecutionComponent( source, tryCreateGroupingTable.Result); })); }
protected GroupByDocumentQueryExecutionComponent( IDocumentQueryExecutionComponent source, GroupingTable groupingTable) : base(source) { this.groupingTable = groupingTable ?? throw new ArgumentNullException(nameof(groupingTable)); }
private ClientGroupByDocumentQueryExecutionComponent( IDocumentQueryExecutionComponent source, GroupingTable groupingTable) : base( source, groupingTable) { }
private ComputeGroupByQueryPipelineStage( IQueryPipelineStage source, CancellationToken cancellationToken, GroupingTable groupingTable, int pageSize) : base(source, cancellationToken, groupingTable, pageSize) { }
public static TryCatch <GroupingTable> TryCreateFromContinuationToken( IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue, string groupingTableContinuationToken) { GroupingTable groupingTable = new GroupingTable( groupByAliasToAggregateType, orderedAliases, hasSelectValue); if (groupingTableContinuationToken != null) { if (!CosmosElement.TryParse( groupingTableContinuationToken, out CosmosObject parsedGroupingTableContinuations)) { return(TryCatch <GroupingTable> .FromException( new MalformedContinuationTokenException($"Invalid GroupingTableContinuationToken"))); } foreach (KeyValuePair <string, CosmosElement> kvp in parsedGroupingTableContinuations) { string key = kvp.Key; CosmosElement value = kvp.Value; if (!UInt128.TryParse(key, out UInt128 groupByKey)) { return(TryCatch <GroupingTable> .FromException( new MalformedContinuationTokenException($"Invalid GroupingTableContinuationToken"))); } if (!(value is CosmosString singleGroupAggregatorContinuationToken)) { return(TryCatch <GroupingTable> .FromException( new MalformedContinuationTokenException($"Invalid GroupingTableContinuationToken"))); } TryCatch <SingleGroupAggregator> tryCreateSingleGroupAggregator = SingleGroupAggregator.TryCreate( EmptyAggregateOperators, groupByAliasToAggregateType, orderedAliases, hasSelectValue, singleGroupAggregatorContinuationToken.Value); if (tryCreateSingleGroupAggregator.Succeeded) { groupingTable.table[groupByKey] = tryCreateSingleGroupAggregator.Result; } else { return(TryCatch <GroupingTable> .FromException(tryCreateSingleGroupAggregator.Exception)); } } } return(TryCatch <GroupingTable> .FromResult(groupingTable)); }
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))); }
protected GroupByQueryPipelineStage( IQueryPipelineStage source, CancellationToken cancellationToken, GroupingTable groupingTable, int pageSize) : base(source, cancellationToken) { this.groupingTable = groupingTable ?? throw new ArgumentNullException(nameof(groupingTable)); this.pageSize = pageSize; }
public static GroupingTable CreateFromContinuationToken(CosmosQueryClient cosmosQueryClient, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue, string groupingTableContinuationToken) { GroupingTable groupingTable = new GroupingTable( cosmosQueryClient, groupByAliasToAggregateType, orderedAliases, hasSelectValue); if (groupingTableContinuationToken != null) { if (!CosmosElement.TryParse( groupingTableContinuationToken, out CosmosObject parsedGroupingTableContinuations)) { throw cosmosQueryClient.CreateBadRequestException($"Invalid GroupingTableContinuationToken"); } foreach (KeyValuePair <string, CosmosElement> kvp in parsedGroupingTableContinuations) { string key = kvp.Key; CosmosElement value = kvp.Value; UInt128 groupByKey = UInt128.Parse(key); if (!(value is CosmosString singleGroupAggregatorContinuationToken)) { throw cosmosQueryClient.CreateBadRequestException($"Invalid GroupingTableContinuationToken"); } SingleGroupAggregator singleGroupAggregator = SingleGroupAggregator.Create( cosmosQueryClient, EmptyAggregateOperators, groupByAliasToAggregateType, orderedAliases, hasSelectValue, singleGroupAggregatorContinuationToken.Value); groupingTable.table[groupByKey] = singleGroupAggregator; } } return(groupingTable); }
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)); }
public static async Task <IDocumentQueryExecutionComponent> CreateAsync( CosmosQueryClient cosmosQueryClient, string requestContinuation, Func <string, Task <IDocumentQueryExecutionComponent> > createSourceCallback, IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType, IReadOnlyList <string> orderedAliases, bool hasSelectValue) { IDocumentQueryExecutionComponent source = await createSourceCallback(requestContinuation); GroupingTable groupingTable = GroupingTable.CreateFromContinuationToken( cosmosQueryClient, groupByAliasToAggregateType, orderedAliases, hasSelectValue, groupingTableContinuationToken: null); return(new ClientGroupByDocumentQueryExecutionComponent( source, groupingTable)); }