Skip to content

Beam Programming Guide: Add Python version of Section 6.4 "Logical Types" #21185

Open

Description

@damccorm

Imported from Jira BEAM-13340. Original Jira may contain additional context.
Reported by: bhulette.
Subtask of issue #21182

Activity

  1. jonathansudhakar1 commented on Nov 29, 2026

    @jonathansudhakar1
    Contributor

    @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).

    What's missing in §6.4 Logical types today:

    • §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):

    1. §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.
    2. §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.
    3. 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions