Skip to content

fix(avro): decode nullable logical timestamps - #935

Merged
zeroshade merged 3 commits into
apache:mainfrom
abir-eon:fix-avro-nullable-logical-timestamps
Jul 15, 2026
Merged

zeroshade merged 3 commits into
apache:mainfrom
abir-eon:fix-avro-nullable-logical-timestamps

Conversation

@abir-eon

@abir-eon abir-eon commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

This is a follow-up to #832, which added support for Avro local timestamp logical types.

For nullable timestamp fields, Hamba decodes a selected logical union branch as a one-entry map such as "long.local-timestamp-micros": time.Time. appendTimestampData only inspected the plain "long" branch, so it treated valid non-null logical timestamp values as null.

What changes are included in this PR?

  • Recognize Hamba's exact union branch names for timestamp-millis, timestamp-micros, local-timestamp-millis, and local-timestamp-micros, while preserving plain long unions.
  • Route decoded time.Time union values through the existing timestamp conversion, including UTC wall-clock reinterpretation for local timestamps.
  • Add end-to-end nullable OCF coverage for all four timestamp logical types, with one non-null and one null record per type, plus focused appender coverage.

Are these changes tested?

Yes. The regression failed before the fix because non-null logical timestamp values were appended as null. The full Avro suite passes in UTC and a non-UTC timezone:

  • TZ=UTC go test ./arrow/avro/... -count=1
  • TZ=Asia/Jerusalem go test ./arrow/avro/... -count=1
  • golangci-lint v2.11.3 run --timeout=5m ./arrow/avro/...

Are there any user-facing changes?

Yes. Non-null values in nullable Avro timestamp logical fields are now decoded as Arrow timestamps instead of null.

@abir-eon
abir-eon marked this pull request as ready for review July 13, 2026 20:28
@abir-eon
abir-eon requested a review from zeroshade as a code owner July 13, 2026 20:28

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks correct, and the union-branch handling preserves UTC vs. local timestamp semantics nicely. Just an optional test-coverage suggestion, non-blocking.

Comment thread arrow/avro/reader_test.go Outdated
assert.True(t, nullable.IsNull(1))
}

func TestOCFReaderNullableLocalTimestampMicros(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this end-to-end OCF test only exercises local-timestamp-micros. TestAppendTimestampDataUnionBranches covers all four branch names at the appender level, but OCF-level coverage for nullable global timestamp-millis/timestamp-micros and local-timestamp-millis would also catch any integration mismatch in Hamba's branch naming/decoding for those flavors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c70bea6. TestOCFReaderNullableTimestamps now exercises timestamp-millis, timestamp-micros, local-timestamp-millis, and local-timestamp-micros end to end through OCF, with one non-null and one null record per type. Verified under TZ=UTC and TZ=Asia/Jerusalem. Thanks!

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified the fix and its test coverage. Thanks!

@zeroshade
zeroshade merged commit bc67578 into apache:main Jul 15, 2026
prochac added a commit to prochac/arrow-go that referenced this pull request Jul 29, 2026
Port TestOCFReaderNullableTimestamps from upstream apache#935, which the
hamba->twmb migration displaced. Extends it with the nanos variants and
pins time.Local to a non-UTC zone so a machine's TZ cannot shift the
decoded value.

The OCF writer is given the raw schema JSON via ocf.WithSchema: twmb
defaults the header to the parsing canonical form, which by spec strips
logical types and would make the fixture meaningless.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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