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.

Usage

Syntax

['array_shift_left'](array, shift_amount)

Parameters

ParameterTypeDescription
arrayArrayThe array to shift.
shift_amountIntegerThe 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)

Run in Playground

Output

events
[
  {
    "name": "Enqueued",
    "timestamp": 1734001111273917000,
    "attributes": null
  },
  {
    "attributes": null,
    "name": "Sent",
    "timestamp": 1734001111273925400
  },
  {
    "name": "ResponseReceived",
    "timestamp": 1734001111274167300,
    "attributes": null
  }
]
shifted_events
[
  {
    "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.