[ 
https://issues.apache.org/jira/browse/FLINK-41669?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ilya Soin updated FLINK-41669:
------------------------------
    Description: 
3 interconnected bugs related to _LOCAL_DATE / LOCAL_TIME / LOCAL_DATE_TIME._
 
{*}Bug 1{*}: _from_collection_ silently turns local temporal values into 
{_}NULL{_}:
{code:java}
import datetime
from pyflink.common.typeinfo import Types, LocalTimeTypeInfo
from pyflink.datastream import StreamExecutionEnvironment

T = LocalTimeTypeInfo.TimeType
env = StreamExecutionEnvironment.get_execution_environment()
ti = Types.ROW([LocalTimeTypeInfo(T.LOCAL_DATE),
                LocalTimeTypeInfo(T.LOCAL_TIME),
                LocalTimeTypeInfo(T.LOCAL_DATE_TIME)])
ds = env.from_collection(
    [(datetime.date(2023, 11, 14),
      datetime.time(12, 34, 56, 123456),
      datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))],
    type_info=ti)
print(list(ds.execute_and_collect()))
{code}
{*}Actual{*}: {_}[Row(f0=None, f1=None, f2=None)]{_}. There is no error, and 
the values are already +I[null, null, null] on the Java side. 

{*}Expected{*}: _[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 34, 
56, 123456), f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_

{*}Cause{*}: _LocalTimeTypeInfo_ in Python defines no need_conversion / 
to_internal_type, so raw date / time / datetime objects are pickled. The 
converter in _PythonTypeUtils_ only accepts _Integer / Long_ for these types 
and returns null for anything else.
 
{*}Bug 2{*}: _execute_and_collect_ returns raw bytes for local temporal values:
{code:java}
from pyflink.common import Row

ds = env.from_collection([1]).map(
    lambda _: Row(datetime.date(2023, 11, 14),
                  datetime.time(12, 34, 56, 123456),
                  datetime.datetime(2023, 11, 14, 22, 13, 20, 123456)),
    output_type=ti)
print(list(ds.execute_and_collect()))
{code}
{*}Actual{*}: _[Row(f0=bytearray(b'\x00\x00\x07\xe7\x0b\x0e'), 
f1=bytearray(b'\x0c"8\x07[\xca\x00'), 
f2=bytearray(b'\x00\x00\x07\xe7\x0b\x0e\x16\r\x14\x07[\xca\x00'))]_ 
 
{*}Expected{*}: 
_[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 34, 56, 123456), 
f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_
 
{*}Cause{*}: _PythonBridgeUtils.getPickledBytesFromJavaObject_ has no branch 
for {_}LocalTimeTypeInfo{_}, so the value falls through to the generic path and 
reaches Python as bytes. Python also has no from_internal_type to decode it.
 
{*}Bug 3{*}: Java converters for local temporal types are zone-dependent and 
lose precision
 
{*}Cause{*}: the converters interpret the incoming number as an instant and 
convert it with {_}ZoneId.systemDefault(){_}, although local temporal types 
carry no time zone, and they go
through {_}Instant.ofEpochMilli(micros / 1000){_}, which drops microseconds and 
truncates toward zero. This is currently masked by Bug 1. It becomes visible as 
soon as Python sends the internal representation (epoch days / microseconds).

  was:
3 interconnected bugs related to ** _LOCAL_DATE / LOCAL_TIME / LOCAL_DATE_TIME._
 
{*}Bug 1{*}: _from_collection_ silently turns local temporal values into 
{_}NULL{_}:
{code:java}
import datetime
from pyflink.common.typeinfo import Types, LocalTimeTypeInfo
from pyflink.datastream import StreamExecutionEnvironment

T = LocalTimeTypeInfo.TimeType
env = StreamExecutionEnvironment.get_execution_environment()
ti = Types.ROW([LocalTimeTypeInfo(T.LOCAL_DATE),
                LocalTimeTypeInfo(T.LOCAL_TIME),
                LocalTimeTypeInfo(T.LOCAL_DATE_TIME)])
ds = env.from_collection(
    [(datetime.date(2023, 11, 14),
      datetime.time(12, 34, 56, 123456),
      datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))],
    type_info=ti)
print(list(ds.execute_and_collect()))
{code}
{*}Actual{*}: {_}[Row(f0=None, f1=None, f2=None)]{_}. There is no error, and 
the values are already +I[null, null, null] on the Java side. 

{*}Expected{*}: _[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 34, 
56, 123456), f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_

{*}Cause{*}: _LocalTimeTypeInfo_ in Python defines no need_conversion / 
to_internal_type, so raw date / time / datetime objects are pickled. The 
converter in _PythonTypeUtils_ only accepts _Integer / Long_ for these types 
and returns null for anything else.
 
{*}Bug 2{*}: _execute_and_collect_ returns raw bytes for local temporal values:
{code:java}
from pyflink.common import Row

ds = env.from_collection([1]).map(
    lambda _: Row(datetime.date(2023, 11, 14),
                  datetime.time(12, 34, 56, 123456),
                  datetime.datetime(2023, 11, 14, 22, 13, 20, 123456)),
    output_type=ti)
print(list(ds.execute_and_collect()))
{code}
{*}Actual{*}: _[Row(f0=bytearray(b'\x00\x00\x07\xe7\x0b\x0e'), 
f1=bytearray(b'\x0c"8\x07[\xca\x00'), 
f2=bytearray(b'\x00\x00\x07\xe7\x0b\x0e\x16\r\x14\x07[\xca\x00'))]_ 
 
{*}Expected{*}: 
_[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 34, 56, 123456), 
f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_
 
{*}Cause{*}: _PythonBridgeUtils.getPickledBytesFromJavaObject_ has no branch 
for {_}LocalTimeTypeInfo{_}, so the value falls through to the generic path and 
reaches Python as bytes. Python also has no from_internal_type to decode it.
 
{*}Bug 3{*}: Java converters for local temporal types are zone-dependent and 
lose precision
 
{*}Cause{*}: the converters interpret the incoming number as an instant and 
convert it with {_}ZoneId.systemDefault(){_}, although local temporal types 
carry no time zone, and they go
through {_}Instant.ofEpochMilli(micros / 1000){_}, which drops microseconds and 
truncates toward zero. This is currently masked by Bug 1. It becomes visible as 
soon as Python sends the internal representation (epoch days / microseconds).


> from_collection and execute_and_collect corrupt LOCAL_DATE / LOCAL_TIME / 
> LOCAL_DATE_TIME values
> ------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41669
>                 URL: https://issues.apache.org/jira/browse/FLINK-41669
>             Project: Flink
>          Issue Type: Bug
>          Components: API / Python
>    Affects Versions: 2.3.0
>            Reporter: Ilya Soin
>            Priority: Major
>
> 3 interconnected bugs related to _LOCAL_DATE / LOCAL_TIME / LOCAL_DATE_TIME._
>  
> {*}Bug 1{*}: _from_collection_ silently turns local temporal values into 
> {_}NULL{_}:
> {code:java}
> import datetime
> from pyflink.common.typeinfo import Types, LocalTimeTypeInfo
> from pyflink.datastream import StreamExecutionEnvironment
> T = LocalTimeTypeInfo.TimeType
> env = StreamExecutionEnvironment.get_execution_environment()
> ti = Types.ROW([LocalTimeTypeInfo(T.LOCAL_DATE),
>                 LocalTimeTypeInfo(T.LOCAL_TIME),
>                 LocalTimeTypeInfo(T.LOCAL_DATE_TIME)])
> ds = env.from_collection(
>     [(datetime.date(2023, 11, 14),
>       datetime.time(12, 34, 56, 123456),
>       datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))],
>     type_info=ti)
> print(list(ds.execute_and_collect()))
> {code}
> {*}Actual{*}: {_}[Row(f0=None, f1=None, f2=None)]{_}. There is no error, and 
> the values are already +I[null, null, null] on the Java side. 
> {*}Expected{*}: _[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 
> 34, 56, 123456), f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_
> {*}Cause{*}: _LocalTimeTypeInfo_ in Python defines no need_conversion / 
> to_internal_type, so raw date / time / datetime objects are pickled. The 
> converter in _PythonTypeUtils_ only accepts _Integer / Long_ for these types 
> and returns null for anything else.
>  
> {*}Bug 2{*}: _execute_and_collect_ returns raw bytes for local temporal 
> values:
> {code:java}
> from pyflink.common import Row
> ds = env.from_collection([1]).map(
>     lambda _: Row(datetime.date(2023, 11, 14),
>                   datetime.time(12, 34, 56, 123456),
>                   datetime.datetime(2023, 11, 14, 22, 13, 20, 123456)),
>     output_type=ti)
> print(list(ds.execute_and_collect()))
> {code}
> {*}Actual{*}: _[Row(f0=bytearray(b'\x00\x00\x07\xe7\x0b\x0e'), 
> f1=bytearray(b'\x0c"8\x07[\xca\x00'), 
> f2=bytearray(b'\x00\x00\x07\xe7\x0b\x0e\x16\r\x14\x07[\xca\x00'))]_ 
>  
> {*}Expected{*}: 
> _[Row(f0=datetime.date(2023, 11, 14), f1=datetime.time(12, 34, 56, 123456), 
> f2=datetime.datetime(2023, 11, 14, 22, 13, 20, 123456))]_
>  
> {*}Cause{*}: _PythonBridgeUtils.getPickledBytesFromJavaObject_ has no branch 
> for {_}LocalTimeTypeInfo{_}, so the value falls through to the generic path 
> and reaches Python as bytes. Python also has no from_internal_type to decode 
> it.
>  
> {*}Bug 3{*}: Java converters for local temporal types are zone-dependent and 
> lose precision
>  
> {*}Cause{*}: the converters interpret the incoming number as an instant and 
> convert it with {_}ZoneId.systemDefault(){_}, although local temporal types 
> carry no time zone, and they go
> through {_}Instant.ofEpochMilli(micros / 1000){_}, which drops microseconds 
> and truncates toward zero. This is currently masked by Bug 1. It becomes 
> visible as soon as Python sends the internal representation (epoch days / 
> microseconds).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to