Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support aggregations across constants #100634

Open
1 of 4 tasks
costin opened this issue Oct 10, 2023 · 7 comments
Open
1 of 4 tasks

Support aggregations across constants #100634

costin opened this issue Oct 10, 2023 · 7 comments
Assignees
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@costin
Copy link
Member

costin commented Oct 10, 2023

Description

In ESQL it is possible to have aggregations working on a constant as long as it comes from a source, however pushing it into the aggregation fails.

This works: row a = 1 | stats m = min(a) but the query stats m = min(1) does not.
We've been looking at adding a dedicated rule for optimizing this ( #100182) however the issue is rather related to folding aggregations.

A somewhat variant of this is folding the aggregation when the argument is the group key itself:
stats mi = min(k), ma = max(k), c = count(k), a = avg(k) by k which is the same as stats by k | keep k as mi, k as ma, k as c, k as a, k

@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Oct 10, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

costin added a commit to costin/elasticsearch that referenced this issue Oct 11, 2023
Add specific check for aliased function declarations in stats

Fix elastic#100634
costin added a commit to costin/elasticsearch that referenced this issue Oct 11, 2023
Add specific check for aliased function declarations in stats

Fix elastic#100634
@costin costin closed this as completed in 3636d3d Oct 11, 2023
costin added a commit to costin/elasticsearch that referenced this issue Oct 11, 2023
…00650)

Add specific check for aliased function declarations in stats

Fix elastic#100634
elasticsearchmachine pushed a commit that referenced this issue Oct 12, 2023
…100738)

Add specific check for aliased function declarations in stats

Fix #100634
@alex-spies
Copy link
Contributor

I think this was closed on accident; just checked and running ROW a = 1 | stats m = min(1) still returns an EsqlIllegalArgumentException (500). Reopening.

@alex-spies alex-spies reopened this Oct 12, 2023
@wchaparro wchaparro added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jan 2, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the Team:QL (Deprecated) Meta label for query languages team label Jan 2, 2024
@alex-spies
Copy link
Contributor

The second variant mentioned in the description cannot be always folded due to multi-values:

POST /testidx/_doc
{"k": [0,1,2,3]}

POST /_query
from testidx | stats mi = min(k),  ma = max(k), c = count(k), a = avg(k) by k

->
      mi       |      ma       |       c       |       a       |   k
---------------+---------------+---------------+---------------+---------------
0              |3              |4              |1.5            |0              
0              |3              |4              |1.5            |1              
0              |3              |4              |1.5            |2              
0              |3              |4              |1.5            |3 

@alex-spies
Copy link
Contributor

Let's also fix STATS COUNT([1,2,3]) as part of this issue (currently - wrongly - treated the same as COUNT(*)) - this should be replaced by STATS MV_COUNT([1,2,3]) * COUNT(*).

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

No branches or pull requests

4 participants