-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Minor
-
Affects Version/s: None
-
Component/s: API / Python
{{}}
Summary
PyFlink's ArrayType and MultisetType 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.
Reproduction
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'
Same for DataTypes.MULTISET(DataTypes.DATE()).
Fix
Call from_sql_type on each element, matching MapType.from_sql_type. Regression tests added for ARRAY<DATE> and MULTISET<DATE>.
- links to