Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trzysiek committed Oct 3, 2024
1 parent 22dd051 commit 454d0ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
8 changes: 6 additions & 2 deletions quesma/model/bucket_aggregations/date_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,14 @@ func (query *DateHistogram) NewRowsTransformer() model.QueryRowsTransformer {
differenceBetweenTwoNextKeys := int64(1)
if query.intervalType == DateHistogramCalendarInterval {
duration, err := kibana.ParseInterval(query.interval)
if err != nil {
if err == nil {
differenceBetweenTwoNextKeys = duration.Milliseconds()
} else {
// Let's do 1000 years here (arbitrary huge number), log an error, and continue normally.
// The transformer just won't add any rows.
logger.ErrorWithCtx(query.ctx).Err(err)
differenceBetweenTwoNextKeys = (time.Hour * 24 * 365 * 1000).Milliseconds()
}
differenceBetweenTwoNextKeys = duration.Milliseconds()
}
return &DateHistogramRowsTransformer{minDocCount: query.minDocCount, differenceBetweenTwoNextKeys: differenceBetweenTwoNextKeys}
}
Expand Down
48 changes: 24 additions & 24 deletions quesma/testdata/dates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ var AggregationTestsWithDates = []AggregationTestCase{
TestName: "simple max/min aggregation as 2 siblings",
QueryRequestJson: `
{
"aggs": {
"sampler": {
"aggs": {
"eventRate": {
"date_histogram": {
"extended_bounds": {
"max": 1727859403270,
"min": 1727858503270
},
"field": "order_date",
"calendar_interval": "1w",
"min_doc_count": 0
}
}
},
"random_sampler": {
"probability": 0.000001,
"seed": "1292529172"
}
}
},
"size": 0,
"track_total_hits": false
}`,
"aggs": {
"sampler": {
"aggs": {
"eventRate": {
"date_histogram": {
"extended_bounds": {
"max": 1727859403270,
"min": 1727858503270
},
"field": "order_date",
"calendar_interval": "1w",
"min_doc_count": 0
}
}
},
"random_sampler": {
"probability": 0.000001,
"seed": "1292529172"
}
}
},
"size": 0,
"track_total_hits": false
}`,
ExpectedResponse: `
{
"completion_time_in_millis": 1707486436398,
Expand Down

0 comments on commit 454d0ef

Please sign in to comment.