Skip to content

SQL: Implement scripting inside aggs (#55241)#55371

Merged
matriv merged 2 commits intoelastic:7.xfrom
matriv:backport-55241
Apr 17, 2020
Merged

SQL: Implement scripting inside aggs (#55241)#55371
matriv merged 2 commits intoelastic:7.xfrom
matriv:backport-55241

Conversation

@matriv
Copy link
Copy Markdown
Contributor

@matriv matriv commented Apr 17, 2020

Implement the use of scalar functions inside aggregate functions.
This allows for complex expressions inside aggregations, with or without
GROUBY as well as with or without a HAVING clause. e.g.:

SELECT MAX(CASE WHEN a IS NULL then -1 ELSE abs(a * 10) + 1 END) AS max, b
FROM test
GROUP BY b
HAVING MAX(CASE WHEN a IS NULL then -1 ELSE abs(a * 10) + 1 END) > 5

Scalar functions are still not allowed for KURTOSIS and SKEWNESS as
this is currently not implemented on the ElasticSearch side.

Fixes: #29980
Fixes: #36865
Fixes: #37271

(cherry picked from commit 506d1be)

Implement the use of scalar functions inside aggregate functions.
This allows for complex expressions inside aggregations, with or without
GROUBY as well as with or without a HAVING clause. e.g.:

```
SELECT MAX(CASE WHEN a IS NULL then -1 ELSE abs(a * 10) + 1 END) AS max, b
FROM test
GROUP BY b
HAVING MAX(CASE WHEN a IS NULL then -1 ELSE abs(a * 10) + 1 END) > 5
```

Scalar functions are still not allowed for `KURTOSIS` and `SKEWNESS` as
this is currently not implemented on the ElasticSearch side.

Fixes: elastic#29980
Fixes: elastic#36865
Fixes: elastic#37271
(cherry picked from commit 506d1be)
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-ql (:Query Languages/SQL)

@matriv matriv merged commit f958e9a into elastic:7.x Apr 17, 2020
@matriv matriv deleted the backport-55241 branch April 17, 2020 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants