-
Couldn't load subscription status.
- Fork 3.9k
GH-37118 [Java][arrow-jdbc] Support converting JDBC TIMESTAMP_WITH_TIMEZONE to Arrow #37088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
aiguofer
wants to merge
2
commits into
apache:main
Choose a base branch
from
aiguofer:fix_timestamp_jdbc_conversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there is still an underlying timezone, right? I guess we just don't know without writing database-specific code. It might be better to error in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this one is tough. As I understand it,
TIMESTAMP_WITH_TIMEZONEmeans that each record includes its own timezone as a UTC offset (or at least, that seems to be the case with Snowflake). Based on the JDBC spec,ResultSet.getTimestamp(int columnIndex, Calendar cal)does the followingThis method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does not store timezone information.. This leads me to believe that it parses out the offset from the underlying db and uses that to convert to UTC. If no offset is available, it assumes the timestamp is in w/e is passed in thecalendarand then converts it to UTC. Here's an interesting SO on the topic: https://stackoverflow.com/a/63078938/1815486From my understanding,
ArrowType.Timestampdoes not support per record timezones and it does not do any conversions on its own. It seems like the timezone is associated with the Vector itself and all records are expected to be in that same timezone. This means we must convertTIMESTAMP_WITH_TIMEZONEvalues into one specific TZ before we add them to the vector. It's also not exactly clear what it means when the TZ isnull(I'm assuming this means it's just a "wall clock" time).This all leaves some questions:
calendarsupposed to represent for these functions?There's some important connotations because it depends on whether one is using the arrow-jdbc library to convert values server side, where it's generally safe to use/assume UTC for a lot of things, or client side, where they might want to express values in the user's timezone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Arrow, the underlying representation for a timestamp with timezone is always UTC. So if the driver is giving us UTC and converting it, we should always bypass their conversion and construct a
timestamp[ms, UTC].And yes, if there's no timezone, then it's a wall-clock time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so Snowflake:
Postgres:
So the underlying value should be UTC. I think you'll have to look at what their JDBC driver specifically does, though: it might localize the value for you. I think you may need database-specific converters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm maybe we can change the consumer to do something smarter than
getTimestamp. This SO suggestsOffsetDateTime odt = myResultSet.getObject( … , OffsetDateTime.class ) ;.So for TZ aware timestamps we could use ^ and if no offset is available assume UTC. I think that would work for most things, but it'd get tricky for something like
TIMESTAMP_LTZ. I wonder how that even comes across through the JDBC driver? I imagine it's still of typeTIMESTAMP_WITH_TIMEZONEjust likeTIMESTAMP_TZ. We might want to add the value fromrsmd.getColumnTypeNameto theJdbcFieldInfoas well so users can disambiguate between the two if they need to write a custom converter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into the same issue: #35916
So agreed, we need more info than what JdbcFieldInfo has. (ADBC's Java adapter already has a workaround to add the extra fields.) And yeah, I think trying to get OffsetDateTime or similar would be better.
That's part of why I want to vendor this into the ADBC driver, iterate on it + test it against actual databases, and then maybe send the changes back...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool makes sense. I'll try to modify the consumer to do something smarter and correctly convert values into UTC.
I'll make a separate PR to add more data into
JdbcFieldInfo.WRT
I want to vendor this into the ADBC driver... and then maybe send the changes backyou mean redesign the JDBC to Arrow conversion within ADBC and eventually pull that back out into thearrow-jdbcpackage?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Though realistically, I don't have the time to do that right now so thank you for fixing up these things 😅