public override IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TValue>( AggregateExpressionDefinition <TResult, TValue> groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { return(WithPipeline(_pipeline.Bucket(groupBy, boundaries, options))); }
/// <inheritdoc /> public virtual IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TValue>( AggregateExpressionDefinition <TResult, TValue> groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { throw new NotImplementedException(); }
public override IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TValue>( AggregateExpressionDefinition <TResult, TValue> groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { Ensure.IsNotNull(groupBy, nameof(groupBy)); Ensure.IsNotNull(boundaries, nameof(boundaries)); const string operatorName = "$bucket"; var stage = new DelegatedPipelineStageDefinition <TResult, AggregateBucketResult <TValue> >( operatorName, (s, sr) => { var valueSerializer = sr.GetSerializer <TValue>(); var renderedGroupBy = groupBy.Render(s, sr); var serializedBoundaries = boundaries.Select(b => valueSerializer.ToBsonValue(b)); var serializedDefaultBucket = options != null && options.DefaultBucket.HasValue ? valueSerializer.ToBsonValue(options.DefaultBucket.Value) : null; var document = new BsonDocument { { operatorName, new BsonDocument { { "groupBy", renderedGroupBy }, { "boundaries", new BsonArray(serializedBoundaries) }, { "default", serializedDefaultBucket, serializedDefaultBucket != null } } } }; return(new RenderedPipelineStageDefinition <AggregateBucketResult <TValue> >( operatorName, document, sr.GetSerializer <AggregateBucketResult <TValue> >())); }); return(AppendStage(stage)); }
/// <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> /// <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="options">The options.</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TResult, TValue>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { Ensure.IsNotNull(aggregate, nameof(aggregate)); return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Bucket(groupBy, boundaries, 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> /// <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="options">The options.</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <AggregateBucketResult <TValue> > Bucket <TResult, TValue>( this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TValue> > groupBy, IEnumerable <TValue> boundaries, AggregateBucketOptions <TValue> options = null) { 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); return(aggregate.Bucket(groupByDefinition, boundaries, 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="options">The options.</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, AggregateBucketOptions <TValue> options = null) { Ensure.IsNotNull(aggregate, nameof(aggregate)); Ensure.IsNotNull(groupBy, nameof(groupBy)); Ensure.IsNotNull(boundaries, nameof(boundaries)); 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.Bucket(groupByDefinition, boundaries, outputDefinition, options)); }