-
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
feat: Add support for Timestamp to Integral for Spark #12369
base: main
Are you sure you want to change the base?
feat: Add support for Timestamp to Integral for Spark #12369
Conversation
✅ Deploy Preview for meta-velox canceled.
|
cc @rui-mo could you please take a look |
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, please also update the document velox/docs/functions/spark/conversion.rst
@@ -50,6 +50,21 @@ Expected<Timestamp> SparkCastHooks::castIntToTimestamp(int64_t seconds) const { | |||
return Timestamp(seconds, 0); | |||
} | |||
|
|||
Expected<int64_t> SparkCastHooks::castTimestampToInt(Timestamp timestamp) const { | |||
static constexpr int64_t MICROS_PER_SECOND = 1'000'000; |
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.
Please add kMicroSecondsInSeconds like kNanosInSecond
@@ -286,6 +286,14 @@ void CastExpr::applyCastKernel( | |||
return; | |||
} | |||
|
|||
if constexpr ( | |||
(FromKind == TypeKind::TIMESTAMP) && ToKind == TypeKind::BIGINT) { |
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.
What if to kind is int?
@@ -50,6 +50,21 @@ Expected<Timestamp> SparkCastHooks::castIntToTimestamp(int64_t seconds) const { | |||
return Timestamp(seconds, 0); | |||
} | |||
|
|||
Expected<int64_t> SparkCastHooks::castTimestampToInt(Timestamp timestamp) const { | |||
static constexpr int64_t MICROS_PER_SECOND = 1'000'000; | |||
int64_t micros = timestamp.toMicros(); |
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.
auto micros
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! Would you please paste the link of Spark's implementation in the PR description?
@@ -97,6 +97,11 @@ Expected<int32_t> PrestoCastHooks::castStringToDate( | |||
return util::fromDateString(dateString, util::ParseMode::kPrestoCast); | |||
} | |||
|
|||
Expected<int64_t> PrestoCastHooks::castTimestampToInt(Timestamp timestamp) const { | |||
return folly::makeUnexpected( |
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.
Have we verified in Presto that this conversion is indeed unsupported?
@@ -32,6 +32,9 @@ class PrestoCastHooks : public CastHooks { | |||
|
|||
Expected<Timestamp> castIntToTimestamp(int64_t seconds) const override; | |||
|
|||
// Cast timestamp to integer. | |||
Expected<int64_t> castTimestampToInt(Timestamp timestamp) const override; |
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.
It appears that we are converting timestamp as big int not integer. Perhaps use consistent function name, and avoid repeating the name in comment.
Timestamp(-1, 1), | ||
Timestamp(1234567, 500000), | ||
Timestamp(-9876543, 1234), | ||
std::nullopt, |
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.
Perhaps remove the null test as it tests the framework not the function itself.
Duplicated with #11468 |
What changes were proposed in this pull request?
How was this patch tested?