You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Beam Programming Guide: Add Python version of Section 6.4 "Logical Types" #21185
@ahmedabu98, I'd like to pick this up, and wanted to check the approach with you first since you added the Python Date and Timestamp logical types (#38078, #39537).
§6.4.1 has text and examples for Java, Go and TypeScript, but nothing for Python.
§6.4.2 says the Python SDK provides no convenience logical types "other than to handle MicrosInstant". apache_beam.typehints.schemas registers more than that now, and schema inference uses some of them for ordinary type hints. On current master, NamedTuple fields typed Timestamp, datetime.date and decimal.Decimal become beam:logical_type:micros_instant:v1, beam:logical_type:date:v1 and beam:logical_type:decimal:v1.
The Java TimestampNanos example in §6.4.1 doesn't compile as written: it declares SCHEMA but uses schema, getBaseType() returns a Schema where a FieldType is expected, and toInputType(Row base) reads from row.
Proposed change (website plus a tested snippet; no SDK code changes):
§6.4.1, Python: a short paragraph and an example that subclasses NoArgumentLogicalType, implements urn, language_type, representation_type, to_representation_type and to_language_type, registers the class with @LogicalType.register_logical_type, and uses its language type as a NamedTuple field. The code would live in examples/snippets/snippets.py, with a test in snippets_test.py (a RowCoder round trip plus a small pipeline), and the guide would include it with code_sample like the other Python snippets. I tried this on master locally and it works on the default runner.
§6.4.2, Python: replace the "minimal convenience logical types" sentence with the type hints that map to built-in logical types. I'd also mention that Timestamp maps to MicrosInstant by default and that re-registering MillisInstant changes that, as the MillisInstant docstring describes.
Java: fix the TimestampNanos example.
Two questions before I start:
Which built-in Python logical types should the guide present as user-facing? I'd cover the ones inference uses for Timestamp, datetime.date and decimal.Decimal, and leave out internal ones such as PythonCallable and the JDBC types, unless you'd like more listed.
Is LogicalType.register_logical_type the API you'd like users to use for their own logical types?
Activity
jonathansudhakar1 commentedon Nov 29, 2026
@ahmedabu98, I'd like to pick this up, and wanted to check the approach with you first since you added the Python
DateandTimestamplogical types (#38078, #39537).What's missing in §6.4 Logical types today:
MicrosInstant".apache_beam.typehints.schemasregisters more than that now, and schema inference uses some of them for ordinary type hints. On current master,NamedTuplefields typedTimestamp,datetime.dateanddecimal.Decimalbecomebeam:logical_type:micros_instant:v1,beam:logical_type:date:v1andbeam:logical_type:decimal:v1.TimestampNanosexample in §6.4.1 doesn't compile as written: it declaresSCHEMAbut usesschema,getBaseType()returns aSchemawhere aFieldTypeis expected, andtoInputType(Row base)reads fromrow.Proposed change (website plus a tested snippet; no SDK code changes):
NoArgumentLogicalType, implementsurn,language_type,representation_type,to_representation_typeandto_language_type, registers the class with@LogicalType.register_logical_type, and uses its language type as aNamedTuplefield. The code would live inexamples/snippets/snippets.py, with a test insnippets_test.py(aRowCoderround trip plus a small pipeline), and the guide would include it withcode_samplelike the other Python snippets. I tried this on master locally and it works on the default runner.Timestampmaps toMicrosInstantby default and that re-registeringMillisInstantchanges that, as theMillisInstantdocstring describes.TimestampNanosexample.Two questions before I start:
Timestamp,datetime.dateanddecimal.Decimal, and leave out internal ones such asPythonCallableand the JDBC types, unless you'd like more listed.LogicalType.register_logical_typethe API you'd like users to use for their own logical types?