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

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

Merged
merged 4 commits into from
Nov 1, 2022

Conversation

Yury-Fridlyand
Copy link

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

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",

Choose a reason for hiding this comment

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

😆

@acarbonetto
Copy link

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

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

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?

Copy link
Author

@Yury-Fridlyand Yury-Fridlyand Oct 27, 2022

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"}

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
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}

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
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)

Copy link

@MitchellGale MitchellGale left a comment

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