Repository navigation
Conversation
checkAnswerWithTolerance skipped the comparison for a float/double pair whenever either side was NaN, so a Comet NaN against a Spark number passed. Every `query tolerance=...` SQL fixture uses that helper, so none of them could catch a kernel returning NaN where Spark returns a value. NaN-ness is now asserted explicitly for both Double and Float. The infinity branch compares the values instead of only their infinite-ness, so +Infinity no longer matches -Infinity, which Spark treats as distinct. Four regression tests cover both types and both directions, finite values inside and outside the tolerance, and the infinity cases. The row overload becomes protected so the suite that consumes the tolerance path can assert the changed method directly, rather than through a copy. Verified on the Spark 4.1 profile: CometSqlFileTestSuite and CometMathExpressionSuite ran 812 tests with none failing, including the 108 `query tolerance=` queries. The one-sided NaN test failed before the fix with "Expected exception ... to be thrown, but no exception was thrown".
cf8bde9 to
59d71fc
Compare
dwsmith1983
left a comment
There was a problem hiding this comment.
This fixes #7672. I checked it end to end with a query tolerance=1e-6 fixture over ln(monotonically_increasing_id() % 3 - 1) with spark.comet.batchSize=2, which still hits #7671 on main: Comet returns NaN where Spark returns 0.0. The fixture passes on main and fails on this branch with "only one side is NaN".
The stricter check also backs checkSparkAnswerWithTolerance outside the SQL file suite, and CI hasn't run here. So I ran every test on this path on Spark 3.5, 4.0, 4.1 and 4.2: the full CometSqlFileTestSuite plus the 11 tolerance tests in CometExpressionSuite, CometAggregateSuite and CometWindowExecSuite. All 816 pass on each profile.
A few small things, none blocking:
-
Could the description say
Closes #7672? It isn't a draft anymore, and as written the issue stays open after the merge. -
The infinity branch now compares by value, so
+Infinityagainst-Infinityfails. The description also calls that hole out of scope, which contradicts the code and the test comment. -
With that change, these still describe the old behavior:
- the
pow.sqlcomment rewritten here ("ignores the sign of Infinity") csc.sql:28("tolerance only checks isInfinity")sql-file-tests.mdlines 259-261, 268 and 486-488
Signed zero is the only case left that needs a plain
query. - the
-
On the old code the infinities test fails too, since
isInfinity == isInfinityholds for+Infand-Inf. So the RED run should show two failures, not one.
comphead
left a comment
There was a problem hiding this comment.
The new branch order in checkAnswerWithTolerance is correct for both arms. Infinity is compared by value first, so +Inf against -Inf or against NaN fails. Then any NaN requires both sides to be NaN, and only finite pairs use absTol. Both directions are covered because the check is symmetric, and null against NaN still reaches the fallback actual == expected arm and fails. I found no fixture added to main since the merge base that uses tolerance=. I did not run any tests. The author reports 812 passing on one profile and dwsmith1983 reports 816 on Spark 3.5, 4.0, 4.1 and 4.2, which is the evidence that no existing test relied on a NaN against a number matching. The stale comment and documentation points from dwsmith1983's review (pow.sql, csc.sql:28, sql-file-tests.md line 260) are still present at this head.
| } | ||
| } | ||
|
|
||
| test("tolerance comparison: one-sided NaN") { |
There was a problem hiding this comment.
The one-sided cases only use finite numbers. Two other routes into the NaN logic are untested. Row(null) against Row(Double.NaN) goes through the final actual == expected arm, and Row(Double.PositiveInfinity) against Row(Double.NaN) goes through the infinity branch, whose message does not say only one side is NaN. Adding both pairs to this test (in both directions) pins the behavior for a null Spark result against a NaN Comet result, which is the likely shape of a real kernel bug.
Which issue does this PR close?
Issue: #7672 (reference only; this draft does not request auto-closure).
Rationale for this change
checkAnswerWithToleranceinCometTestBaseskips a float/double comparison whenevereither side is NaN, so a Comet NaN against a Spark number passes. Every
query tolerance=...SQL fixture uses this comparison, which means such a fixture cannot catch a kernel that
returns NaN where Spark returns a number.
What changes are included in this PR?
CometTestBase.checkAnswerWithTolerancecompares NaN-ness explicitly: two NaNs match, andone-sided NaN fails with
actual answer <v> and correct answer <v> differ: only one side is NaN. The infinity branch compares the values rather than only their infinite-ness, so+Infinityno longer matches-Infinity, and finite values keep the existingabs(actual - expected) < absTolcheck.protectedso the suite that consumes the tolerance path canassert the contract directly.
CometSqlFileTestSuitecover both-NaN, one-sided NaN (Float andDouble, both directions), finite values inside/outside
absTol, and infinities including thetwo sign-flipped pairs.
pow.sqljustified exact comparison by claiming a tolerance comparison makesno assertion for NaN. That claim is now false, so it is corrected; the surviving reasons are
the signed Infinity and signed zero cases.
No production code and no assertion in an existing suite is modified; the only fixture change is
that comment. The pre-existing hole where
+Infcompares equal to-Infis out of scope and isnamed in the infinity test's comment.
How are these changes tested?
Tests: succeeded 3, failed 1; theone-sided NaN test fails with "Expected exception ... TestFailedException to be thrown, but
no exception was thrown".
Tests: succeeded 4, failed 0.org.apache.comet.CometSqlFileTestSuite(all fixtures, 108query tolerance=queries in37 files) plus
CometMathExpressionSuite:Tests: succeeded 812, failed 0, run on the finalcommit
59d71fce0.org.apache.comet.CometMathExpressionSuite:Tests: succeeded 7, failed 0.Run in
nix-shell -p jdk17 maven cargo rustc protobuf cmake clangwith./mvnw test -Dtest=none -Dsuites="<suite>".