Skip to content

Fix incorrect results returned by min, max and avg - #145

Merged
Yury-Fridlyand merged 4 commits into
integ-fix-aggreg-on-nullsfrom
dev-fix-aggreg-on-nulls
Nov 1, 2022
Merged

Yury-Fridlyand merged 4 commits into
integ-fix-aggreg-on-nullsfrom
dev-fix-aggreg-on-nulls

Conversation

@Yury-Fridlyand

@Yury-Fridlyand Yury-Fridlyand commented Oct 26, 2022 •

Copy link
Copy Markdown

Fix incorrect results returned by min, max and avg when processing null/missing values only.

Signed-off-by: Yury-Fridlyand [email protected]

Description

Before

opensearchsql> select min(int0) from calcs where int0 IS NULL;
fetched rows / total rows = 1/1
+-------------+
| min(int0)   |
|-------------|
| 2147483647  |
+-------------+

After

opensearchsql> select min(int0) from calcs where int0 IS NULL;
fetched rows / total rows = 1/1
+-------------+
| min(int0)   |
|-------------|
| null        |
+-------------+

Fixed:

  • min
  • max
  • avg

Not fixed:

  • sum
opensearchsql> select sum(int0) from calcs where int0 IS NULL;
fetched rows / total rows = 1/1
+-------------+
| sum(int0)   |
|-------------|
| 0           |
+-------------+
mysql> select sum(int0) from calcs where int0 IS NULL;

+-----------+
| sum(int0) |
+-----------+
|      NULL |
+-----------+
1 row in set (0.00 sec)

This requires much more changes.

Not affected

  • var_samp
  • var_pop
  • stddev_samp
  • stddev_pop

Issues Resolved

opensearch-project#817

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

… on null/missing values.

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand
Yury-Fridlyand marked this pull request as ready for review October 27, 2022 00:40
@Bit-Quill Bit-Quill deleted a comment from codecov Bot Oct 27, 2022
@codecov

This comment was marked as abuse.

"format": "yyyy-MM-dd"
},
"time" : {
"type" : "date",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

@acarbonetto

Copy link
Copy Markdown

What the MySQL result for sum(null)? Is it supposed to be null or zero?

@@ -0,0 +1,18 @@
{"index":{}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't want to give these index numbers?

@Yury-Fridlyand Yury-Fridlyand Oct 27, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are assigned automatically if not given.

{"index":{}}
{"key" : "values", "int" : 42, "dbl" : 3.1415, "bool" : true, "str" : "pewpew", "date" : "1984-05-22", "time" : "22:13:37", "datetime" : "1984-05-22 22:13:37", "timestamp" : "2000-01-02 03:04:05" }
{"index":{}}
{"key" : "missing"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not confusing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key is not a PK. Just a column.

{"index":{}}
{"key" : "missing"}
{"index":{}}
{"key" : "null", "int" : null, "dbl" : null, "bool" : null, "str" : null, "date" : null, "time" : null, "datetime" : null, "timestamp" : null}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "key": "null" also not confusing?

@Yury-Fridlyand

Copy link
Copy Markdown
Author

What the MySQL result for sum(null)? Is it supposed to be null or zero?

mysql> select sum(num0) from calcs where num0 is null;
+-----------+
| sum(num0) |
+-----------+
|      NULL |
+-----------+
1 row in set (0.00 sec)

@Yury-Fridlyand Yury-Fridlyand mentioned this pull request Oct 27, 2022
6 tasks done

@MitchellGale MitchellGale left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Yury-Fridlyand <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants