Skip to content

[Go SDK] Add portable logical type registration and standard date and micros_instant types - #40154

Open
Eliaaazzz wants to merge 2 commits into
apache:masterfrom
Eliaaazzz:go-logical-types-api
Open

Eliaaazzz wants to merge 2 commits into
apache:masterfrom
Eliaaazzz:go-logical-types-api

Conversation

@Eliaaazzz

@Eliaaazzz Eliaaazzz commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #39684.

The Go SDK could only support a portable logical type by registering it in three places (schema.RegisterLogicalType, coder.RegisterSchemaProviders, and the beam.SchemaProvider glue) with hand written encoders, and none of the standard logical types from schema.proto were registered. A schema from another SDK with a beam:logical_type:date:v1 or beam:logical_type:micros_instant:v1 field failed with unknown logical type.

Registration API, in package schema:

  • RegisterLogicalTypeConversion[GoT, StorageT](urn, toStorage, fromStorage) registers the URN, the Go type and the storage type, and builds the row coder for GoT from the row field coder of StorageT plus the two conversion functions.
  • RegisterParameterizedLogicalTypeConversion is the same for a logical type with an argument; each argument value gets its own Go type.
  • RegisterLogicalTypeCoder[GoT, StorageT](urn, enc, dec) is for logical types whose wire encoding differs from the row encoding of the storage type, such as millis_instant and decimal (following PRs).
  • coder.RowFieldEncoderForType and coder.RowFieldDecoderForType expose the row field encoding of a single type, which the registration builds on. Encoding an untyped nil value or a typed nil pointer returns an error. Pointer storage types are rejected at registration because the row coder decides nullability from the Go type of the field, and interface Go types are rejected because the row coder matches every implementation of an interface and the schema matches only the interface itself.

Standard types, registered by default:

  • schema.Date (beam:logical_type:date:v1), a calendar date stored as days since the epoch. Encoding requires a valid date with a year from -999999999 to 999999999.
  • schema.MicrosInstant (beam:logical_type:micros_instant:v1), a time.Time stored as a row of seconds and microseconds. Encoding a value with sub microsecond precision returns an error, as in the Java SDK. Decoding requires the micros field to be in [0, 999999].

The standard types are registered with runtime.RegisterType, so pipeline graphs with these types in a transform signature serialize. The row decoder also uses a provider registered for a value type when it decodes a top level pointer to that type, as the row encoder already does.

time.Time keeps its current Go specific encoding; the standard types are separate Go types, so existing pipelines are unaffected. Because the Go row coder is built from the Go type alone, each registered logical type needs its own Go type, and a parameterized one needs a Go type per argument value.

Regression test changes in sdks/go/test/regression/coders/fromyaml:

  • The expected row of a beam:coder:row:v1 case is built from the schema in the coder payload through schema.ToType, so logical type fields get their registered Go types. This replaces the name based type table.
  • Coder payloads are decoded from the yaml string the same way the examples are, so payload bytes above 0x7f (used by the timestamp:v1 cases) are read correctly.
  • Encoding mismatches now count as failures; before, they were only logged.
  • The micros_instant case runs. The remaining logical type cases are skipped by URN with a reason pointing at [Task]: Go SDK portable logical type support #39684.

Tests: schema conversion and byte level row encoding for Date and MicrosInstant (the bytes are the micros_instant example of standard_coders.yaml), date conversion at the epoch boundaries, the sub microsecond error, RegisterLogicalTypeConversion end to end with a user type, and RowFieldEncoderForType/RowFieldDecoderForType for atomic, slice and struct types. Tests also cover interface Go type rejection, the date and micros storage ranges, a nil pointer value, a top level pointer with a value provider, and graph serialization of the standard types.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label go.

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @jrmccluskey

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.82677% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.73%. Comparing base (76f6e6d) to head (2689ec7).
⚠️ Report is 139 commits behind head on master.

Files with missing lines Patch % Lines
sdks/go/pkg/beam/core/graph/coder/row_decoder.go 66.66% 4 Missing and 4 partials ⚠️
...kg/beam/core/runtime/graphx/schema/logicaltypes.go 87.75% 3 Missing and 3 partials ⚠️
sdks/go/pkg/beam/core/graph/coder/row_encoder.go 69.23% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40154       +/-   ##
=============================================
- Coverage     56.16%   28.73%   -27.44%     
=============================================
  Files          1124      381      -743     
  Lines        178336    71101   -107235     
  Branches       1489        0     -1489     
=============================================
- Hits         100170    20432    -79738     
+ Misses        75645    48819    -26826     
+ Partials       2521     1850      -671     
Flag Coverage Δ
go 28.73% <85.82%> (-0.40%) ⬇️
java ?
python ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jrmccluskey

Copy link
Copy Markdown
Contributor

Hey there! I'm starting a review pass, if you would go ahead and rebase this PR now that the two diffbase PRs are merged that would make this a little bit smoother as far as reviewing and merging. Thanks!

… micros_instant types

schema.RegisterLogicalTypeConversion registers a logical type identified
by a URN together with the conversions between its Go type and its
storage type, and derives the row coder from the storage type.
schema.RegisterLogicalTypeCoder does the same for logical types whose
wire encoding differs from the row encoding of the storage type. The
standard beam:logical_type:date:v1 and beam:logical_type:micros_instant:v1
logical types are registered by default as schema.Date and
schema.MicrosInstant.

The standard coder regression test now builds the expected row from the
schema in the coder payload, decodes payload bytes above 0x7f, counts
encoding mismatches as failures, and runs the micros_instant case.

Part of apache#39684.
@Eliaaazzz
Eliaaazzz force-pushed the go-logical-types-api branch from db75cf6 to 2689ec7 Compare October 12, 2026 23:18
@Eliaaazzz

Eliaaazzz commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks a lot for reviewing this series, Jack, and for merging #40152 and #40153! I rebased this one onto master, so the diff now only shows its own changes.

I also pushed a small commit that swaps reflect.PtrTo for reflect.PointerTo in row_test.go, since Yi pointed out on #40153 that PtrTo is deprecated.

Happy to adjust anything you spot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants