Skip to content

Commit 6e09a10

Browse files
committed
SQL: Translate MIN/MAX on keyword fields as FIRST/LAST
Although the translation rule was implemented in the `Optimizer`, the rule was not added in the list of rules to be executed. Relates to elastic#41195 Follows elastic#37936
1 parent 4fb156a commit 6e09a10

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

x-pack/plugin/sql/qa/src/main/resources/agg.csv-spec

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ SELECT COUNT(ALL last_name)=COUNT(ALL first_name) AS areEqual, COUNT(ALL first_n
414414
false |90 |100
415415
;
416416

417+
topHitsAsMinAndMax
418+
schema::gender:s|first:s|last:s
419+
SELECT gender, MIN(first_name) as first, MAX(first_name) as last FROM test_emp GROUP BY gender ORDER BY gender;
420+
421+
gender | first | last
422+
---------------+---------------+---------------
423+
null | Berni | Patricio
424+
F | Alejandro | Xinglin
425+
M | Amabile | Zvonko
426+
;
427+
417428
topHitsWithOneArgAndGroupBy
418429
schema::gender:s|first:s|last:s
419430
SELECT gender, FIRST(first_name) as first, LAST(first_name) as last FROM test_emp GROUP BY gender ORDER BY gender;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/optimizer/Optimizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ protected Iterable<RuleExecutor<LogicalPlan>.Batch> batches() {
149149

150150
Batch aggregate = new Batch("Aggregation Rewrite",
151151
//new ReplaceDuplicateAggsWithReferences(),
152+
new ReplaceMinMaxWithTopHits(),
152153
new ReplaceAggsWithMatrixStats(),
153154
new ReplaceAggsWithExtendedStats(),
154155
new ReplaceAggsWithStats(),

0 commit comments

Comments
 (0)