Skip to content

Extract common class for WithTimestamps.AddTimestampsDoFn and Create.TimestampedValues.ConvertTimestamps #18350

Closed

Description

@kennknowles

It seems like these APIs are predominantly duplicative of each other and, that it's hard to find one of them if you knew about the other.

public void processElement(ProcessContext c) {

c.outputWithTimestamp(c.element().getValue(), c.element().getTimestamp());

What would make the most sense to me is if TimestampedValues were implemented in terms of both Values and WithTimestamps. I'm still learning about Beam though -- would this approach cause some kind of performance problem?

Imported from Jira BEAM-1811. Original Jira may contain additional context.
Reported by: wtanaka.

Activity

  1. Gaurav598 commented on Sep 1, 2026

    @Gaurav598
    Contributor

    I investigated the current implementation of this issue and wanted to leave a few findings here that may be useful to whoever picks it up next.

    The duplication between WithTimestamps.AddTimestampsDoFn and Create.TimestampedValues.ConvertTimestamps is still present: both ultimately use outputWithTimestamp(...).

    However, a direct Create.Values + WithTimestamps implementation does not appear to be a straightforward replacement. The timestamp is part of each TimestampedValue<T> and is not necessarily derivable from T, so duplicate/equal values can have different timestamps.

    I also found that Create.TimestampedValues was previously related to Create.Values through inheritance, but that was intentionally removed because it caused runner matching issues. Reintroducing that relationship would therefore be risky.

    The current TimestampedValues implementation also deliberately:

    • infers the coder from the underlying T values,
    • uses TimestampedValueCoder for the intermediate collection,
    • unwraps the timestamped values through ConvertTimestamps,
    • and explicitly restores the final Coder<T>.

    Because of this, a conservative internal abstraction for the common timestamp-output behavior seems safer than restructuring TimestampedValues around Values + WithTimestamps. This would allow the existing execution path, coder behavior, and transform structure to remain unchanged.

    The relevant tests also include renderer and Dataflow runner expectations around the current Create.TimestampedValues/ConvertTimestamps structure, so those are worth considering before changing the pipeline graph.
    Hopefully these findings save some investigation time for the next contributor.

  2. xujiantop-crypto commented on Sep 9, 2026

    @xujiantop-crypto
    Contributor

    .take-issue

  3. kennknowles commented on Sep 9, 2026

    @kennknowles
    MemberAuthor

    TBH I don't think this is a good idea. This creates an inheritance-based coupling when just having this trivial code in two places is more flexible and keeps control flow simpler.

  4. added this to the 2.77.0 Release milestone on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions