fix: Overflow when reading Timestamp from parquet file #542
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.
Which issue does this PR close?
Closes #481.
Rationale for this change
When spark reads and writes timestamps in parquet file it using the following code: https://github.com/apache/spark/blob/v3.5.1/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala#L48-L66 to convert from the Long microsecond timestamp into the julian date + nano second format used in parquet. Because of the logic is implement dates like
290000-12-31T01:00:00+02:00
will lead to overflow both when encoding and decoding the value. Since it for both the reading and writing it "cancels out" and still gives the expected results. This means the date in year 290000 is stored with a negative day offset, which to me is a bit unexpected.What changes are included in this PR?
This changes the comet code to use wrapping_mul/add to make it explicit that wrapping overflow is expected and needed to match Spark behavior.
How are these changes tested?
Existing and new unit test in CometCastSuite.