[Task]: Go SDK portable logical type support
What needs to happen?
Logical types defined in https://github.com/apache/beam/blob/master/model/pipeline/src/main/proto/org/apache/beam/model/pipeline/v1/schema.proto are not supported in Go SDK. This prevents Go SDK to use schema transforms in a meaningful way.
Currently, only PYTHON_CALLABLE appear to be supported,
https://github.com/apache/beam/blob/1318bfe2039aa3d5b421bf1f23f9fcc338916750/sdks/go/pkg/beam/transforms/xlang/python/external.go#L42
however, through a different mechanism. Likely we need to first implement a framework for portable logical types in Golang, then implement each of them
Issue Priority
Priority: 2 (default / most normal work should be filed as P2)
Issue Components
- [ ] Component: Python SDK
- [ ] Component: Java SDK
- [x] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Infrastructure
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Prism Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
Some AI insights. Likely we need a series of changes to support it
Architectural Comparison: Go SDK vs. Python SDK
In Python (schemas.py), a LogicalType is a unified class containing:
- The URN (
urn()) - The Language Type (
language_type()) - The Representation Wire Type (
representation_type()) - Bidirectional Converters:
to_representation_type(val)andto_language_type(val) - Argument Specs:
argument_type()andargument()for parameterized types
When RowCoder encodes/decodes rows in Python, it automatically invokes to_representation_type() / to_language_type().
In Go (logicaltypes.go), LogicalType is only a static struct containing goT, storageT, argT, argV—with no conversion methods attached. Custom encoding/decoding is offloaded to RegisterSchemaProviders or SchemaProvider instances (like callableSourceProvider in external.go:L79).
Key Gaps in Go SDK for Portable Logical Type Support
Gap 1: Lack of Bidirectional Conversion Methods in schema.LogicalType
- Problem:
schema.LogicalTypein Go (logicaltypes.go) defines types (goTandstorageT), but does not provideToStorageValue(goValue)orToGoValue(storageValue)functions. - Impact: Automatic conversion cannot occur during
RowEncoder/RowDecoderexecution. Every new logical type requires writing manualBuildEncoderandBuildDecoderclosures usingcoder.EncodeStringUTF8or reflection, rather than specifying how to map a Go value to its underlying storage representation type.
Gap 2: Fragmented Registries across Packages
- Problem: Logical type metadata is split across three ununified registries:
schema.RegisterLogicalType: RegistersgoT<->storageTinschema.Registry(logicaltypes.go:L36).coder.RegisterSchemaProviders: Registers encoder/decoder functions inRowEncoderBuilder/RowDecoderBuilder(row.go:L43).beam.RegisterSchemaProviderWithURN: Ties a URN to aSchemaProviderinterface (schema.go:L87).
- Impact: Adding a new logical type requires multiple calls across
schema,coder, andbeampackages rather than registering a single logical type object.
Gap 3: Missing Argument & Payload Support for Parameterized Types
- Proto Specification (
schema.proto:L152-L165):message LogicalType { string urn = 1; bytes payload = 2; FieldType representation = 3; FieldType argument_type = 4; FieldValue argument = 5; } - Problem: In
schema.go:L580, argument handling is explicitly marked as unhandled:
Neither// TODO(BEAM-9615): Handle type Arguments.reflectTypeToFieldType(encoding) norfieldTypeToReflectType(decoding) sets or parsesargument_typeorargument. - Impact: Parameterized logical types defined in Beam standard schemas—such as
TIMESTAMP(precision arg),DECIMAL(precision/scale arg),FIXED_BYTES(length arg), andVAR_CHAR(max_length arg)—cannot be serialized or deserialized with their parameters.
Gap 4: Local Identifier Keying vs. Standard URN Lookup
- Problem: Go SDK uses
identifieras the map key inregistry.logicalTypes[identifier].- For Go's primitive type overrides (
int,uint16),identifieris"int","uint16"(logicaltypes.go:L166-L171). - For
time.Time,identifieris"time.Time"(encoding.go:L52).
- For Go's primitive type overrides (
- Impact: When decoding a row schema sent from a cross-language runner or Python/Java SDK containing standard URNs (e.g.
beam:logical_type:timestamp:v1orbeam:logical_type:date:v1),fieldTypeToReflectTypeinschema.go:L796attemptsr.logicalTypes["beam:logical_type:timestamp:v1"]and fails with:unknown logical type: beam:logical_type:timestamp:v1
Gap 5: Non-Standard Wire Representations for Standard Types (e.g., time.Time)
- Problem: In
encoding.go:L52-L53, L274, Go'stime.Timeis registered using a custom Go-specific logical type ("time.Time") that encodes time usingt.MarshalText()(string format) inside a wrapper structstruct{ EncodedBeamData string }. - Impact: Standard Beam portable timestamps expect either
beam:logical_type:micros_instant:v1(ROW<seconds: INT64, micros: INT64>),beam:logical_type:millis_instant:v1(INT64), orbeam:logical_type:timestamp:v1. Go'stime.Timecannot interoperate out of the box with cross-language rows containing standard Beam timestamps.
Gap 6: FieldValue <-> reflect.Value Conversion Framework Missing
- Problem:
FieldValueprotos inschema.protoare used to encode default values, option values, and logical type arguments. Go SDK only supports basic toggle options (optGoNillableUrn,optGoEmbeddedUrn) and string options (optGoLogicalUrn) (schema.go:L408-L500). - Impact: Arguments or payloads stored inside
pipepb.FieldValuecannot be automatically converted to Goreflect.Valueinstances.
Summary of Requirements for a Full Portable Logical Type Framework in Go
To bring Go SDK to parity with Python/Java for portable logical types, the following framework enhancements are needed:
- Extend
LogicalTypeinterface/struct inlogicaltypes.goto includeToStorageValue(goVal)andToGoValue(storageVal)conversion hooks, allowingRowEncoder/RowDecoderto automatically convert values without requiring customSchemaProviderboilerplate. - Support
argument_typeandargument(pipepb.FieldValue) inschema.gowhen translatingLogicalTypeto/frompipepb.FieldType. - Register standard Beam URNs (
beam:logical_type:timestamp:v1,beam:logical_type:date:v1,beam:logical_type:decimal:v1, etc.) by default inschema.defaultRegistry. - Map
time.Timetobeam:logical_type:micros_instant:v1ortimestamp:v1(or provide standard aliases) for cross-language compatibility.
.take-issue
.take-issue
.take-issue
Hi Yi, I went through the Go schema code against the six gaps above and they all check out on current master. Two extra findings on the way: the Go row coder encodes INT16 as a varint while Java and Python use 2 byte big endian, and the Go standard coder regression test skipped every logical type row case with one "logical" filter, so the 7 yaml cases can serve as acceptance tests.
I split the work into a series of PRs, each one commit stacked on the previous one:
- #40152 fixes the INT16 row encoding. This is the separate bug #40151, and timestamp:v1 below precision 5 needs it.
- #40153 plumbs argument_type and argument through the schema proto conversion and keys the registry by URN and argument.
- #40154 adds a single registration call for portable logical types, schema.RegisterLogicalTypeConversion with its parameterized and coder variants, and the standard date and micros_instant types.
- #40155 adds millis_instant and decimal, whose wire encodings differ from their representation types.
- #40156 maps fixed_char, var_char, fixed_bytes and var_bytes to string and []byte as pass through types.
- #40157 adds timestamp:v1 as TimestampMillis, TimestampMicros and TimestampNanos.
- #40158 updates the programming guide.
With the last one, every logical type row case in standard_coders.yaml runs in the Go regression test.
Two decisions I made that are easy to change if you prefer otherwise. First, time.Time keeps its current Go specific encoding and the standard types are separate Go types, so nothing existing breaks. Second, because the Go row coder is built from the Go type alone, each URN and argument value maps to one named Go type, so timestamp:v1 covers precisions 3, 6 and 9, and the string and bytes types do not enforce their length argument.
If the other assignees have work in progress on any part of this, I am happy to rebase or drop the overlapping PR.
Update: #40155 and #40156 are open again. #40157 and #40158 stay closed for now to keep the review load small, and their branches stay in my fork.