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.
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
Splunk SPL users
In Splunk SPL, you can use mvindex
to extract elements from an array. APL’s array_slice
is similar but more expressive, allowing you to specify slices with optional bounds.
ANSI SQL users
In ANSI SQL, arrays are often handled using JSON functions or window functions, requiring workarounds to slice arrays. In APL, array_slice
directly handles arrays, making operations more concise.
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. |
An array containing the elements from the specified slice. If the indices are out of bounds, it adjusts to return valid elements without error.
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.
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.
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
Splunk SPL users
In Splunk SPL, you can use mvindex
to extract elements from an array. APL’s array_slice
is similar but more expressive, allowing you to specify slices with optional bounds.
ANSI SQL users
In ANSI SQL, arrays are often handled using JSON functions or window functions, requiring workarounds to slice arrays. In APL, array_slice
directly handles arrays, making operations more concise.
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. |
An array containing the elements from the specified slice. If the indices are out of bounds, it adjusts to return valid elements without error.
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.