Skip to content

[Go SDK] Encode INT16 row fields as big endian to match Java and Python - #40152

Open
Eliaaazzz wants to merge 1 commit into
apache:masterfrom
Eliaaazzz:go-row-int16-bigendian
Open

Eliaaazzz wants to merge 1 commit into
apache:masterfrom
Eliaaazzz:go-row-int16-bigendian

Conversation

@Eliaaazzz

Copy link
Copy Markdown
Contributor

Fixes #40151. Part of #39684.

The reflection based row coder encoded int16 and uint16 struct fields with the varint encoding. Java (BigEndianShortCoder) and Python (BigEndianShortCoder) encode the INT16 schema type as 2 big endian bytes, so rows with such fields could not be exchanged with the other SDKs. The beam:logical_type:timestamp:v1 cases in standard_coders.yaml depend on this encoding for precisions below 5.

Changes:

  • Add coder.EncodeInt16, DecodeInt16, EncodeUint16 and DecodeUint16.
  • The row encoder and decoder use them for int16 and uint16 fields. uint16 is stored as an INT16 schema field.
  • Byte level test against the Java and Python encoding.
  • CHANGES.md breaking change note: rows with int16 or uint16 fields written by earlier Go SDK versions decode differently.

This is the first PR of a series for #39684 (Go SDK portable logical 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.

The reflection based row coder used the varint encoding for int16 and
uint16 fields. Java and Python encode the INT16 schema type as 2 big
endian bytes, so rows with such fields could not be exchanged with the
other SDKs.

Fixes apache#40151. Part of apache#39684.
@Eliaaazzz
Eliaaazzz force-pushed the go-row-int16-bigendian branch from 525272f to 15745eb Compare September 17, 2026 13:38
@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

case reflect.String:
return typeDecoderFieldReflect{decode: reflectDecodeString}, nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
case reflect.Int, reflect.Int8, reflect.Int32, reflect.Int64:

@Abacn Abacn Sep 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Int8 (BYTE) likely has similar inconsistency. Consider a same fix here, or could be a follow up

edit: It's fine: BYTE is backed by uint8. See https://github.com/Eliaaazzz/beam/blob/15745eb513417942b6cfe563961edb508804bd8a/sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go#L658

Comment thread CHANGES.md
## Breaking Changes

* X behavior was changed ([#X](https://github.com/apache/beam/issues/X)).
* (Go) The row coder now encodes `int16` and `uint16` struct fields as 2 byte big endian INT16 values, matching the Java and Python SDKs. Rows with such fields written by earlier Go SDK versions decode differently with this version ([#40151](https://github.com/apache/beam/issues/40151)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider changing

Rows with such fields written by earlier Go SDK versions decode differently with this version

To something

This is a upgrade incompatible change for streaming pipelines used rows of int16/uint16 types

moer informative to users (decoding is an implementation detail)

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping 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).

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.

[Bug]: Go SDK row coder encodes INT16 schema fields as varint instead of big endian

2 participants