Support overflow in Timestamp::toTimeZone method#10641
Support overflow in Timestamp::toTimeZone method#10641JkSelf wants to merge 1 commit intofacebookincubator:mainfrom
Conversation
✅ Deploy Preview for meta-velox canceled.
|
|
@pedroerp @rui-mo @jinchengchenghh Can you help to review? Thanks. |
| // 8 hours ahead UTC. | ||
| setQueryTimeZone("Asia/Shanghai"); | ||
|
|
||
| #ifdef NDEBUG |
There was a problem hiding this comment.
The max value of seconds allowed in Spark is INT64_MAX/1'000'000, so this limitation could be removed if we avoid creating invalid timestamp from the unix_timestamp function, seeing #9904. To use INT64_MAX/1'000'000 as seconds, below overflow should also be reproducible.
Timepoint is outside of supported year range: [-32767, 32767]
There was a problem hiding this comment.
+1. It would be great if there was a way to ensure this from the Spark functions themselves, since the Timestamp class is shared with Presto and others.
pedroerp
left a comment
There was a problem hiding this comment.
Sorry about changing the behavior here. Asked a few questions in the PR
| void Timestamp::toTimezone(const tz::TimeZone& zone, bool allowOverflow) { | ||
| try { | ||
| seconds_ = zone.to_local(std::chrono::seconds(seconds_)).count(); | ||
| auto tp = toTimePointMs(allowOverflow); |
There was a problem hiding this comment.
why do we need to create a time point here just to discard it later? The same validateRange() method will be called inside to_local()
| // 8 hours ahead UTC. | ||
| setQueryTimeZone("Asia/Shanghai"); | ||
|
|
||
| #ifdef NDEBUG |
There was a problem hiding this comment.
+1. It would be great if there was a way to ensure this from the Spark functions themselves, since the Timestamp class is shared with Presto and others.
| // 8 hours ahead UTC. | ||
| setQueryTimeZone("Asia/Shanghai"); | ||
|
|
||
| #ifdef NDEBUG |
There was a problem hiding this comment.
Also, it's sort of weird that we only let it overflow in release code and add a test to ensure it. The lack of test in release wasn't intentional, but due to performance to prevent the checking overhead. How could we make this more general?
|
This pull request has been automatically marked as stale because it has not had recent activity. If you'd still like this PR merged, please comment on the PR, make sure you've addressed reviewer comments, and rebase on the latest main. Thank you for your contributions! |
After merging the PR#10563, we encountered an error during the unit tests in Gluten.
The reason is that this PR#10563 removed the handling for overflow. We have added handling for overflow in the toTimeZone method in this PR.