converter: cast ints to float in float-inferred fields before table build - #132
Merged
Merged
Conversation
…uild JSON producers emit whole floats as integers. PyArrow accepts an int in a double column only when the conversion is exact; an integer above 2^53 makes pa.Table.from_pylist raise ArrowInvalid and the batch crashes before any column coercion runs (session_replay_features carried 130184854372975800 in a mouse aggregate and crash-looped the consumer). Pre-cast ints to float when the inferred field type is floating - nearest-double is the wanted semantics for a floating measure. Int-only fields are untouched and keep exact int64 (existing large-int precision test still passes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
session-replay-featurescrash-loops: the topic's float aggregates JSON-serialize as integers when whole, and one record carried130184854372975800(> 2^53) in a double-inferred field.pa.Table.from_pylistrefuses inexact int→double, so the batch crashes insideconvert()— beforecoerce_typed_columnsruns, which is why thetypedColumnspins (PostHog/charts#15010) can't fix this half of the failure.Fix
_floatify_integers_in_float_fields: after schema inference and mixed-type stringification, cast int values tofloat()for fields the schema types as floating. Nearest-double is the intended semantics for floating measures; PyArrow's exactness check is the only obstacle. Int-only fields are untouched (schema infers int64, no cast) — the existingtest_large_integer_precision_preservedguarding >2^53 int precision still passes.Records are only copied when a cast is needed; the common all-float path allocates nothing.
Tests
test_large_int_in_float_field_converts_lossily(the exact prod poison value) andtest_whole_int_in_float_field_stays_float.Deploy
Standard release path: merge → release workflow → Promote-to-prod retag. The session consumers are scaled to zero pending this + the charts pins; re-enable follows both.