The array_shift_right function in Axiom Processing Language (APL) shifts the elements of an array one position to the right. The last element of the array wraps around and becomes the first element. You can use this function to reorder elements, manage time-series data in circular arrays, or preprocess arrays for specific analytical needs.

When to use the function

  • To manage and rotate data within arrays.
  • To implement cyclic operations or transformations.
  • To manipulate array data structures in log analysis or telemetry contexts.

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.

Usage

Syntax

array_shift_right(array: array) : array

Parameters

ParameterTypeDescription
arrayarrayThe input array whose elements are shifted

Returns

An array with its elements shifted one position to the right. The last element of the input array wraps around to the first position.

Use case example

Reorganize span events in telemetry data for visualization or debugging.

Query

['otel-demo-traces']
| take 50
| extend shifted_events = array_shift_right(events, 1)

Run in Playground

Output

events
[
  {
    "name": "Enqueued",
    "timestamp": 1734001215487927300,
    "attributes": null
  },
  {
    "attributes": null,
    "name": "Sent",
    "timestamp": 1734001215487937000
  },
  {
    "timestamp": 1734001215488191000,
    "attributes": null,
    "name": "ResponseReceived"
  }
]
shifted_events
[
  null,
  {
    "timestamp": 1734001215487927300,
    "attributes": null,
    "name": "Enqueued"
  },
  {
    "attributes": null,
    "name": "Sent",
    "timestamp": 1734001215487937000
  }
]

The query rotates span events for better trace debugging.

  • 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_left: Shifts array elements one position to the left, moving the first element to the last position.