Skip to content

fix(diffy): compare Long fields exactly in AvroDiffy - #942

Open
pcbeingused33 wants to merge 1 commit into
spotify:masterfrom
pcbeingused33:fix/avrodiffy-long-precision
Open

pcbeingused33 wants to merge 1 commit into
spotify:masterfrom
pcbeingused33:fix/avrodiffy-long-precision

Conversation

@pcbeingused33

Copy link
Copy Markdown

AvroDiffy converted numeric fields to Double before checking equality. Long values above 2^53 lose precision in that conversion, so two records whose ids differ only past that point (for example 9007199254740992 and 9007199254740993) were reported as identical and BigDiffy hid the change.

Compare two Longs exactly instead. The delta is still computed through the overridable numericDelta hook, so it stays a Double (it can be 0.0 for two distinct Longs that round to the same Double, but the difference is now reported). Int, Float and Double keep the existing Double comparison (including NaN semantics), and a test covers that.

Testing and validation

New AvroDiffyTest case "detect differences between Longs above 2^53": fails on current master (the diff is empty), passes with the fix and reports the difference (NumericDelta(0.0), since the Doubles round equal). A second test checks that Double fields keep the existing comparison (NaN case). AvroDiffyTest passes (10 tests).

sbt "ratatoolDiffy/testOnly com.spotify.ratatool.diffy.AvroDiffyTest" on JDK 17, Scala 2.12.21.

AI assistance was used to prepare this change and its tests.

Longs were converted to Double before the equality check, so values that
differ only above 2^53 were reported as identical. Compare two Longs
exactly; the delta still goes through numericDelta. Other numeric types
keep the Double comparison.
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.

1 participant