Skip to main content
Scalar function
Aliases: slice NULL supplied argument returns NULL.

Syntax

Scalar

Slice endpoint (scalar)

  • The third argument is the inclusive end index. It is not a length. Supply exactly three arguments.

Arguments

Type notation used below:
  • T is the array element type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.

Scalar, slice endpoint

Returns

  • Type: ARRAY<T>
  • Possible values: Selected elements.
  • NULL behavior: NULL supplied argument returns NULL.
  • Shape: Contains the input elements between the inclusive start and end bounds, after adjusting out-of-range bounds as described below.
  • Ordering: Preserves input encounter order; reversed positive bounds return an empty array.

Scalar, Slice endpoint

  • Type: ARRAY<T>, preserving the input element type
  • Possible values: Selected elements.
  • NULL behavior: NULL supplied argument returns NULL.
  • Shape: Contains the input elements between the inclusive start and end bounds, after adjusting out-of-range bounds as described below.
  • Ordering: Preserves input encounter order; reversed positive bounds return an empty array.

Properties

Usage notes

  • Negative bounds count from the end; start zero behaves as one.
  • Bounds are inclusive, positive indexes are one-based, negative indexes count from the end, and start zero acts as one. Too-negative start is clamped to the start; an end beyond the length is clamped to the last element. An end below the array or a start beyond the array produces an empty array.
  • INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.

Examples

Typical behavior

Alias calling form: SLICE

Limitations

  • ARRAY_SLICE and SLICE take exactly three arguments. The third is an inclusive end index; SLICE does not use Spark’s length interpretation. A fourth step or stride argument is not accepted.
Last modified on October 15, 2026