[
https://issues.apache.org/jira/browse/FLINK-40792?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated FLINK-40792:
-----------------------------------
Labels: pull-request-available (was: )
> Emit "Z" instead of "+00:00" for UTC in Variant.toJson()
> --------------------------------------------------------
>
> Key: FLINK-40792
> URL: https://issues.apache.org/jira/browse/FLINK-40792
> Project: Flink
> Issue Type: Improvement
> Components: API / Core
> Reporter: Ramin Gharib
> Assignee: Ramin Gharib
> Priority: Minor
> Labels: pull-request-available
>
> Variant.toJson() renders TIMESTAMP_LTZ and TIMESTAMP_LTZ_NS values as an ISO
> 8601 timestamp with a numeric UTC offset. For a value at UTC, the offset is
> printed as +00:00.
> Current output:
> {code}
> "1970-01-01T00:00:00+00:00"
> "1970-01-01T00:00:00.123456789+00:00"
> {code}
> The formatter lives in
> [BinaryVariantUtil|https://github.com/apache/flink/blob/b25e303d5353e9e1a252712e746eb1b372df5729/flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java#L235-L239]:
> {code:java}
> public static final DateTimeFormatter TIMESTAMP_LTZ_FORMATTER =
> new DateTimeFormatterBuilder()
> .append(TIMESTAMP_FORMATTER)
> .appendOffset("+HH:MM", "+00:00")
> .toFormatter(Locale.US);
> {code}
> h3. Proposed change
> Emit \{{Z}} for the zero offset instead. The change is one line, setting the
> "no offset" text to \{{Z}}:
> {code:java}
> .appendOffset("+HH:MM", "Z")
> {code}
> Proposed output:
> {code}
> "1970-01-01T00:00:00Z"
> "1970-01-01T00:00:00.123456789Z"
> {code}
> Only the zero offset changes, from \{{+00:00}} to \{{Z}}.
> h3. Why
> It is the canonical form for UTC. RFC 3339 and ISO 8601 both define \{{Z}} as
> the marker for UTC. It is the form most readers expect for a "Zulu time"
> timestamp.
> It matches standard tooling. \{{Instant.toString()}},
> \{{DateTimeFormatter.ISO_OFFSET_DATE_TIME}}, Jackson, and most JSON libraries
> emit \{{Z}} for UTC. Consumers parsing our output with a standard library
> round-trip more cleanly.
> It is more compact. \{{Z}} is one character versus six.
> The blast radius is small right now. VARIANT is new in Flink 2.x. Aligning
> the format before it is widely depended on is cheaper than changing it later.
> h3. Compatibility
> This is a behavior change to a public string output. Anyone doing string
> equality on \{{toJson()}} for a UTC \{{TIMESTAMP_LTZ}} value will see a diff.
> Should be documented as a behavior change with a release note.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)