Convert All Usage of LocalDateTime to Instant#456
Merged
Conversation
parthban-db
reviewed
Jun 4, 2025
parthban-db
reviewed
Jun 4, 2025
renaudhartert-db
approved these changes
Jun 4, 2025
renaudhartert-db
left a comment
Contributor
There was a problem hiding this comment.
LGTM modulo resolution of the fallback discussion.
parthban-db
approved these changes
Jun 5, 2025
Contributor
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
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.
What changes are proposed in this pull request?
This pull request refactors the Databricks Java SDK to replace all usages of LocalDateTime with Instant for representing date-time values. The primary motivation is to ensure that all date-time handling is unambiguous, always in UTC, and consistent across the SDK.
How does time currently operate in the SDK?
Currently, tokens in the SDK use LocalDateTime for expiry timestamps, which by itself is timezone-agnostic and could be ambiguous. Thus, it is not clear how time is handled from the type alone and we need to look at the implementation details of the ClockSupplier used.
The SDK currently uses system time through the
SystemClockSupplierclass as defined here. This implementation of the ClockSupplier interface returnsClock.systemDefaultZone(), meaning it uses the actual system time from the operating system. TheSystemClockSupplieris the used throughout the SDK to conduct OAuth token expiration checks as seen here in theisExpired()method of the Token class. WhileLocalDateTimedoesn't explicitly store timezone information, the system's timezone is being implicitly used for these comparisons throughClock.systemDefaultZone(). In other words, token expiry times are implicitly measured in the system's timezone.Converting to UTC
To convert these expiry times to UTC while maintaining the SDK's current behavior, we need to handle two distinct scenarios:
1. Tokens with
expires_inAdd the
expires_invalue to the current UTC time.This approach maintains the original expiration behavior while using UTC internally.
2. Tokens with
expires_on(e.g., Azure CLI, Databricks CLI)With Time Zone Indicator
These can be easily converted to UTC using standard library methods.
Without Time Zone Indicator
expiresOnfield from Azure CLIReference
We do this with
LocalDateTime.atZone(systemDefault).toInstant()How is this tested?
Future Work
expiresOn: Local datetime without timezone (maintained for backward compatibility)expires_on: POSIX timestamp (seconds since epoch) - preferred formatCurrent Implementation
expiresOnfieldLocalDateTimecreates timezone interpretation challengesTo Do
expiresOnThis legacy field should be deprecated in favor of
expires_onFuture PRs should prioritize using
expires_on(POSIX timestamp) which:NO_CHANGELOG=true