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

[BUG] Aggregation functions return invalid result when processing NULLs #817

Closed
2 of 6 tasks
Yury-Fridlyand opened this issue Sep 12, 2022 · 1 comment · Fixed by #1000
Closed
2 of 6 tasks

[BUG] Aggregation functions return invalid result when processing NULLs #817

Yury-Fridlyand opened this issue Sep 12, 2022 · 1 comment · Fixed by #1000
Assignees
Labels
bug Something isn't working SQL

Comments

@Yury-Fridlyand
Copy link
Collaborator

Yury-Fridlyand commented Sep 12, 2022

I use TDVT data set for experiments

dataset
opensearchsql> select int0 i0, int1 i1, int2 from calcs;
fetched rows / total rows = 17/17
+------+------+--------+
| i0   | i1   | int2   |
|------+------+--------|
| 1    | -3   | 5      |
| null | -6   | -4     |
| null | null | 5      |
| null | -4   | -5     |
| 7    | null | 3      |
| 3    | null | 2      |
| 8    | null | 9      |
| null | 2    | 0      |
| null | 3    | -6     |
| 8    | 3    | -9     |
| 4    | null | -3     |
| 10   | -8   | -4     |
| null | null | 0      |
| 4    | null | 4      |
| 11   | null | -8     |
| 4    | null | -9     |
| 8    | -9   | 6      |
+------+------+--------+

The test query:

select max(int0), int1, min(int2) from calcs group by int1;

OpenSearch:

opensearchsql> select max(`int0`), `int1`, min(`int2`) from calcs group by `int1`;
fetched rows / total rows = 8/8
+---------------+--------+---------------+
| max(`int0`)   | int1   | min(`int2`)   |
|---------------+--------+---------------|
| 11            | null   | -9            |
| 8             | -9     | 6             |
| 10            | -8     | -4            |
| -2147483648   | -6     | -4            |
| -2147483648   | -4     | -5            |
| 1             | -3     | 5             |
| -2147483648   | 2      | 0             |
| 8             | 3      | -9            |
+---------------+--------+---------------+

MySQL:

mysql> select max(`int0`), `int1`, min(`int2`) from Calcs group by `int1`;
+-------------+------+-------------+
| max(`int0`) | int1 | min(`int2`) |
+-------------+------+-------------+
|           1 |   -3 |           5 |
|        NULL |   -6 |          -4 |
|          11 | NULL |          -9 |
|        NULL |   -4 |          -5 |
|        NULL |    2 |           0 |
|           8 |    3 |          -9 |
|          10 |   -8 |          -4 |
|           8 |   -9 |           6 |
+-------------+------+-------------+
8 rows in set (0.00 sec)

See also (could be related):

@Yury-Fridlyand Yury-Fridlyand added bug Something isn't working untriaged labels Sep 12, 2022
@dai-chen dai-chen added SQL and removed untriaged labels Sep 12, 2022
@Yury-Fridlyand
Copy link
Collaborator Author

BTW, why GROUP BY reorders rows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants