Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ArnavBalyan
Copy link

@ArnavBalyan ArnavBalyan commented Feb 18, 2025

What changes were proposed in this pull request?

  • Add support for timestamp to integral cast for Spark.
  • Replicates the same behaviour as Spark cast for timestamp to int.

How was this patch tested?

  • Unit tests

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 18, 2025
Copy link

netlify bot commented Feb 18, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 97f7afa
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/67b46b0105667c00083fe7e0

@ArnavBalyan
Copy link
Author

cc @rui-mo could you please take a look

Copy link
Contributor

@jinchengchenghh jinchengchenghh left a 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;
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto micros

Copy link
Collaborator

@rui-mo rui-mo left a 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(
Copy link
Collaborator

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;
Copy link
Collaborator

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,
Copy link
Collaborator

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.

@jinchengchenghh
Copy link
Contributor

Duplicated with #11468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants