Daniel-Davies commented on code in PR #38867:
URL: https://github.com/apache/spark/pull/38867#discussion_r1064153224
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -4601,6 +4601,231 @@ case class ArrayExcept(left: Expression, right:
Expression) extends ArrayBinaryL
newLeft: Expression, newRight: Expression): ArrayExcept = copy(left =
newLeft, right = newRight)
}
+@ExpressionDescription(
+ usage = "_FUNC_(x, pos, val) - Places val into index pos of array x (array
indices start at 1)",
+ examples = """
+ Examples:
+ > SELECT _FUNC_(array(1, 2, 3, 4), 5, 5);
+ [1,2,3,4,5]
+ > SELECT _FUNC_(array(5, 3, 2, 1), 2, 4);
+ [5,4,3,2,1]
Review Comment:
Fixed by now following 0 index, thanks @beliefer
##########
sql/core/src/test/resources/sql-tests/inputs/array.sql:
##########
@@ -130,6 +130,18 @@ select get(array(1, 2, 3), 3);
select get(array(1, 2, 3), null);
select get(array(1, 2, 3), -1);
+-- function array_insert()
+select array_insert(array(1, 2, 3), 3, 4);
+select array_insert(array(2, 3, 4), 0, 1);
+select array_insert(array(2, 3, 4), 1, 1);
+select array_insert(array(1, 3, 4), -2, 2);
+select array_insert(array(1, 2, 3), 3, "4");
+select array_insert(cast(NULL as ARRAY<INT>), 1, 1);
+select array_insert(array(1, 2, 3, NULL), cast(NULL as INT), 4);
Review Comment:
There doesn't seem to be a way to specify that the array can have NULL
elements in the raw SQL syntax. I've added a null to the base array in the
meantime, but please let me know if there is a better way to avoid the
following outcome:
-- !query
select array_insert(array(2, 3, 4), 5, 1)
-- !query schema
struct<array_insert(array(2, 3, 4), 5, 1):array>
-- !query output
[2,3,4,0,1]
--
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]