Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 3edc8b0

Browse files
committed
Initial
1 parent 898d937 commit 3edc8b0

File tree

6 files changed

+531
-75
lines changed

6 files changed

+531
-75
lines changed

quesma/queryparser/aggregation_parser_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import (
1010
"quesma/schema"
1111
"quesma/testdata"
1212
"quesma/testdata/clients"
13-
dashboard_1 "quesma/testdata/dashboard-1"
14-
kibana_visualize "quesma/testdata/kibana-visualize"
15-
opensearch_visualize "quesma/testdata/opensearch-visualize"
1613
"testing"
1714
)
1815

@@ -655,17 +652,18 @@ func allAggregationTests() []testdata.AggregationTestCase {
655652
}
656653
}
657654

658-
add(testdata.AggregationTests, "agg_req")
659-
add(testdata.AggregationTests2, "agg_req_2")
660-
add(testdata.AggregationTestsWithDates, "dates")
661-
add(opensearch_visualize.AggregationTests, "opensearch-visualize/agg_req")
662-
add(dashboard_1.AggregationTests, "dashboard-1/agg_req")
663-
add(testdata.PipelineAggregationTests, "pipeline_agg_req")
664-
add(opensearch_visualize.PipelineAggregationTests, "opensearch-visualize/pipeline_agg_req")
665-
add(kibana_visualize.AggregationTests, "kibana-visualize/agg_req")
666-
add(kibana_visualize.PipelineAggregationTests, "kibana-visualize/pipeline_agg_req")
667-
add(clients.KunkkaTests, "clients/kunkka")
668-
add(clients.OpheliaTests, "clients/ophelia")
655+
//add(testdata.AggregationTests, "agg_req")
656+
//add(testdata.AggregationTests2, "agg_req_2")
657+
//add(testdata.AggregationTestsWithDates, "dates")
658+
//add(opensearch_visualize.AggregationTests, "opensearch-visualize/agg_req")
659+
//add(dashboard_1.AggregationTests, "dashboard-1/agg_req")
660+
//add(testdata.PipelineAggregationTests, "pipeline_agg_req")
661+
//add(opensearch_visualize.PipelineAggregationTests, "opensearch-visualize/pipeline_agg_req")
662+
//add(kibana_visualize.AggregationTests, "kibana-visualize/agg_req")
663+
//add(kibana_visualize.PipelineAggregationTests, "kibana-visualize/pipeline_agg_req")
664+
//add(clients.KunkkaTests, "clients/kunkka")
665+
//add(clients.OpheliaTests, "clients/ophelia")
666+
add(clients.CloverTests, "clients/clover")
669667

670668
return allTests
671669
}

quesma/queryparser/pancake_sql_query_generation.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"github.com/k0kubun/pp"
910
"quesma/model"
1011
"quesma/model/bucket_aggregations"
1112
"quesma/model/metrics_aggregations"
@@ -292,7 +293,7 @@ func (p *pancakeSqlQueryGenerator) generateSelectCommand(aggregation *pancakeMod
292293
addIfCombinators := make([]addIfCombinator, 0)
293294
var optTopHitsOrMetrics *pancakeModelMetricAggregation
294295

295-
for _, layer := range aggregation.layers {
296+
for i, layer := range aggregation.layers {
296297
for _, metric := range layer.currentMetricAggregations {
297298
switch metric.queryType.(type) {
298299
case *metrics_aggregations.TopMetrics, *metrics_aggregations.TopHits:
@@ -309,7 +310,15 @@ func (p *pancakeSqlQueryGenerator) generateSelectCommand(aggregation *pancakeMod
309310

310311
if layer.nextBucketAggregation != nil {
311312
if combinator, isCombinator := layer.nextBucketAggregation.queryType.(bucket_aggregations.CombinatorAggregationInterface); isCombinator {
312-
addIfCombinators = append(addIfCombinators, addIfCombinator{len(selectColumns), combinator})
313+
var isFilter bool
314+
pp.Println(combinator)
315+
switch combinator.(type) {
316+
case *bucket_aggregations.FilterAgg, bucket_aggregations.Filters:
317+
isFilter = true
318+
}
319+
if !isFilter || i > 0 {
320+
addIfCombinators = append(addIfCombinators, addIfCombinator{len(selectColumns), combinator})
321+
}
313322
}
314323

315324
if layer.nextBucketAggregation.DoesHaveGroupBy() {
@@ -333,6 +342,7 @@ func (p *pancakeSqlQueryGenerator) generateSelectCommand(aggregation *pancakeMod
333342
// this change selects by adding -If suffix, e.g. count(*) -> countIf(response_time < 1000)
334343
// they may also add more columns with different prefix and where clauses
335344
var combinatorWhere []model.Expr
345+
fmt.Println("len(addIfCombinators): ", len(addIfCombinators))
336346
for i := len(addIfCombinators) - 1; i >= 0; i-- { // reverse order is important
337347
combinator := addIfCombinators[i]
338348
selectsBefore := selectColumns[:combinator.selectNr]

quesma/queryparser/pancake_sql_query_generation_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func TestPancakeQueryGeneration(t *testing.T) {
6060
t.Skip("Need to implement order by top metrics (talk with Jacek, he has an idea)")
6161
}
6262

63+
if i != 0 {
64+
t.Skip()
65+
}
66+
6367
fmt.Println("i:", i, "test:", test.TestName)
6468

6569
jsonp, err := types.ParseJSON(test.QueryRequestJson)

quesma/queryparser/pancake_transformer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,14 @@ type layerAndNextBucket struct {
125125
}
126126

127127
func (a *pancakeTransformer) optimizeSimpleFilter(previousAggrNames []string, result *layerAndNextBucket, childAgg *pancakeAggregationTreeNode) bool {
128+
if len(previousAggrNames) == 0 { // already optimized
129+
//return false
130+
}
131+
128132
_, isFilter := result.nextBucketAggregation.queryType.(bucket_aggregations.FilterAgg)
129133
secondFilter, isFilter2 := childAgg.queryType.(bucket_aggregations.FilterAgg)
130134

135+
fmt.Println("dupa", isFilter, isFilter2, len(childAgg.children))
131136
if isFilter && isFilter2 && len(childAgg.children) == 0 {
132137
metrics, err := a.metricAggregationTreeNodeToModel(previousAggrNames, childAgg)
133138
if err != nil {
@@ -241,6 +246,7 @@ func (a *pancakeTransformer) aggregationChildrenToLayers(aggrNames []string, chi
241246

242247
func (a *pancakeTransformer) checkIfSupported(layers []*pancakeModelLayer) error {
243248
// for now we support filter only as last bucket aggregation
249+
/* let's try to support everything
244250
for layerIdx, layer := range layers {
245251
if layer.nextBucketAggregation != nil {
246252
switch layer.nextBucketAggregation.queryType.(type) {
@@ -253,14 +259,17 @@ func (a *pancakeTransformer) checkIfSupported(layers []*pancakeModelLayer) error
253259
continue // histogram are fine
254260
case bucket_aggregations.CombinatorAggregationInterface:
255261
continue // we also support nested filters/range/dataRange
262+
case *bucket_aggregations.Filters:
263+
continue
256264
default:
257-
return fmt.Errorf("filter(s)/range/dataRange aggregation must be the last bucket aggregation")
265+
return fmt.Errorf("filter(s)/range/dataRange aggregation must be the last bucket aggregation (found %s)", bucket.queryType.String())
258266
}
259267
}
260268
}
261269
}
262270
}
263271
}
272+
*/
264273
return nil
265274
}
266275

@@ -379,6 +388,8 @@ func (a *pancakeTransformer) aggregationTreeToPancakes(topLevel pancakeAggregati
379388
return nil, fmt.Errorf("no top level aggregations found")
380389
}
381390

391+
//pp.Println("pancakeAggregationTree", topLevel, topLevel.children[0])
392+
382393
resultLayers, err := a.aggregationChildrenToLayers([]string{}, topLevel.children)
383394

384395
if err != nil {

0 commit comments

Comments
 (0)