private ComputeDistinctDocumentQueryExecutionComponent(
     DistinctQueryType distinctQueryType,
     DistinctMap distinctMap,
     IDocumentQueryExecutionComponent source)
     : base(distinctMap, source)
 {
 }
            /// <summary>
            /// Creates an DistinctDocumentQueryExecutionComponent
            /// </summary>
            /// <param name="queryClient">The query client</param>
            /// <param name="requestContinuation">The continuation token.</param>
            /// <param name="createSourceCallback">The callback to create the source to drain from.</param>
            /// <param name="distinctQueryType">The type of distinct query.</param>
            /// <returns>A task to await on and in return </returns>
            public static async Task <DistinctDocumentQueryExecutionComponent> CreateAsync(
                CosmosQueryClient queryClient,
                string requestContinuation,
                Func <string, Task <IDocumentQueryExecutionComponent> > createSourceCallback,
                DistinctQueryType distinctQueryType)
            {
                DistinctContinuationToken distinctContinuationToken;

                if (requestContinuation != null)
                {
                    if (!DistinctContinuationToken.TryParse(requestContinuation, out distinctContinuationToken))
                    {
                        throw queryClient.CreateBadRequestException($"Invalid {nameof(DistinctContinuationToken)}: {requestContinuation}");
                    }
                }
                else
                {
                    distinctContinuationToken = new DistinctContinuationToken(sourceToken: null, distinctMapToken: null);
                }

                DistinctMap distinctMap = DistinctMap.Create(distinctQueryType, distinctContinuationToken.DistinctMapToken);
                IDocumentQueryExecutionComponent source = await createSourceCallback(distinctContinuationToken.SourceToken);

                return(new ComputeDistinctDocumentQueryExecutionComponent(
                           distinctQueryType,
                           distinctMap,
                           source));
            }
Beispiel #3
0
        protected DistinctDocumentQueryExecutionComponent(
            DistinctMap distinctMap,
            IDocumentQueryExecutionComponent source)
            : base(source)
        {
            if (distinctMap == null)
            {
                throw new ArgumentNullException(nameof(distinctMap));
            }

            this.distinctMap = distinctMap;
        }
            private ClientDistinctDocumentQueryExecutionComponent(
                DistinctQueryType distinctQueryType,
                DistinctMap distinctMap,
                IDocumentQueryExecutionComponent source)
                : base(distinctMap, source)
            {
                if ((distinctQueryType != DistinctQueryType.Unordered) && (distinctQueryType != DistinctQueryType.Ordered))
                {
                    throw new ArgumentException($"Unknown {nameof(DistinctQueryType)}: {distinctQueryType}.");
                }

                this.distinctQueryType = distinctQueryType;
            }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the DistinctDocumentQueryExecutionComponent class.
        /// </summary>
        /// <param name="distinctQueryType">The type of distinct query.</param>
        /// <param name="previousHash">The previous that distinct map saw.</param>
        /// <param name="source">The source to drain from.</param>
        private DistinctDocumentQueryExecutionComponent(
            DistinctQueryType distinctQueryType,
            UInt192?previousHash,
            IDocumentQueryExecutionComponent source)
            : base(source)
        {
            if (distinctQueryType == DistinctQueryType.None)
            {
                throw new ArgumentException("It doesn't make sense to create a distinct component of type None.");
            }

            this.distinctQueryType = distinctQueryType;
            this.distinctMap       = DistinctMap.Create(distinctQueryType, previousHash);
        }
Beispiel #6
0
        private GroupByDocumentQueryExecutionComponent(
            IReadOnlyDictionary <string, AggregateOperator?> groupByAliasToAggregateType,
            IDocumentQueryExecutionComponent source)
            : base(source)
        {
            if (groupByAliasToAggregateType == null)
            {
                throw new ArgumentNullException(nameof(groupByAliasToAggregateType));
            }

            this.groupingTable = new Dictionary <UInt192, GroupByValues>();

            // Using an ordered distinct map to get hashes.
            this.distinctMap = DistinctMap.Create(DistinctQueryType.Ordered, null);
            this.groupByAliasToAggregateType = groupByAliasToAggregateType;
        }
            public static async Task <TryCatch <IDocumentQueryExecutionComponent> > TryCreateAsync(
                string requestContinuation,
                Func <string, Task <TryCatch <IDocumentQueryExecutionComponent> > > tryCreateSourceAsync,
                DistinctQueryType distinctQueryType)
            {
                DistinctContinuationToken distinctContinuationToken;

                if (requestContinuation != null)
                {
                    if (!DistinctContinuationToken.TryParse(requestContinuation, out distinctContinuationToken))
                    {
                        return(TryCatch <IDocumentQueryExecutionComponent> .FromException(
                                   new Exception($"Invalid {nameof(DistinctContinuationToken)}: {requestContinuation}")));
                    }
                }
                else
                {
                    distinctContinuationToken = new DistinctContinuationToken(sourceToken: null, distinctMapToken: null);
                }

                TryCatch <DistinctMap> tryCreateDistinctMap = DistinctMap.TryCreate(
                    distinctQueryType,
                    distinctContinuationToken.DistinctMapToken);

                if (!tryCreateDistinctMap.Succeeded)
                {
                    return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateDistinctMap.Exception));
                }

                TryCatch <IDocumentQueryExecutionComponent> tryCreateSource = await tryCreateSourceAsync(distinctContinuationToken.SourceToken);

                if (!tryCreateSource.Succeeded)
                {
                    return(TryCatch <IDocumentQueryExecutionComponent> .FromException(tryCreateSource.Exception));
                }

                return(TryCatch <IDocumentQueryExecutionComponent> .FromResult(
                           new ClientDistinctDocumentQueryExecutionComponent(
                               distinctQueryType,
                               tryCreateDistinctMap.Result,
                               tryCreateSource.Result)));
            }