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

Esql eager nans to nulls #98899

Closed

Conversation

not-napoleon
Copy link
Member

Resolve #98698

Turn NaNs and infinite results into nulls, as early as possible.

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.11.0 labels Aug 25, 2023
@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Aug 25, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @not-napoleon, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Aug 25, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

Generally LGTM, I just wonder if we really want to get rid of the infinities as well. (The discussion on the corresponding issue #98698 had no further comments.)

@@ -210,48 +210,6 @@ salary:integer | s:long
73851 | 1330201
;

isFiniteFalse
row d = 1.0 | eval s = is_finite(d/0);
Copy link
Contributor

Choose a reason for hiding this comment

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

question: I see that there were no more comments on your question whether to treat infinities as null, and here we seem to pick the Infinity -> null option.

I may be a bit out of the loop here :) if the discussion proceeded elsewhere than #98698, I'm curious why we want to treat also the infinities as null?

(For what it's worth, I think the infinities are semantically different from NaNs and it's less natural to treat +-Infinity as null, whereas NaN and null have very close meaning to begin with. However, for practical matters, I can imagine that in the end it might not make a difference for the end user and treating all the non-finite double values as null might simplify everything.)

@@ -266,6 +267,7 @@ public final void testSimple() {
// TODO should we convert unsigned_long into BigDecimal so it's easier to assert?
Object result = toJavaObject(evaluator(expression).get().eval(row(testCase.getDataValues())), 0);
assertThat(result, testCase.getMatcher());
assertThat(result, not(equalTo(Double.NaN)));
Copy link
Contributor

Choose a reason for hiding this comment

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

question: should we also assert that the result is neither of the infinities?

Comment on lines +87 to 90
if (rhs == 0) {
throw new ArithmeticException("Division by zero");
}
return lhs / rhs;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this does not cover all the edge cases if we care about infinities. Dividing something big by something small can still end up infinite.

Maybe in this case it's easier to just perform lhs/rhs and throw an ArithmeticException if the result is not finite?

.withWarning("java.lang.ArithmeticException: Division by zero")
),
new TestCaseSupplier(
"1d / 0d",
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I'd add two tests, one for dividing a number close to Double.MAX_VALUE by something close to Double.MIN_VALUE or Double.MIN_NORMAL, and another test for the negative case.

 Conflicts:
	x-pack/plugin/esql/qa/testFixtures/src/main/resources/show.csv-spec
	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java
arg = randomDouble();
} else {
arg = 1 / randomDouble();
}
Copy link
Member

Choose a reason for hiding this comment

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

In #98890 I've introduced something to emit cases for both big and little values. Just makes two cases every time.

@not-napoleon
Copy link
Member Author

We've moved the test framework in a different direction, and this PR is no longer appropriate.

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:QL (Deprecated) Meta label for query languages team v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESQL: replace Float/Double NaN with null
4 participants