Skip to content

Commit

Permalink
Force selection of calendar or fixed intervals in date histo aggregat…
Browse files Browse the repository at this point in the history
…ions (#3988)

Implements elastic/elasticsearch#33727
  • Loading branch information
codebrain authored Aug 9, 2019
1 parent d4c9cef commit 802c570
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ public interface IDateHistogramAggregation : IBucketAggregation
[DataMember(Name ="format")]
string Format { get; set; }

[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
[DataMember(Name ="interval")]
Union<DateInterval, Time> Interval { get; set; }

[DataMember(Name ="calendar_interval")]
Union<DateInterval, Time> CalendarInterval { get; set; }

[DataMember(Name ="fixed_interval")]
Union<DateInterval, Time> FixedInterval { get; set; }

[DataMember(Name ="min_doc_count")]
int? MinimumDocumentCount { get; set; }

Expand Down Expand Up @@ -65,7 +72,11 @@ public string Format
set => _format = value;
}


[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
public Union<DateInterval, Time> Interval { get; set; }
public Union<DateInterval, Time> CalendarInterval { get; set; }
public Union<DateInterval, Time> FixedInterval { get; set; }

public int? MinimumDocumentCount { get; set; }
public DateTime? Missing { get; set; }
Expand Down Expand Up @@ -99,7 +110,10 @@ string IDateHistogramAggregation.Format
set => _format = value;
}

[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
Union<DateInterval, Time> IDateHistogramAggregation.Interval { get; set; }
Union<DateInterval, Time> IDateHistogramAggregation.CalendarInterval { get; set; }
Union<DateInterval, Time> IDateHistogramAggregation.FixedInterval { get; set; }

int? IDateHistogramAggregation.MinimumDocumentCount { get; set; }

Expand All @@ -124,11 +138,18 @@ string IDateHistogramAggregation.Format
public DateHistogramAggregationDescriptor<T> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
Assign(scriptSelector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor()));

[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
public DateHistogramAggregationDescriptor<T> Interval(Time interval) => Assign(interval, (a, v) => a.Interval = v);

[Obsolete("Deprecated in version 7.2.0, use CalendarInterval or FixedInterval instead")]
public DateHistogramAggregationDescriptor<T> Interval(DateInterval interval) =>
Assign(interval, (a, v) => a.Interval = v);

public DateHistogramAggregationDescriptor<T> CalendarInterval(Time interval) => Assign(interval, (a, v) => a.CalendarInterval = v);
public DateHistogramAggregationDescriptor<T> CalendarInterval(DateInterval interval) => Assign(interval, (a, v) => a.CalendarInterval = v);
public DateHistogramAggregationDescriptor<T> FixedInterval(Time interval) => Assign(interval, (a, v) => a.FixedInterval = v);
public DateHistogramAggregationDescriptor<T> FixedInterval(DateInterval interval) => Assign(interval, (a, v) => a.FixedInterval = v);

public DateHistogramAggregationDescriptor<T> Format(string format) => Assign(format, (a, v) => a.Format = v);

public DateHistogramAggregationDescriptor<T> MinimumDocumentCount(int? minimumDocumentCount) =>
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Tests.Reproduce/GithubIssue3673.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GithubIssue3673 : IClusterFixture<ReadOnlyCluster>
[I]
public void DeserializeDateAggregation()
{
#pragma warning disable 612, 618
Action action = () => _cluster.Client.Search<Project>(s => s
.Size(0)
.Aggregations(a => a
Expand All @@ -27,6 +28,7 @@ public void DeserializeDateAggregation()
)
)
);
#pragma warning restore 612, 618

action.Should().NotThrow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", date => date
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -106,6 +107,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
}
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down Expand Up @@ -160,6 +162,7 @@ public DateHistogramAggregationNoSubAggregationsUsageTests(ReadOnlyCluster i, En
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", date => date
.Field(p => p.StartedOn)
Expand All @@ -186,6 +189,7 @@ public DateHistogramAggregationNoSubAggregationsUsageTests(ReadOnlyCluster i, En
Order = HistogramOrder.CountAscending,
Missing = FixedDate
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public AverageBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -68,6 +69,7 @@ public AverageBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
{
GapPolicy = GapPolicy.InsertZeros
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -125,6 +126,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
Script = new InlineScript("params.stableCommits / params.totalCommits * 100")
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public BucketSelectorAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -80,6 +81,7 @@ public BucketSelectorAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
Script = new InlineScript("params.totalCommits >= 500")
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public BucketSortAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -87,6 +88,7 @@ public BucketSortAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
GapPolicy = GapPolicy.InsertZeros
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public CumulativeSumAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -64,6 +65,7 @@ public CumulativeSumAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
new SumAggregation("commits", "numberOfCommits") &&
new CumulativeSumAggregation("cumulative_commits", "commits")
};
#pragma warning restore 618

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -65,6 +66,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
new SumAggregation("commits", "numberOfCommits") &&
new DerivativeAggregation("commits_derivative", "commits")
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ExtendedStatsBucketAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -68,6 +69,7 @@ public ExtendedStatsBucketAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
{
Sigma = 2.0
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public MaxBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -63,6 +64,7 @@ public MaxBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
Aggregations = new SumAggregation("commits", "numberOfCommits")
}
&& new MaxBucketAggregation("max_commits_per_month", "projects_started_per_month>commits");
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public MinBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -63,6 +64,7 @@ public MinBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage usa
Aggregations = new SumAggregation("commits", "numberOfCommits")
}
&& new MinBucketAggregation("min_commits_per_month", "projects_started_per_month>commits");
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -83,6 +84,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
}
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -84,6 +85,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
}
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -100,6 +101,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
}
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public MovingAverageLinearAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -78,6 +79,7 @@ public MovingAverageLinearAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
Model = new LinearModel()
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -81,6 +82,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
Model = new SimpleModel()
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -86,6 +87,7 @@ public MovingFunctionAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsag
Script = "MovingFunctions.unweightedAvg(values)"
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public PercentilesBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -68,6 +69,7 @@ public PercentilesBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
{
Percents = new[] { 95, 99, 99.9 }
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand Down Expand Up @@ -69,6 +70,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
Lag = 2
}
};
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public StatsBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage u
}
};

#pragma warning disable 618, 612
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.DateHistogram("projects_started_per_month", dh => dh
.Field(p => p.StartedOn)
Expand All @@ -63,6 +64,7 @@ public StatsBucketAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage u
Aggregations = new SumAggregation("commits", "numberOfCommits")
}
&& new StatsBucketAggregation("stats_commits_per_month", "projects_started_per_month>commits");
#pragma warning restore 618, 612

protected override void ExpectResponse(ISearchResponse<Project> response)
{
Expand Down
Loading

0 comments on commit 802c570

Please sign in to comment.