array_rotate_right
Usage#
Syntax#
array_rotate_right(array, count)Parameters#
array: An array to rotate.count: An integer specifying the number of positions to rotate the array to the right.
Returns#
An array where the elements are rotated to the right by the specified count.
Use case example#
In OpenTelemetry traces, rotating an array of span details can help you reorder trace information for performance tracking or troubleshooting.
Query
['otel-demo-traces']
| extend rotated_sequence = array_rotate_right(events, 1)Output
events
[
{
"attributes": null,
"name": "Enqueued",
"timestamp": 1733997421220380700
},
{
"name": "Sent",
"timestamp": 1733997421220390400,
"attributes": null
},
{
"attributes": null,
"name": "ResponseReceived",
"timestamp": 1733997421221118500
}
]rotated_sequence
[
{
"attributes": null,
"name": "ResponseReceived",
"timestamp": 1733997421221118500
},
{
"attributes": null,
"name": "Enqueued",
"timestamp": 1733997421220380700
},
{
"name": "Sent",
"timestamp": 1733997421220390400,
"attributes": null
}
]List of related functions#
- array_length: Returns the number of elements in an array.
- array_index_of: Finds the index of an element in an array.
- array_rotate_left: Rotates elements of an array to the left.
Other query languages#
Splunk SPL users
In APL, the array_rotate_right function provides functionality similar to the use of mvindex or specific SPL commands for reordering arrays. The rotation here shifts all elements by a set count to the right, maintaining their original order within the new positions.
Splunk example
| eval rotated_array=mvindex(array, -3)APL equivalent
| extend rotated_array = array_rotate_right(array, 3)ANSI SQL users
ANSI SQL lacks a direct function for rotating elements within arrays. In APL, the array_rotate_right function offers a straightforward way to accomplish this by specifying a rotation count, while SQL users typically require a more complex use of CASE statements or custom functions to achieve the same.
SQL example
-- No direct ANSI SQL equivalent for array rotationAPL equivalent
| extend rotated_array = array_rotate_right(array_column, 3)