Serge Rielau created SPARK-44840: ------------------------------------ Summary: array_insert() give wrong results for ngative index Key: SPARK-44840 URL: https://issues.apache.org/jira/browse/SPARK-44840 Project: Spark Issue Type: Bug Components: Spark Core Affects Versions: 3.4.0 Reporter: Serge Rielau
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(). {code:java} > 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"] {code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org