Skip to content

feat(avro): support local-timestamp logical types - #832

Merged
zeroshade merged 1 commit into
apache:mainfrom
abir-eon:avro-local-timestamp
Jun 8, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
abir-eon:avro-local-timestamp

Conversation

@abir-eon

@abir-eon abir-eon commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

arrow/avro/schema.go had the Avro local-timestamp-millis and local-timestamp-micros logical types commented out with a note that they were "not implemented in hamba/avro". As of the github.com/hamba/avro/v2 version this module depends on, both types are fully supported (defined as logical types, parsed, and encoded/decoded to time.Time), so the note is stale and the types can now be mapped.

What changes are included in this PR

  • Map local-timestamp-millis / local-timestamp-micros to a zone-less arrow.TimestampType (Millisecond / Microsecond unit, empty TimeZone), reflecting their wall-clock semantics — as opposed to the global timestamp-millis / timestamp-micros types which map to UTC-zoned types.
  • Fix value conversion in reader_types.go: hamba decodes a local-timestamp into a time.Time whose wall-clock fields are correct but whose location is the reader's machine zone. Because arrow.TimestampFromTime derives the stored value from the instant (Unix()), the machine's zone offset would otherwise leak into the stored value. The wall-clock fields are reinterpreted in UTC before conversion so the stored value is zone-independent.
  • Extend the all-types schema and roundtrip tests (schema_test.go, reader_test.go, testdata/) to cover both new types. The roundtrip test was verified to fail without the conversion fix under a non-UTC timezone (e.g. TZ=Asia/Kolkata) and pass with it.

Are these changes tested?

Yes — go test ./arrow/avro/... passes, including under non-UTC timezones.

Are there any user-facing changes?

Yes. Avro schemas using local-timestamp-millis / local-timestamp-micros were previously unsupported; they now convert to zone-less arrow.TimestampType columns.

Map the Avro local-timestamp-millis and local-timestamp-micros logical
types to zone-less arrow.TimestampType values. These are now supported by
hamba/avro, so the prior "not implemented in hamba/avro" note was stale.

local-timestamp carries wall-clock (zone-less) semantics, distinct from
the global timestamp-millis/micros types which map to a UTC-zoned
arrow.TimestampType. hamba decodes a local-timestamp into a time.Time whose
wall-clock fields are correct but whose location is the reader's machine
zone; arrow.TimestampFromTime derives the stored value from the instant, so
the machine offset would leak in. Reinterpret the wall-clock fields in UTC
before conversion to keep the stored value zone-independent.

Extend the all-types roundtrip and schema tests to cover both new types.
@abir-eon
abir-eon requested a review from zeroshade as a code owner June 1, 2026 06:04
@zeroshade

Copy link
Copy Markdown
Member

LGTM! Thanks for this, I'll merge once the CI completes if all is green

@zeroshade
zeroshade merged commit dd96f38 into apache:main Jun 8, 2026
40 of 41 checks passed
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.

2 participants