You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "coderfender (via GitHub)" <gi...@apache.org> on 2026/02/03 23:25:32 UTC
[PR] feat: support_cast_date_timestamp [datafusion-comet]
coderfender opened a new pull request, #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383
## Which issue does this PR close?
Adds cast support from date to timestamp (UTC)
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support_cast_date_timestamp [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#discussion_r2764250855
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1118,6 +1119,50 @@ fn cast_array(
Ok(spark_cast_postprocess(cast_result?, from_type, to_type))
}
+fn cast_date_to_timestamp(
+ array_ref: &ArrayRef,
+ cast_options: &SparkCastOptions,
+ target_tz: &Option<Arc<str>>,
+) -> SparkResult<ArrayRef> {
+ let tz_str = if cast_options.timezone.is_empty() {
+ "UTC"
+ } else {
+ cast_options.timezone.as_str()
+ };
+ // safe to unwrap since we are falling back to UTC above
+ let tz = timezone::Tz::from_str(tz_str)?;
+ let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
+ let date_array = array_ref.as_primitive::<Date32Type>();
+
+ let mut builder = TimestampMicrosecondBuilder::with_capacity(date_array.len());
+
+ for date in date_array.iter() {
+ match date {
+ Some(date) => {
+ // safe to unwrap since chrono's range ( 262,143 yrs) is higher than
+ // number of years possible with days as i32 (~ 6 mil yrs)
+ // convert date in session timezone to timestamp in UTC
+ let naive_date = epoch + chrono::Duration::days(date as i64);
Review Comment:
Could you add some Rust tests that cover this logic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support_cast_date_timestamp [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#discussion_r2764245105
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -989,8 +989,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
castTest(generateDates(), DataTypes.StringType)
}
- ignore("cast DateType to TimestampType") {
- // Arrow error: Cast error: Casting from Date32 to Timestamp(Microsecond, Some("UTC")) not supported
+ test("cast DateType to TimestampType") {
castTest(generateDates(), DataTypes.TimestampType)
Review Comment:
`generateDates` only returns 3 values, so we don't have good test coverage here. Could you add some tests specifically for DST transition dates, like dates around 2023-03-12 or 2023-11-05 for US timezones, with different session timezones configured. This would help verify the timezone conversion logic matches Spark's behavior for those edge cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support_cast_date_timestamp [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#issuecomment-3844681515
I believe I can piggy back Date -> numeric types (which always return null) in thr PR or perhaps in a different PR if you think that is a good idea ? (Date -> Int is more a formality than adding additional logic)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support_cast_date_timestamp [datafusion-comet]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#issuecomment-3844509484
## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/3383?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `5 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 16.46%. Comparing base ([`f09f8af`](https://app.codecov.io/gh/apache/datafusion-comet/commit/f09f8af64c6599255e116a376f4f008f2fd63b43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4c6eb3a`](https://app.codecov.io/gh/apache/datafusion-comet/commit/4c6eb3ae0e1e44c94fc1afdcc99359c016598c4c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 923 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion-comet/pull/3383?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...scala/org/apache/comet/expressions/CometCast.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/3383?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fcomet%2Fexpressions%2FCometCast.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9jb21ldC9leHByZXNzaW9ucy9Db21ldENhc3Quc2NhbGE=) | 0.00% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/3383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #3383 +/- ##
=============================================
- Coverage 56.12% 16.46% -39.66%
+ Complexity 976 401 -575
=============================================
Files 119 175 +56
Lines 11743 16170 +4427
Branches 2251 2662 +411
=============================================
- Hits 6591 2663 -3928
- Misses 4012 13098 +9086
+ Partials 1140 409 -731
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/3383?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Support date to timestamp cast [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on code in PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#discussion_r2767651072
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -989,8 +989,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
castTest(generateDates(), DataTypes.StringType)
}
- ignore("cast DateType to TimestampType") {
- // Arrow error: Cast error: Casting from Date32 to Timestamp(Microsecond, Some("UTC")) not supported
+ test("cast DateType to TimestampType") {
castTest(generateDates(), DataTypes.TimestampType)
Review Comment:
Thank you @andygrove . I added set of dates covering almost all DST start and end dates for various timezones across US, EU, Asia and Australia. I also added some sample dates for future along with regular dates starting from epoch to make sure we have wide coverage
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Support date to timestamp cast [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: support_cast_date_timestamp [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#issuecomment-3844678900
@parthchandra , @andygrove . Please take a look whenever you get a chance .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Support date to timestamp cast [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on code in PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#discussion_r2767653829
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1118,6 +1119,50 @@ fn cast_array(
Ok(spark_cast_postprocess(cast_result?, from_type, to_type))
}
+fn cast_date_to_timestamp(
+ array_ref: &ArrayRef,
+ cast_options: &SparkCastOptions,
+ target_tz: &Option<Arc<str>>,
+) -> SparkResult<ArrayRef> {
+ let tz_str = if cast_options.timezone.is_empty() {
+ "UTC"
+ } else {
+ cast_options.timezone.as_str()
+ };
+ // safe to unwrap since we are falling back to UTC above
+ let tz = timezone::Tz::from_str(tz_str)?;
+ let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
+ let date_array = array_ref.as_primitive::<Date32Type>();
+
+ let mut builder = TimestampMicrosecondBuilder::with_capacity(date_array.len());
+
+ for date in date_array.iter() {
+ match date {
+ Some(date) => {
+ // safe to unwrap since chrono's range ( 262,143 yrs) is higher than
+ // number of years possible with days as i32 (~ 6 mil yrs)
+ // convert date in session timezone to timestamp in UTC
+ let naive_date = epoch + chrono::Duration::days(date as i64);
Review Comment:
Thank you . I added set of tests to verify expected output in various timezones following and not following DST
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat: Support date to timestamp cast [datafusion-comet]
Posted by "coderfender (via GitHub)" <gi...@apache.org>.
coderfender commented on PR #3383:
URL: https://github.com/apache/datafusion-comet/pull/3383#issuecomment-3854773511
Thank you for the quick approval @andygrove .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org