jonathansudhakar1 commented on issue #21185:
URL: https://github.com/apache/beam/issues/21185#issuecomment-7257034338

   @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](https://beam.apache.org/documentation/programming-guide/#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?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to