MaxGekk opened a new pull request, #42616:
URL: https://github.com/apache/spark/pull/42616

   ### What changes were proposed in this pull request?
   In the PR, I propose to make the `array_insert` function 1-based for 
negative indexes. So, the maximum index is -1 should point out to the last 
element, and the function should insert new element at the end of the given 
array for the index -1.
   
   The old behaviour can be restored via the SQL config 
`spark.sql.legacy.negativeIndexInArrayInsert`.
   
   This is a backport of https://github.com/apache/spark/pull/42564
   
   ### Why are the changes needed?
   1.  To match the behaviour of functions such as `substr()` and 
`element_at()`.
   ```sql
   spark-sql (default)> select element_at(array('a', 'b'), -1), substr('ab', 
-1);
   b    b
   ```
   2. To fix an inconsistency in `array_insert` in which positive indexes are 
1-based, but negative indexes are 0-based.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes.
   
   Before:
   ```sql
   spark-sql (default)> select array_insert(array('a', 'b'), -1, 'c');
   ["a","c","b"]
   ```
   
   After:
   ```sql
   spark-sql (default)> select array_insert(array('a', 'b'), -1, 'c');
   ["a","b","c"]
   ```
   
   ### How was this patch tested?
   By running the modified test suite:
   ```
   $ build/sbt "test:testOnly *CollectionExpressionsSuite"
   $ build/sbt "test:testOnly *DataFrameFunctionsSuite"
   $ PYSPARK_PYTHON=python3 build/sbt "sql/testOnly 
org.apache.spark.sql.SQLQueryTestSuite"
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to