Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-40308

str_to_map should accept non-foldable delimiter arguments

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.4.0
    • 3.4.0
    • SQL
    • None

    Description

      Currently, str_to_map requires the delimiter arguments to be foldable expressions. For example, the following doesn't work in Spark SQL:

      drop table if exists maptbl;
      create table maptbl as select ',' as del1, ':' as del2, 'a:1,b:2,c:3' as str;
      insert into table maptbl select '%' as del1, '-' as del2, 'a-1%b-2%c-3' as str;
      select str, str_to_map(str, del1, del2) from maptbl;
      

      You get the following error:

      str_to_map's delimiters must be foldable.; line 1 pos 12;
      

      However, the above example SQL statements do work in Hive 2.3.9. There, you get:

      +--------------+----------------------------+
      |     str      |            _c1             |
      +--------------+----------------------------+
      | a:1,b:2,c:3  | {"a":"1","b":"2","c":"3"}  |
      | a-1%b-2%c-3  | {"a":"1","b":"2","c":"3"}  |
      +--------------+----------------------------+
      2 rows selected (0.13 seconds)
      

      It's unlikely that an input table would have the needed delimiters in columns. The use-case is more likely to be something like this, where the delimiters are determined based on some other value:

      select
        str,
        str_to_map(str, ',', if(region = 0, ':', '#')) as m
      from
        maptbl2;
      

      Attachments

        Activity

          People

            bersprockets Bruce Robbins
            bersprockets Bruce Robbins
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: