-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Return Status for several utility datetime functions #8918
Conversation
This PR is based on some discussions here: #8812 (comment) |
✅ Deploy Preview for meta-velox canceled.
|
@rui-mo Please kindly review. Thanks! |
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.
Thanks!
daysSinceEpoch = daysSinceEpochFromDate(year, 1, 1); | ||
if (!daysSinceEpochFromDate(year, 1, 1, daysSinceEpoch).ok()) { | ||
return false; | ||
} |
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.
Maybe simplified with VELOX_RETURN_IF?
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.
Looks like it cannot. VELOX_RETURN_IF returns status code.
@@ -327,8 +335,7 @@ bool tryParseDateString( | |||
} | |||
} | |||
|
|||
daysSinceEpoch = daysSinceEpochFromDate(year, month, day); | |||
return true; | |||
return daysSinceEpochFromDate(year, month, day, daysSinceEpoch).ok(); |
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.
Do we need to check if daysSinceEpochFromDate
returns ok here?
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.
return daysSinceEpochFromDate(year, month, day, daysSinceEpoch).ok();
It will return true when status is ok, otherwise return false.
@mbasmanova Could you help to review? Thanks! |
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'm surprised there are not unit test changes. The APIs in TimestampConversion.h have changed, but there are not test changes. Are we missing test coverage for these APIs? If so, let's add it.
velox/type/TimestampConversion.cpp
Outdated
@@ -528,10 +535,21 @@ int32_t getMaxDayOfMonth(int32_t year, int32_t month) { | |||
} | |||
|
|||
int64_t daysSinceEpochFromDate(int32_t year, int32_t month, int32_t day) { | |||
int64_t daysSinceEpoch; | |||
auto status = daysSinceEpochFromDate(year, month, day, daysSinceEpoch); |
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.
@mbasmanova int64_t daysSinceEpochFromDate
is preserved here and the unit tests still use this API. Should I remove it?
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.
@marin-ma Is daysSinceEpochFromDate used only in unit tests? If so, then it is better to remove.
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.
@mbasmanova The previous one is also in use by non-test code. e.g. in sparksql function call:
velox/velox/functions/sparksql/DateTimeFunctions.h
Lines 315 to 334 in b11aeeb
template <typename T> | |
struct MakeDateFunction { | |
VELOX_DEFINE_FUNCTION_TYPES(T); | |
FOLLY_ALWAYS_INLINE void call( | |
out_type<Date>& result, | |
const int32_t year, | |
const int32_t month, | |
const int32_t day) { | |
auto daysSinceEpoch = util::daysSinceEpochFromDate(year, month, day); | |
VELOX_USER_CHECK_EQ( | |
daysSinceEpoch, | |
(int32_t)daysSinceEpoch, | |
"Integer overflow in make_date({}, {}, {})", | |
year, | |
month, | |
day); | |
result = daysSinceEpoch; | |
} | |
}; |
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.
@marin-ma I see. Looks like we have inconsistent APIs. Some provide 2 versions: one that returns Status and doesn't throw and another that throws. While other APIs provide only non-throwing version. Would it make sense to align all these APIs to provide only non-throwing behavior?
901ab9a
to
9d8e795
Compare
@mbasmanova The previous APIs that throws have been removed. Could you help to review again? Thanks! |
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.
@marin-ma Looks good to me. Thanks.
util::daysSinceEpochFromDate(year, month, day, daysSinceEpoch); | ||
EXPECT_TRUE(status.isUserError()); | ||
}; | ||
EXPECT_NO_THROW(testDaysSinceEpochFromDateInvalid(1970, 1, -1)); |
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.
Would it be possible to verify error message as well?
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.
Updated in the latest commit.
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mbasmanova There are internal linter and test failures. Could you provide the log? |
8cfa2d0
to
d844691
Compare
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mbasmanova merged this pull request in d54b76a. |
…or#8918) Summary: Modify utility functions `daysSinceEpochFromDate`, `daysSinceEpochFromDayOfYear` and `daysSinceEpochFromWeekDate` to return Status code. These functions are likely to be frequently used in sparksql functions. As such, they could achieve better performance without throwing exceptions. Pull Request resolved: facebookincubator#8918 Reviewed By: pedroerp Differential Revision: D54566326 Pulled By: mbasmanova fbshipit-source-id: d7d35a216deae01f7a5f07c96803deb0975689a1
Modify utility functions
daysSinceEpochFromDate
,daysSinceEpochFromDayOfYear
anddaysSinceEpochFromWeekDate
to return Status code. These functions are likely to be frequently used in sparksql functions. As such, they could achieve better performance without throwing exceptions.