-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Deserialize DateHistogram bucket with no sub aggregations #3678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -570,6 +570,18 @@ ref ArraySegment<byte> propertyName | |
items.Add(item); | ||
} | ||
|
||
token = reader.GetCurrentJsonToken(); | ||
if (token == JsonToken.ValueSeparator) | ||
{ | ||
reader.ReadNext(); | ||
propertyName = reader.ReadPropertyNameSegmentRaw(); | ||
if (propertyName.EqualsBytes(JsonWriter.GetEncodedPropertyNameWithoutQuotation("interval"))) | ||
bucket.Interval = formatterResolver.GetFormatter<Time>().Deserialize(ref reader, formatterResolver); | ||
else | ||
// skip for now | ||
reader.ReadNextBlock(); | ||
} | ||
|
||
bucket.Items = items; | ||
reader.ReadNext(); // close outer } | ||
return bucket; | ||
|
@@ -745,15 +757,21 @@ private IBucket GetDateHistogramBucket(ref JsonReader reader, IJsonFormatterReso | |
reader.ReadNext(); // , | ||
reader.ReadNext(); // "key" | ||
reader.ReadNext(); // : | ||
var key = reader.ReadNullableLong().GetValueOrDefault(0); | ||
var key = reader.ReadInt64(); | ||
reader.ReadNext(); // , | ||
reader.ReadNext(); // "doc_count" | ||
reader.ReadNext(); // : | ||
var docCount = reader.ReadNullableLong().GetValueOrDefault(0); | ||
reader.ReadNext(); // , | ||
var docCount = reader.ReadInt64(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, no longer nullable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to previous comment, this is an artifact of porting over from Json.NET. Based on there is always a |
||
|
||
var propertyName = reader.ReadPropertyName(); | ||
var subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver); | ||
Dictionary<string, IAggregate> subAggregates = null; | ||
if (reader.GetCurrentJsonToken() == JsonToken.ValueSeparator) | ||
{ | ||
reader.ReadNext(); // , | ||
russcam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var propertyName = reader.ReadPropertyName(); | ||
subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver); | ||
} | ||
else | ||
reader.ReadNext(); // } | ||
|
||
var dateHistogram = new DateHistogramBucket(subAggregates) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.ManagedElasticsearch.Clusters; | ||
using Tests.Domain; | ||
|
||
namespace Tests.Reproduce | ||
{ | ||
public class GithubIssue3673 : IClusterFixture<ReadOnlyCluster> | ||
{ | ||
private readonly ReadOnlyCluster _cluster; | ||
|
||
public GithubIssue3673(ReadOnlyCluster cluster) => _cluster = cluster; | ||
|
||
[I] | ||
public void DeserializeDateAggregation() | ||
{ | ||
Action action = () => _cluster.Client.Search<Project>(s => s | ||
.Size(0) | ||
.Aggregations(a => a | ||
.DateHistogram("publication_year", st => st | ||
.Field(o => o.StartedOn) | ||
.Interval(DateInterval.Year) | ||
.Format("yyyy") | ||
.MinimumDocumentCount(0) | ||
) | ||
) | ||
); | ||
|
||
action.Should().NotThrow(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an artifact of porting over from Json.NET, where the conversion is made to
long?
- I don't believe nullability it's actually needed here, based onhttps://github.com/elastic/elasticsearch/blob/daa2ec8a605d385a65b9ab3e89d016b3fd0dffe2/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalDateHistogram.java#L114-L116