The array_shift_left function in APL rotates the elements of an array to the left by a specified number of positions. If the shift exceeds the array length, it wraps around and continues from the beginning. This function is useful when you need to realign or reorder elements for pattern analysis, comparisons, or other array transformations.
For example, you can use array_shift_left to:
- Align time-series data for comparative analysis.
- Rotate log entries for cyclic pattern detection.
- Reorganize multi-dimensional datasets in your queries.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, there is no direct equivalent to array_shift_left, but you can achieve similar results using custom code or by manipulating arrays manually. In APL, array_shift_left simplifies this operation by providing a built-in, efficient implementation.
['array_shift_left'](array, 1)ANSI SQL doesn’t have a native function equivalent to array_shift_left. Typically, you would use procedural SQL to write custom logic for this transformation. In APL, the array_shift_left function provides an elegant, concise solution.
['array_shift_left'](array_column, shift_amount)Usage
Syntax
['array_shift_left'](array, shift_amount)Parameters
| Parameter | Type | Description |
|---|---|---|
array |
Array | The array to shift. |
shift_amount |
Integer | The number of positions to shift elements to the left. |
Returns
An array with elements shifted to the left by the specified shift_amount. The function wraps the excess elements to the start of the array.
Use case example
Reorganize span events to analyze dependencies in a different sequence.
Query
['otel-demo-traces']
| take 50
| extend shifted_events = array_shift_left(events, 1)Output
[
{
"name": "Enqueued",
"timestamp": 1734001111273917000,
"attributes": null
},
{
"attributes": null,
"name": "Sent",
"timestamp": 1734001111273925400
},
{
"name": "ResponseReceived",
"timestamp": 1734001111274167300,
"attributes": null
}
][
{
"attributes": null,
"name": "Sent",
"timestamp": 1734001111273925400
},
{
"name": "ResponseReceived",
"timestamp": 1734001111274167300,
"attributes": null
},
null
]This query shifts span events for frontend services to analyze the adjusted sequence.
List of related functions
- array_rotate_right: Rotates array elements to the right by a specified number of positions.
- array_rotate_left: Rotates elements of an array to the left.
- array_shift_right: Shifts array elements to the right.