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

Commit 4061c35

Browse files
committed
Add test
1 parent 7c7c5da commit 4061c35

File tree

2 files changed

+240
-0
lines changed

2 files changed

+240
-0
lines changed

quesma/queryparser/pancake_sql_query_generation_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func TestPancakeQueryGeneration(t *testing.T) {
5252
if filters(test.TestName) {
5353
t.Skip("Fix filters")
5454
}
55+
56+
if test.TestName == "Terms with order by top metrics(file:kibana-visualize/agg_req,nr:9)" {
57+
t.Skip("Fails in real life because of transformations, passes here. Fix it by adding query transformations here.")
58+
}
59+
5560
if test.TestName == "complex sum_bucket. Reproduce: Visualize -> Vertical Bar: Metrics: Sum Bucket (Bucket: Date Histogram, Metric: Average), Buckets: X-Asis: Histogram(file:opensearch-visualize/pipeline_agg_req,nr:22)" {
5661
t.Skip("error: filter(s)/range/dataRange aggregation must be the last bucket aggregation")
5762
}

quesma/testdata/kibana-visualize/aggregation_requests.go

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,4 +1784,239 @@ var AggregationTests = []testdata.AggregationTestCase{
17841784
WHERE "aggr__0__order_1_rank"<=13
17851785
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
17861786
},
1787+
{ // [9]
1788+
TestName: "Kibana 8.15 TSVB -> Metric, Aggregation: Top hit",
1789+
QueryRequestJson: `
1790+
{
1791+
"aggs": {
1792+
"timeseries": {
1793+
"aggs": {
1794+
"badccb5b-5077-4bc9-9cbb-8a13abb0e33f": {
1795+
"aggs": {
1796+
"docs": {
1797+
"top_hits": {
1798+
"fields": [
1799+
"message"
1800+
],
1801+
"size": 1
1802+
}
1803+
}
1804+
},
1805+
"filter": {
1806+
"exists": {
1807+
"field": "message"
1808+
}
1809+
}
1810+
}
1811+
},
1812+
"date_histogram": {
1813+
"extended_bounds": {
1814+
"max": 1731580657318,
1815+
"min": 1731526657318
1816+
},
1817+
"field": "timestamp",
1818+
"fixed_interval": "600s",
1819+
"min_doc_count": 0,
1820+
"time_zone": "Europe/Warsaw"
1821+
},
1822+
"meta": {
1823+
"dataViewId": "d3d7af60-4c81-11e8-b3d7-01146121b73d",
1824+
"indexPatternString": "kibana_sample_data_flights",
1825+
"intervalString": "600s",
1826+
"normalized": true,
1827+
"panelId": "a7039566-0e44-48bb-8677-ff54cc3d8d20",
1828+
"seriesId": "4dd4251c-43c2-4e53-b07a-e7562564c70e",
1829+
"timeField": "timestamp"
1830+
}
1831+
}
1832+
},
1833+
"size": 0,
1834+
"timeout": "30000ms",
1835+
"track_total_hits": true
1836+
}`,
1837+
ExpectedResponse: `
1838+
{
1839+
"completion_time_in_millis": 1726937127128,
1840+
"expiration_time_in_millis": 1726937187124,
1841+
"id": "Fm9QLU5BRXFoVEwyQk1WWC1XalJ1R2cccjdQX1ljN3hSYktWdjNya1RCY3BSdzoxMjM5Mg==",
1842+
"is_partial": false,
1843+
"is_running": false,
1844+
"response": {
1845+
"_shards": {
1846+
"failed": 0,
1847+
"skipped": 0,
1848+
"successful": 1,
1849+
"total": 1
1850+
},
1851+
"aggregations": {
1852+
"other-filter": {
1853+
"buckets": {
1854+
"": {
1855+
"1": {
1856+
"buckets": [
1857+
{
1858+
"2-bucket": {
1859+
"2-metric": {
1860+
"top": [
1861+
{
1862+
"metrics": {
1863+
"DistanceKilometers": 8619.34375
1864+
},
1865+
"sort": [
1866+
"2024-09-09T09:56:35.000Z"
1867+
]
1868+
}
1869+
]
1870+
},
1871+
"doc_count": 140
1872+
},
1873+
"doc_count": 140,
1874+
"key": 1725832800000,
1875+
"key_as_string": "2024-09-09T00:00:00.000+02:00"
1876+
},
1877+
{
1878+
"2-bucket": {
1879+
"2-metric": {
1880+
"top": [
1881+
{
1882+
"metrics": {
1883+
"DistanceKilometers": 11549.353515625
1884+
},
1885+
"sort": [
1886+
"2024-09-09T21:58:01.000Z"
1887+
]
1888+
}
1889+
]
1890+
},
1891+
"doc_count": 178
1892+
},
1893+
"doc_count": 178,
1894+
"key": 1725876000000,
1895+
"key_as_string": "2024-09-09T12:00:00.000+02:00"
1896+
},
1897+
{
1898+
"2-bucket": {
1899+
"2-metric": {
1900+
"top": [
1901+
{
1902+
"metrics": {
1903+
"DistanceKilometers": 10641.537109375
1904+
},
1905+
"sort": [
1906+
"2024-09-10T09:59:52.000Z"
1907+
]
1908+
}
1909+
]
1910+
},
1911+
"doc_count": 146
1912+
},
1913+
"doc_count": 146,
1914+
"key": 1725919200000,
1915+
"key_as_string": "2024-09-10T00:00:00.000+02:00"
1916+
}
1917+
]
1918+
},
1919+
"2-bucket": {
1920+
"2-metric": {
1921+
"top": [
1922+
{
1923+
"metrics": {
1924+
"DistanceKilometers": 11077.248046875
1925+
},
1926+
"sort": [
1927+
"2024-09-21T16:42:22.000Z"
1928+
]
1929+
}
1930+
]
1931+
},
1932+
"doc_count": 4032
1933+
},
1934+
"doc_count": 4032
1935+
}
1936+
}
1937+
}
1938+
},
1939+
"hits": {
1940+
"hits": [],
1941+
"max_score": null,
1942+
"total": {
1943+
"relation": "eq",
1944+
"value": 4044
1945+
}
1946+
},
1947+
"timed_out": false,
1948+
"took": 4
1949+
},
1950+
"start_time_in_millis": 1726937127124
1951+
}`,
1952+
ExpectedPancakeResults: []model.QueryResultRow{ // incorrect
1953+
{Cols: []model.QueryResultCol{
1954+
model.NewQueryResultCol("aggr__0__key_0", int64(1716834210000/30000)),
1955+
model.NewQueryResultCol("aggr__0__count", 4),
1956+
model.NewQueryResultCol("aggr__0__1__parent_count", uint64(4)),
1957+
model.NewQueryResultCol("aggr__0__1__key_0", "artemis"),
1958+
model.NewQueryResultCol("aggr__0__1__key_1", "error"),
1959+
model.NewQueryResultCol("aggr__0__1__count", 1),
1960+
}},
1961+
{Cols: []model.QueryResultCol{
1962+
model.NewQueryResultCol("aggr__0__key_0", int64(1716834210000/30000)),
1963+
model.NewQueryResultCol("aggr__0__count", 4),
1964+
model.NewQueryResultCol("aggr__0__1__parent_count", uint64(4)),
1965+
model.NewQueryResultCol("aggr__0__1__key_0", "artemis"),
1966+
model.NewQueryResultCol("aggr__0__1__key_1", "info"),
1967+
model.NewQueryResultCol("aggr__0__1__count", 1),
1968+
}},
1969+
{Cols: []model.QueryResultCol{
1970+
model.NewQueryResultCol("aggr__0__key_0", int64(1716834210000/30000)),
1971+
model.NewQueryResultCol("aggr__0__count", 4),
1972+
model.NewQueryResultCol("aggr__0__1__parent_count", uint64(4)),
1973+
model.NewQueryResultCol("aggr__0__1__key_0", "jupiter"),
1974+
model.NewQueryResultCol("aggr__0__1__key_1", "info"),
1975+
model.NewQueryResultCol("aggr__0__1__count", 1),
1976+
}},
1977+
{Cols: []model.QueryResultCol{
1978+
model.NewQueryResultCol("aggr__0__key_0", int64(1716834270000/30000)),
1979+
model.NewQueryResultCol("aggr__0__count", 16),
1980+
model.NewQueryResultCol("aggr__0__1__parent_count", uint64(15)),
1981+
model.NewQueryResultCol("aggr__0__1__key_0", "apollo"),
1982+
model.NewQueryResultCol("aggr__0__1__key_1", "info"),
1983+
model.NewQueryResultCol("aggr__0__1__count", 2),
1984+
}},
1985+
{Cols: []model.QueryResultCol{
1986+
model.NewQueryResultCol("aggr__0__key_0", int64(1716834270000/30000)),
1987+
model.NewQueryResultCol("aggr__0__count", 16),
1988+
model.NewQueryResultCol("aggr__0__1__parent_count", uint64(15)),
1989+
model.NewQueryResultCol("aggr__0__1__key_0", "cassandra"),
1990+
model.NewQueryResultCol("aggr__0__1__key_1", "debug"),
1991+
model.NewQueryResultCol("aggr__0__1__count", 1),
1992+
}},
1993+
},
1994+
ExpectedPancakeSQL: `
1995+
SELECT "aggr__0__parent_count", "aggr__0__key_0", "aggr__0__count",
1996+
"aggr__0__order_1", "aggr__0__1__key_0", "aggr__0__1__count",
1997+
"aggr__0__1__2-bucket__count"
1998+
FROM (
1999+
SELECT "aggr__0__parent_count", "aggr__0__key_0", "aggr__0__count",
2000+
"aggr__0__order_1", "aggr__0__1__key_0", "aggr__0__1__count",
2001+
"aggr__0__1__2-bucket__count",
2002+
dense_rank() OVER (ORDER BY "aggr__0__order_1" DESC, "aggr__0__key_0" ASC)
2003+
AS "aggr__0__order_1_rank",
2004+
dense_rank() OVER (PARTITION BY "aggr__0__key_0" ORDER BY
2005+
"aggr__0__1__key_0" ASC) AS "aggr__0__1__order_1_rank"
2006+
FROM (
2007+
SELECT sum(count(*)) OVER () AS "aggr__0__parent_count",
2008+
"AvgTicketPrice" AS "aggr__0__key_0",
2009+
sum(count(*)) OVER (PARTITION BY "aggr__0__key_0") AS "aggr__0__count",
2010+
"top_metrics__0__2-bucket__2-metric_col_0" AS "aggr__0__order_1",
2011+
toInt64((toUnixTimestamp64Milli("timestamp")+timeZoneOffset(toTimezone(
2012+
"timestamp", 'Europe/Warsaw'))*1000) / 43200000) AS "aggr__0__1__key_0",
2013+
count(*) AS "aggr__0__1__count",
2014+
countIf("bytes_gauge" IS NOT NULL) AS "aggr__0__1__2-bucket__count"
2015+
FROM __quesma_table_name
2016+
GROUP BY "AvgTicketPrice" AS "aggr__0__key_0",
2017+
toInt64((toUnixTimestamp64Milli("timestamp")+timeZoneOffset(toTimezone(
2018+
"timestamp", 'Europe/Warsaw'))*1000) / 43200000) AS "aggr__0__1__key_0"))
2019+
WHERE "aggr__0__order_1_rank"<=13
2020+
ORDER BY "aggr__0__order_1_rank" ASC, "aggr__0__1__order_1_rank" ASC`,
2021+
},
17872022
}

0 commit comments

Comments
 (0)