Skip to content

feat: add support for datediff expression - #3145

Merged
andygrove merged 5 commits into
apache:mainfrom
andygrove:feature/date-diff
Jan 21, 2026
Merged

andygrove merged 5 commits into
apache:mainfrom
andygrove:feature/date-diff

Conversation

@andygrove

Copy link
Copy Markdown
Member

Summary

  • Adds native Comet support for Spark's datediff function
  • Returns the number of days between two dates: datediff(endDate, startDate) = endDate - startDate
  • Since Date32 stores days since epoch, implementation is a simple subtraction

Test Plan

  • Added unit tests in CometTemporalExpressionSuite
  • Tests cover: positive/negative differences, same dates, larger ranges, null handling
  • All existing tests pass

Note: This PR was generated with AI assistance.

Closes #3087

Adds native Comet support for Spark's datediff function, which returns
the number of days between two dates (endDate - startDate).

Closes apache#3087

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andygrove
andygrove marked this pull request as draft January 14, 2026 23:49
@codecov-commenter

codecov-commenter commented Jan 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.02%. Comparing base (f09f8af) to head (ff5a19e).
⚠️ Report is 859 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3145      +/-   ##
============================================
+ Coverage     56.12%   60.02%   +3.89%     
- Complexity      976     1429     +453     
============================================
  Files           119      170      +51     
  Lines         11743    15748    +4005     
  Branches       2251     2602     +351     
============================================
+ Hits           6591     9453    +2862     
- Misses         4012     4976     +964     
- Partials       1140     1319     +179     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

FuzzDataGenerator.generateDataFrame(r, spark, schema, 1000, DataGenOptions())
}

test("datediff") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tests using dates from leap years would be fun to try. Try this -

datediff( 1900-03-01, 1900-02-27) != datediff(2000-03-01, 2000-02-27)  

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good suggestion! I've added leap year edge case tests:

  • datediff('1900-03-01', '1900-02-27') = 2 days (1900 was NOT a leap year - divisible by 100 but not 400)
  • datediff('2000-03-01', '2000-02-27') = 3 days (2000 WAS a leap year - divisible by 400)
  • datediff('2004-03-01', '2004-02-28') = 2 days (2004 was a leap year - divisible by 4, not by 100)
  • datediff('2100-03-01', '2100-02-28') = 1 day (2100 will NOT be a leap year - divisible by 100 but not 400)

All tests pass.

@andygrove
andygrove marked this pull request as ready for review January 15, 2026 02:25
Add tests for leap year handling as suggested in review:
- 1900 was NOT a leap year (divisible by 100 but not 400)
- 2000 WAS a leap year (divisible by 400)
- 2004 was a leap year (divisible by 4, not by 100)
- 2100 will NOT be a leap year (divisible by 100 but not 400)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@parthchandra parthchandra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm. pending conflict resolution and ci.

@andygrove
andygrove merged commit 267ad4c into apache:main Jan 21, 2026
119 checks passed
@andygrove
andygrove deleted the feature/date-diff branch January 21, 2026 01:57
@andygrove

Copy link
Copy Markdown
Member Author

Thanks for the review @parthchandra

mixermt added a commit to mixermt/datafusion-comet that referenced this pull request Oct 11, 2026
Brings in origin/main up to 9e13649 and moves the iceberg-rust pin to the
current head of apache/iceberg-rust#3111 (0145ca6b), which still contains
main's pin (af1da4c5).

Main now loads the Iceberg scheme allow-lists from the native
builtin_storage_schemes over JNI, so hdfs is admitted there (read and write)
instead of in the two Scala sets.

The pin brings apache/iceberg-rust apache#3145, which makes FileScanTaskDeleteFile's
fields private behind a validating builder and its deletion-vector offsets
unsigned: the planner builds delete files through the builder (rejecting a
negative offset or size as iceberg-rust does for a manifest entry), and the
delete-file sizing rebuilds each delete through it.

The reworked HDFS backend validates every declared nameservice and a
forwarded fs.defaultFS when it builds the storage, failing all I/O otherwise.
Comet's gate now simulates its option expansion (hadoop.* keys win over the
hdfs.name-node.<ns> sugar key by key) and declines those cases at planning.
It also builds HDFS clients in a runtime of its own, so the AbortOnDrop
comment about runtime-bound operators is replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support Spark expression: date_diff

3 participants