Hive: Fix integer overflow in HMS createTime and lastAccessTime#16620
Open
wombatu-kun wants to merge 2 commits into
Open
Hive: Fix integer overflow in HMS createTime and lastAccessTime#16620wombatu-kun wants to merge 2 commits into
wombatu-kun wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Baunsgaard
reviewed
Jun 5, 2026
Baunsgaard
left a comment
Contributor
There was a problem hiding this comment.
Good catch, I have a few minor nits.
Comment on lines
-216
to
-217
| (int) currentTimeMillis / 1000, | ||
| (int) currentTimeMillis / 1000, |
Contributor
There was a problem hiding this comment.
Since you are anyway fixing it, it is a bit odd to do the calculation twice,
How about editing the variable above and call it:
final int currentTime = (int) (System.currentTimeMillis() / 1000L);
Contributor
Author
There was a problem hiding this comment.
Done 2334107 - hoisted into a single currentTimeSeconds local (named for the unit) in both the table and view creation paths.
Comment on lines
+183
to
+185
| // HMS overwrites createTime server-side on create, but keeps the lastAccessTime that Iceberg | ||
| // sends. Computing it as '(int) currentTimeMillis / 1000' casts the long before dividing and | ||
| // overflows to a 1970-era value; assert it instead reflects the current epoch second. |
Contributor
There was a problem hiding this comment.
I would suggest removing this comment.
Contributor
Author
There was a problem hiding this comment.
Done 2334107 - also dropped the mirrored comment in the view test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
HiveOperationsBase.newHmsTableandHiveViewOperations.newHMSViewset the HMScreateTimeandlastAccessTimeas(int) currentTimeMillis / 1000. Java operator precedence makes this((int) currentTimeMillis) / 1000, so the 64-bit epoch-millis value is truncated to 32 bits before the division. The resulting seconds value is nonsensical: it lands around January 1970 and is negative for part of every ~49-day wrap cycle, instead of the intended creation time. The fix parenthesizes the division as(int) (currentTimeMillis / 1000).HMS overwrites
createTimeserver-side on create, so the persisted and observable symptom islastAccessTime, which HMS stores exactly as the client sends it. A garbagelastAccessTimeshows up inDESCRIBE FORMATTEDand can mislead staleness or retention tooling that readsTBLS.LAST_ACCESS_TIME.Tests
Added regression coverage that creates a table and a view through
HiveCatalogand asserts the HMSlastAccessTimereflects the current epoch second:TestHiveCatalog.newTableSetsCurrentHmsLastAccessTimeandTestHiveViewCatalog.newViewSetsCurrentHmsLastAccessTime. Both fail before the fix (the value lands near 1970) and pass after it.