Skip to content

Commit

Permalink
SQL: Translate MIN/MAX on keyword fields as FIRST/LAST
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matriv committed Apr 16, 2019
1 parent 4fb156a commit 6e09a10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/agg.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ SELECT COUNT(ALL last_name)=COUNT(ALL first_name) AS areEqual, COUNT(ALL first_n
false |90 |100
;

topHitsAsMinAndMax
schema::gender:s|first:s|last:s
SELECT gender, MIN(first_name) as first, MAX(first_name) as last FROM test_emp GROUP BY gender ORDER BY gender;

gender | first | last
---------------+---------------+---------------
null | Berni | Patricio
F | Alejandro | Xinglin
M | Amabile | Zvonko
;

topHitsWithOneArgAndGroupBy
schema::gender:s|first:s|last:s
SELECT gender, FIRST(first_name) as first, LAST(first_name) as last FROM test_emp GROUP BY gender ORDER BY gender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ protected Iterable<RuleExecutor<LogicalPlan>.Batch> batches() {

Batch aggregate = new Batch("Aggregation Rewrite",
//new ReplaceDuplicateAggsWithReferences(),
new ReplaceMinMaxWithTopHits(),
new ReplaceAggsWithMatrixStats(),
new ReplaceAggsWithExtendedStats(),
new ReplaceAggsWithStats(),
Expand Down

0 comments on commit 6e09a10

Please sign in to comment.