[FLINK-40491][core] Extend BinaryVariant with TIME, TIMESTAMP_NS, TIMESTAMP_LTZ_NS primitives - #29050
Open
manner wants to merge 4 commits into
Open
[FLINK-40491][core] Extend BinaryVariant with TIME, TIMESTAMP_NS, TIMESTAMP_LTZ_NS primitives#29050manner wants to merge 4 commits into
manner wants to merge 4 commits into
Conversation
…ESTAMP_LTZ_NS primitives
raminqaf
reviewed
Aug 31, 2026
snuyanzin
reviewed
Aug 31, 2026
| case DATE: | ||
| return readLong(value, pos + 1, 4); | ||
| case INT8: | ||
| case TIME: |
Contributor
There was a problem hiding this comment.
is it TIME with micro/nanos or not?
snuyanzin
reviewed
Aug 31, 2026
Comment on lines
+451
to
+452
| case TIMESTAMP_LTZ_NS: | ||
| case TIMESTAMP_NS: |
Contributor
There was a problem hiding this comment.
why do we think 8 bytes is enough here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
The variant binary encoding spec (see Variant Encoding) defines primitive type codes 17-20 for
TIME,TIMESTAMP_LTZ_NS,TIMESTAMP_NS, andUUIDthat are currently missing in Flink.This PR adds support for codes 17-19 (
TIME,TIMESTAMP_LTZ_NS,TIMESTAMP_NS) toBinaryVariant, so that aLocalTimeand a nanosecond-precisionInstant/LocalDateTimecan be represented in aVariantwithout lossy truncation to microseconds.UUID(code 20) is intentionally out of scope here and will be added in a separate ticket.Brief change log
BinaryVariantUtilconstants for primitive codes 17-19, extendedgetType()/valueSize()/getLong()to handle them, and added aTIME_FORMATTERfor JSON renderingVariant.Type.TIME/TIMESTAMP_NS/TIMESTAMP_LTZ_NSand the correspondinggetTime()/getDateTimeNanos()/getInstantNanos()accessors to theVariantinterfaceVariantBuilder.of(LocalTime); madeof(Instant)/of(LocalDateTime)precision-aware so a value with no sub-microsecond component keeps using the existing compact micros encoding, and only switches to the new nanosecond encoding when the value actually needs itappendTime/appendTimestampNanos/appendTimestampLtzNanosinBinaryVariantInternalBuilder, and the matching read/get()/toJson()support inBinaryVariantVerifying this change
This change added tests and can be verified as follows:
get()dispatch tests for the new types (BinaryVariantTest#testScalarVariant)Instant/LocalDateTimepick the existingTIMESTAMP_LTZ/TIMESTAMPencoding for microsecond-aligned values and the newTIMESTAMP_LTZ_NS/TIMESTAMP_NSencoding otherwise, including that the mismatched accessor throwsVariantTypeException(BinaryVariantTest#testNanosecondPrecisionVariant)LocalTimesilently truncates below microsecond precision, sinceTIMEhas no nanosecond-precision counterpart in the variant spec (BinaryVariantTest#testTimeSubMicrosecondTruncation)TIME/TIMESTAMP_NS/TIMESTAMP_LTZ_NS(BinaryVariantTest#testToJsonScalar)Does this pull request potentially affect one of the following parts:
@Public(Evolving): yes (VariantandVariantBuilderare@PublicEvolving; this adds new enum constants and new interface methods)Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Sonnet 5 (Claude Code)