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

Dian Fu closed FLINK-40322.
---------------------------
    Fix Version/s: 2.2.2
                   1.20.6
                   2.3.1
                   2.4.0
         Assignee: Nikolaus Schuetz
       Resolution: Fixed

Fixed in:
- master via c1133c338d0a94431ff7d2e3747a8c22ade05075
- release-2.3 via f01cf8cd6b7dabb529760b97ab7fc121ebdc9301
- release-2.2 via 2e995ffa29e3250b9060ac6119d71e8bff505a45
- release-1.20 via 378f8081b3fc96c73a14ec4e287f962cd3da0662

> PyFlink ArrayType/MultisetType.from_sql_type calls to_sql_type instead
> ----------------------------------------------------------------------
>
>                 Key: FLINK-40322
>                 URL: https://issues.apache.org/jira/browse/FLINK-40322
>             Project: Flink
>          Issue Type: Bug
>          Components: API / Python
>            Reporter: Nikolaus Schuetz
>            Assignee: Nikolaus Schuetz
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 2.2.2, 1.20.6, 2.3.1, 2.4.0
>
>
> {{}}
> h2. Summary
> {{PyFlink's 
> [ArrayType|https://github.com/apache/flink/blob/release-2.3.0/flink-python/pyflink/table/types.py#L926]}}
>  and 
> [{{MultisetType}}|https://github.com/apache/flink/blob/release-2.3.0/flink-python/pyflink/table/types.py#L1054]
>   mistakenly call {{to_sql_type}} from their {{from_sql_type}} wrappers:
>  * *MultisetType:* 
> [https://github.com/apache/flink/blob/release-2.3.0/flink-python/pyflink/table/types.py#L1054]
>  * *ArrayType:* 
> [https://github.com/apache/flink/blob/release-2.3.0/flink-python/pyflink/table/types.py#L926]
> This is a typo from the above wrapping of {{{}to_sql_type{}}}. To be clear, 
> {{from_sql_type}} is meant to decode the internal/SQL representation back to 
> Python. For an element type that needs conversion (e.g. {{{}DATE{}}}, whose 
> internal form is an int day-count), decoding an 
> {{{}ARRAY{}}}/{{{}MULTISET{}}} then feeds an {{int}} into 
> {{{}DateType.to_sql_type{}}}, which does {{v.toordinal()}} and as expected it 
> raises:
> {{AttributeError: 'int' object has no attribute 'toordinal'}}
> The sibling {{MapType.from_sql_type}} (same file) is correct — it calls 
> {{from_sql_type}} on both key and value — so 
> {{{}ArrayType{}}}/{{{}MultisetType{}}} are simply inconsistent with it.
> h3. Reproduction
> {code:python}
> from pyflink.table.types import DataTypes
> at = DataTypes.ARRAY(DataTypes.DATE())
> at.from_sql_type([0, 1])
> # expected: [datetime.date(1970, 1, 1), datetime.date(1970, 1, 2)]
> # actual:   AttributeError: 'int' object has no attribute 'toordinal'
> {code}
> Same for {{{}DataTypes.MULTISET(DataTypes.DATE()){}}}.
> h3. Fix
> Call {{from_sql_type}} on each element, matching 
> {{{}MapType.from_sql_type{}}}. Regression tests added for {{ARRAY<DATE>}} and 
> {{{}MULTISET<DATE>{}}}.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to