Skip to content

Make DateTime a portable logical type with a precision - #41550

Open
ahmedabu98 wants to merge 2 commits into
apache:masterfrom
ahmedabu98:datetime-logicaltype
Open

ahmedabu98 wants to merge 2 commits into
apache:masterfrom
ahmedabu98:datetime-logicaltype

Conversation

@ahmedabu98

@ahmedabu98 ahmedabu98 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Makes beam:logical_type:datetime:v1 a standard portable logical type with a precision (0 to 9, default 6). In Java, SqlTypes.DATETIME becomes DateTime(6), so a LocalDateTime with sub-microsecond digits now throws (DateTime.NANOS keeps them). Python gets a matching apache_beam.utils.timestamp.DateTime.

The Python DateTime has no arithmetic for now. To compute with it, convert it to datetime.datetime with to_datetime() or to Arrow with to_arrow().

This takes a similar approach to logical Timestamp (#36705, #39537). Design: https://s.apache.org/beam-timestamp-strategy

Java's DateTime now takes a precision (0 to 9, default 6) and is the
standard beam:logical_type:datetime:v1 type, so SqlTypes.DATETIME is
DateTime(6). Python gets a matching apache_beam.utils.timestamp.DateTime
that converts to and from datetime.datetime and Arrow timestamps.

@github-actions github-actions Bot 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.

📋 Review Summary

This PR promotes beam:logical_type:datetime:v1 to a standard portable logical type parameterized by subsecond precision (0–9, defaulting to 6) across the model proto, Java SDK, and Python SDK. The implementation is clean, well-structured, and thoroughly tested—including backward-compatibility handling for Java-serialized DateTime instances, legacy empty-string proto arguments, standard coder YAML test cases, and conversions between Python DateTime, datetime.datetime/pandas.Timestamp, and pyarrow.TimestampScalar.

🔍 General Feedback

  • The precision validation, lossless/lossy conversion semantics, and representation invariants (ROW<Date: INT64, Time: INT64> with Time in nanoseconds) are consistent between Java and Python.
  • Backward compatibility with older SDK encodings (both Java object serialization via readResolve and legacy proto STRING "" arguments in Python) is well covered by unit tests.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.31034% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.41%. Comparing base (6b9bec4) to head (ace8989).
⚠️ Report is 162 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/utils/timestamp.py 99.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41550      +/-   ##
============================================
+ Coverage     59.38%   59.41%   +0.03%     
  Complexity     5133     5133              
============================================
  Files          1469     1469              
  Lines        187488   187668     +180     
  Branches       3816     3816              
============================================
+ Hits         111342   111507     +165     
- Misses        72741    72756      +15     
  Partials       3405     3405              
Flag Coverage Δ
python 80.65% <99.31%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @tvalentyn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant