PyFlink ArrayType/MultisetType.from_sql_type calls to_sql_type instead

XMLWordPrintableJSON

      {{}}

      Summary

      PyFlink's ArrayType and MultisetType  mistakenly call to_sql_type from their from_sql_type wrappers:

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

       

            Assignee:
            Nikolaus Schuetz
            Reporter:
            Nikolaus Schuetz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: