soin08 opened a new pull request, #30106:
URL: https://github.com/apache/flink/pull/30106

   ## What is the purpose of the change
   
   `LocalTimeTypeInfo` (`LOCAL_DATE`, `LOCAL_TIME`, `LOCAL_DATE_TIME`) is 
broken in both directions of the PyFlink DataStream API:
   
   - `from_collection` silently turns the values into NULL. Python pickles raw 
`date` / `time` / `datetime` objects, and the Java converter only accepts 
integers for these types and returns null otherwise.
   - `execute_and_collect` returns the serialized bytes (`bytearray`) instead 
of `date` / `time` / `datetime`. `PythonBridgeUtils` has no branch for 
`LocalTimeTypeInfo`, and Python has no conversion back.
   - The Java converters for these types in `PythonTypeUtils` are wrong as 
well, which was masked by the first bug. They go through an `Instant` in the 
JVM default time zone, so `LOCAL_TIME` and `LOCAL_DATE_TIME` are shifted by the 
zone offset, truncated to milliseconds, and values before 1970 are rounded in 
the wrong direction.
   
   Reproducers with actual and expected output are in the ticket.
   
   ## Brief change log
   
   - `LocalTimeTypeInfo` in Python converts to and from an internal 
representation: epoch days for `LOCAL_DATE`, microseconds of the day for 
`LOCAL_TIME`, microseconds since the epoch for `LOCAL_DATE_TIME`. A 
timezone-aware `datetime` for `LOCAL_DATE_TIME` is rejected with a `TypeError`.
   - `PythonBridgeUtils#getPickledBytesFromJavaObject` pickles the same 
representation for `LocalTimeTypeInfo`.
   - The converters in `PythonTypeUtils` build the values with plain calendar 
arithmetic (`LocalDate.ofEpochDay`, `LocalTime.ofNanoOfDay`, 
`LocalDateTime.ofEpochSecond` with `ZoneOffset.UTC`), independent of the JVM 
time zone and with microsecond precision.
   - A separate hotfix commit fixes two typos in the `TypeInformation` 
docstring.
   
   Not covered: local temporal values nested in `LIST`, `MAP` or array type 
infos are still not converted on the way into `from_collection`.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
   - `test_typeinfo.py`: conversion in both directions for the three types, 
including a value before 1970, NULL, a `datetime` in a `LOCAL_DATE` field and 
the error for a timezone-aware `datetime`; `_from_java_type` round trip for the 
three types.
   - `test_stream_execution_environment.py`: 
`test_from_collection_with_local_temporal_types` runs a job and checks the rows 
on the Java side with microsecond precision, including a row before 1970 and a 
NULL row. It does not override the JVM time zone and was run in a UTC+2 zone, 
where it fails with the old converters.
   - Manually ran `from_collection` followed by `execute_and_collect`, and a 
Python `map` followed by `execute_and_collect`, before and after the change.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Fable 5.2)
   


-- 
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