Skip to content

Commit

Permalink
Pancake - quickfix (date) histogram (#604)
Browse files Browse the repository at this point in the history
We want all the buckets in `(date) histogram`, so there should be no
limit
  • Loading branch information
trzysiek authored Aug 5, 2024
1 parent 8ee3727 commit 2eefe0e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
5 changes: 3 additions & 2 deletions quesma/queryparser/pancake_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type pancakeAggregationLevel struct {
// only for bucket aggregations
children []*pancakeAggregationLevel
orderBy []model.OrderByExpr
limit int // 0 if none, only for bucket aggregation
limit int // pancakeBucketAggregationNoLimit if none, only for bucket aggregation
isKeyed bool
filterOutEmptyKeyBucket bool

Expand All @@ -45,7 +45,7 @@ type pancakeLayerBucketAggregation struct {

// only for bucket aggregations
orderBy []model.OrderByExpr
limit int // 0 if none, only for bucket aggregation
limit int // pancakeBucketAggregationNoLimit if none
isKeyed bool

metadata model.JsonMap
Expand Down Expand Up @@ -81,6 +81,7 @@ type pancakeAggregation struct {
}

const PancakeTotalCountMetricName = "__quesma_total_count"
const pancakeBucketAggregationNoLimit = 0

// Not a real aggregation, but it is a pancake that has alternative JSON rendering
type PancakeQueryType struct {
Expand Down
6 changes: 4 additions & 2 deletions quesma/queryparser/pancake_query_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ func (p *pancakeQueryGenerator) generateSelectCommand(aggregation *pancakeAggreg
}
}

whereRank := model.NewInfixExpr(p.newQuotedLiteral(aliasedRank.Alias), "<=", model.NewLiteral(bucketAggregation.limit))
whereRanks = append(whereRanks, whereRank)
if bucketAggregation.limit != pancakeBucketAggregationNoLimit {
whereRank := model.NewInfixExpr(p.newQuotedLiteral(aliasedRank.Alias), "<=", model.NewLiteral(bucketAggregation.limit))
whereRanks = append(whereRanks, whereRank)
}

rankOrderBy := model.NewOrderByExpr([]model.Expr{p.newQuotedLiteral(aliasedRank.Alias)}, model.AscOrder)
rankOrderBys = append(rankOrderBys, rankOrderBy)
Expand Down
7 changes: 0 additions & 7 deletions quesma/queryparser/pancake_query_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func TestPancakeQueryGeneration(t *testing.T) {

for i, test := range allAggregationTestsWithoutPipeline() { // TODO fix pipeline
t.Run(test.TestName+"("+strconv.Itoa(i)+")", func(t *testing.T) {
// --------
// TODO FIXME
// Fix date_histogram always having WHERE "aggr__0__1__order_1_rank"<=0
// It's wrong and should be an easy fix.
// It's e.g. test with i == 2
// --------

if test.ExpectedPancakeSQL == "" || test.ExpectedPancakeResults == nil { // TODO remove this
t.Skip("Not updated answers for pancake.")
}
Expand Down
10 changes: 5 additions & 5 deletions quesma/testdata/aggregation_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ var AggregationTests = []AggregationTestCase{
AND "timestamp"<=parseDateTime64BestEffort('2024-02-09T13:47:16.029Z'))
GROUP BY "FlightDelayType" AS "aggr__0__key_0",
toInt64(toUnixTimestamp64Milli("timestamp") / 10800000) AS "aggr__0__1__key_0"))
WHERE ("aggr__0__order_1_rank"<=10 AND "aggr__0__1__order_1_rank"<=0)
WHERE "aggr__0__order_1_rank"<=10
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
},
{ // [3]
Expand Down Expand Up @@ -2032,7 +2032,7 @@ var AggregationTests = []AggregationTestCase{
parseDateTime64BestEffort('2024-02-09T16:36:49.940Z')))
GROUP BY "severity" AS "aggr__0__key_0", toInt64(toUnixTimestamp64Milli(
"@timestamp") / 10800000) AS "aggr__0__1__key_0"))
WHERE ("aggr__0__order_1_rank"<=3 AND "aggr__0__1__order_1_rank"<=0)
WHERE "aggr__0__order_1_rank"<=3
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
},
{ // [10]
Expand Down Expand Up @@ -2860,7 +2860,7 @@ var AggregationTests = []AggregationTestCase{
GROUP BY COALESCE("event.dataset",'unknown') AS "aggr__stats__key_0",
toInt64(toUnixTimestamp64Milli("@timestamp") / 60000) AS
"aggr__stats__series__key_0"))
WHERE ("aggr__stats__order_1_rank"<=4 AND "aggr__stats__series__order_1_rank"<=0)
WHERE "aggr__stats__order_1_rank"<=4
ORDER BY "aggr__stats__order_1_rank" ASC, "aggr__stats__series__order_1_rank" ASC`,
},
{ // [14], "old" test, also can be found in testdata/requests.go TestAsyncSearch[5]
Expand Down Expand Up @@ -7066,7 +7066,7 @@ var AggregationTests = []AggregationTestCase{
WHERE ("message" IS NOT NULL AND NOT ("message" iLIKE '%US%'))
GROUP BY "host.name" AS "aggr__0__key_0", "FlightDelayMin" AS
"aggr__0__1__key_0"))
WHERE ("aggr__0__order_1_rank"<=8 AND "aggr__0__1__order_1_rank"<=0)
WHERE "aggr__0__order_1_rank"<=8
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
},
{ // [36]
Expand Down Expand Up @@ -7332,7 +7332,7 @@ var AggregationTests = []AggregationTestCase{
WHERE ("message" IS NOT NULL AND NOT ("message" iLIKE '%US%'))
GROUP BY "host.name" AS "aggr__0__key_0", "FlightDelayMin" AS
"aggr__0__1__key_0"))
WHERE ("aggr__0__order_1_rank"<=10 AND "aggr__0__1__order_1_rank"<=0)
WHERE "aggr__0__order_1_rank"<=10
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
},
{ // [38]
Expand Down

0 comments on commit 2eefe0e

Please sign in to comment.