lyne7-sc opened a new issue, #2453:
URL: https://github.com/apache/auron/issues/2453
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
A grouped aggregate with a `FILTER` clause can fail when a group exists but
none of its rows satisfy the aggregate filter.
The grouping key is created independently of the aggregate filter. However,
the accumulator is currently expanded only when aggregate rows are updated. If
all rows for an aggregate are filtered out, its accumulator may remain shorter
than the number of groups.
The query then fails while producing the result:
```text
index out of bounds: the len is 0 but the index is 0
```
**To Reproduce**
<!--
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
-->
Run a filtered aggregation where one merchant has no refunded orders:
```sql
WITH orders AS (
SELECT * FROM VALUES
('A', 100, 'PAID'),
('A', 20, 'REFUNDED'),
('B', 200, 'PAID'),
('B', 300, 'PAID')
AS orders(merchant_id, amount, status)
)
SELECT
merchant_id,
SUM(amount) FILTER (WHERE status = 'PAID') AS paid_amount,
COUNT(*) FILTER (WHERE status = 'REFUNDED') AS refund_count
FROM orders
GROUP BY merchant_id
ORDER BY merchant_id;
```
**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
All discovered groups should be preserved, using each aggregate's
empty-input value:
```text
A | 100 | 1
B | 500 | 0
```
**Screenshots**
<!--
If applicable, add screenshots to help explain your problem.
-->
**Additional context**
<!--
Add any other context about the problem here.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]