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

Add Spark CAST(double/float as timestamp) #12041

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boneanxs
Copy link
Contributor

@boneanxs boneanxs commented Jan 9, 2025

Add Spark CAST (double/float as timestamp). The input value is treated as the
number of seconds since the epoch (1970-01-01 00:00:00 UTC).

Spark's implementation: https://github.com/apache/spark/blob/fd86f85e181fc2dc0f50a096855acf83a6cc5d9c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala#L675

@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 Jan 9, 2025
Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit b7068cf
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/677f3d6b74f62b00082aa673

@boneanxs
Copy link
Contributor Author

Hey @rui-mo @jinchengchenghh , can help review this? Thanks!

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.

ToKind == TypeKind::TIMESTAMP) {
const auto castResult =
hooks_->castDoubleToTimestamp(static_cast<double>(inputRowValue));
if (castResult.hasError()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use 'setResultOrError'?

Status::Invalid("Can not convert NaN or Infinity to timestamp"));
}
return Timestamp::fromMicrosNoError(
static_cast<int64_t>(value * Timestamp::kMicrosecondsInSecond));
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is overflow handled? It looks different with the impl. of 'castIntToTimestamp'.

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.

3 participants