From 65c84e62b9b800ff147a3768e506b8530e610da5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kiewicz Date: Tue, 7 May 2024 22:51:54 +0200 Subject: [PATCH] Add test --- .../aggregation_requests.go | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/quesma/testdata/opensearch-visualize/aggregation_requests.go b/quesma/testdata/opensearch-visualize/aggregation_requests.go index 61cec663d..f813aded2 100644 --- a/quesma/testdata/opensearch-visualize/aggregation_requests.go +++ b/quesma/testdata/opensearch-visualize/aggregation_requests.go @@ -620,4 +620,144 @@ var AggregationTests = []testdata.AggregationTestCase{ `WHERE "epoch_time">='2024-04-18T04:40:12.252Z' AND "epoch_time"<='2024-05-03T04:40:12.252Z' `, }, }, + { // [4] + TestName: "Min/max with simple script. Reproduce: Visualize -> Line -> Metrics: Count, Buckets: X-Asis Histogram", + QueryRequestJson: ` + { + "_source": { + "excludes": [] + }, + "aggs": { + "maxAgg": { + "max": { + "script": { + "lang": "painless", + "source": "doc['timestamp'].value.getHour()" + } + } + }, + "minAgg": { + "min": { + "script": { + "lang": "painless", + "source": "doc['timestamp'].value.getHour()" + } + } + } + }, + "docvalue_fields": [ + { + "field": "@timestamp", + "format": "date_time" + }, + { + "field": "timestamp", + "format": "date_time" + }, + { + "field": "utc_time", + "format": "date_time" + } + ], + "query": { + "bool": { + "filter": [], + "must": [ + { + "match_all": {} + } + ], + "must_not": [], + "should": [] + } + }, + "script_fields": { + "hour_of_day": { + "script": { + "lang": "painless", + "source": "doc['timestamp'].value.getHour()" + } + } + }, + "size": 0, + "stored_fields": [ + "*" + ] + }`, + ExpectedResponse: ``, + ExpectedResults: [][]model.QueryResultRow{}, + ExpectedSQLs: []string{}, + }, + { // [5] + TestName: "Histogram with simple script. Reproduce: Visualize -> Line -> Metrics: Count, Buckets: X-Asis Histogram", + QueryRequestJson: ` + { + "_source": { + "excludes": [] + }, + "aggs": { + "2": { + "histogram": { + "interval": 1, + "min_doc_count": 1, + "script": { + "lang": "painless", + "source": "doc['timestamp'].value.getHour()" + } + } + } + }, + "docvalue_fields": [ + { + "field": "@timestamp", + "format": "date_time" + }, + { + "field": "timestamp", + "format": "date_time" + }, + { + "field": "utc_time", + "format": "date_time" + } + ], + "query": { + "bool": { + "filter": [ + { + "range": { + "timestamp": { + "format": "strict_date_optional_time", + "gte": "2024-05-07T20:32:10.918Z", + "lte": "2024-05-07T20:47:10.918Z" + } + } + } + ], + "must": [ + { + "match_all": {} + } + ], + "must_not": [], + "should": [] + } + }, + "script_fields": { + "hour_of_day": { + "script": { + "lang": "painless", + "source": "doc['timestamp'].value.getHour()" + } + } + }, + "size": 0, + "stored_fields": [ + "*" + ] + }`, + ExpectedResponse: ``, + ExpectedResults: [][]model.QueryResultRow{}, + ExpectedSQLs: []string{}, + }, }