예제 #1
0
        /// <summary>
        /// Appends a $bucketAuto stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="groupBy">The expression providing the value to group by.</param>
        /// <param name="buckets">The number of buckets.</param>
        /// <param name="output">The output projection.</param>
        /// <param name="options">The options (optional).</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TNewResult> BucketAuto <TResult, TValue, TNewResult>(
            this IAggregateFluent <TResult> aggregate,
            Expression <Func <TResult, TValue> > groupBy,
            int buckets,
            Expression <Func <IGrouping <TValue, TResult>, TNewResult> > output,
            AggregateBucketAutoOptions options = null)
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(groupBy, nameof(groupBy));
            Ensure.IsNotNull(output, nameof(output));

            var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions);
            var outputDefinition  = new ExpressionBucketOutputProjection <TResult, TValue, TNewResult>(x => default(TValue), output, aggregate.Options.TranslationOptions);

            return(aggregate.BucketAuto(groupByDefinition, buckets, outputDefinition, options));
        }
        /// <summary>
        /// Appends a $bucket stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="groupBy">The expression providing the value to group by.</param>
        /// <param name="boundaries">The bucket boundaries.</param>
        /// <param name="output">The output projection.</param>
        /// <param name="defaultBucket">The default bucket (optional).</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TNewResult> Bucket <TResult, TValue, TNewResult>(
            this IAggregateFluent <TResult> aggregate,
            Expression <Func <TResult, TValue> > groupBy,
            IEnumerable <TValue> boundaries,
            Expression <Func <IGrouping <TValue, TResult>, TNewResult> > output,
            Optional <TValue> defaultBucket = default(Optional <TValue>))
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(groupBy, nameof(groupBy));
            Ensure.IsNotNull(boundaries, nameof(boundaries));

            var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions);
            var outputDefinition  = new ExpressionBucketOutputProjection <TResult, TValue, TNewResult>(x => default(TValue), output, aggregate.Options.TranslationOptions);

            return(aggregate.Bucket(groupByDefinition, boundaries, outputDefinition, defaultBucket));
        }