array_slice
This page explains how to use the array_slice function in APL.
The array_slice
function in APL extracts a subset of elements from an array, based on specified start and end indices. This function is useful when you want to analyze or transform a portion of data within arrays, such as trimming logs, filtering specific events, or working with trace data in OpenTelemetry logs.
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
Parameters
Parameter | Description |
---|---|
array | The input array to slice. |
start | The starting index of the slice (inclusive). If negative, it is counted from the end of the array. |
end | The ending index of the slice (exclusive). If negative, it is counted from the end of the array. |
Returns
An array containing the elements from the specified slice. If the indices are out of bounds, it adjusts to return valid elements without error.
Use case example
Filter spans from trace data to analyze a specific range of events.
Query
Output
Slices the last three events from the events
array, excluding the final one.
List of related functions
- array_concat: Combines multiple arrays.
- array_reverse: Reverses the order of array elements.
- array_shift_right: Shifts array elements to the right.
Was this page helpful?