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

array_insert() give wrong results for ngative index

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.0
    • 3.4.2, 4.0.0, 3.5.1
    • Spark Core
    • None

    Description

      Unlike in Snowflake we decided that array_inert() is 1 based.
      This means 1 is the first element in an array and -1 is the last. 
      This matches the behavior of functions such as substr() and element_at().

       

      > SELECT array_insert(array('a', 'b', 'c'), 1, 'z');
      ["z","a","b","c"]
      > SELECT array_insert(array('a', 'b', 'c'), 0, 'z');
      Error
      > SELECT array_insert(array('a', 'b', 'c'), -1, 'z');
      ["a","b","c","z"]
      > SELECT array_insert(array('a', 'b', 'c'), 5, 'z');
      ["a","b","c",NULL,"z"]
      > SELECT array_insert(array('a', 'b', 'c'), -5, 'z');
      ["z",NULL,"a","b","c"]
      > SELECT array_insert(array('a', 'b', 'c'), 2, cast(NULL AS STRING));
      ["a",NULL,"b","c"]
      

       

      Attachments

        Activity

          People

            maxgekk Max Gekk
            srielau Serge Rielau
            Max Gekk Max Gekk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: