Arrow Run-End Encoding: Find a Value by Its Run Boundary
2026-11-09

Arrow Run-End Encoding: Find a Value by Its Run Boundary

Arrow Run-End Encoding represents a sequence of consecutive equal values as one run. The representation stores one value per run and an increasing boundary for each run. A reader uses the boundary array to find which run contains a logical index, then retrieves the matching value. The number of logical elements can therefore differ from the number of stored runs.

The boundary array records cumulative positions

The Apache Arrow columnar specification defines two child arrays named run_ends and values. A value entry describes one consecutive group. The corresponding run end records the cumulative length through that group. Each run has at least one logical element, so the ends are positive and strictly increasing. The run-end child uses a signed integer width supported by the format and contains no null entries.

Consider the fictional sequence red, red, red, blue, blue, red. It has three runs with values red, blue and red. Their run ends are three, five and six. The first red run occupies indices zero through two, the blue run occupies three through four, and the final red run occupies index five. The repeated red value appears in two separate runs because blue interrupts it.

Red spans indices zero to two, blue spans three to four, red resumes at five, with exclusive ends three, five and six.
Nonadjacent red groups have separate run entries. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

An exclusive end identifies the next boundary

For the unsliced example, the first run begins at logical index zero. Its end of three means it covers indices strictly below three. The next run begins at three. Its length can be found by subtracting the preceding end from its own end. With ends of three and five, the blue run therefore has length two.

To find the value at logical index three, look for the first run end strictly greater than three. The first end equals three and is already past the first run's last valid index. The next end is five, so the answer comes from the blue run. A lookup that accepts an equal end would choose the wrong group at a boundary.

Ordered ends support a search across stored runs

The Arrow specification explains that cumulative positions allow a binary search from a logical index. In the Rust Arrow documentation, the physical index of a run is separate from the logical index in the expanded sequence. The search returns the physical position in the ends and values arrays, after which the corresponding run value can be read.

For this example, logical indices three and four both map to physical run index one. Their different logical positions can still matter to other columns in a record batch. Sharing a stored run value does not combine rows or discard the positions in the expanded column. It describes how this one array stores a sequence of repeated values.

Three entries have ends three, five, and six. Index three selects the second entry, blue, because five is the first larger end.
Find the first exclusive end greater than the index and read its value. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Logical length and null state still belong to different levels

The specification distinguishes the logical length of the parent and the physical length of the run children. Here the expanded length is six and there are three run entries. A long sequence of one repeated value can have one run entry, while a changing sequence can have many. The representation is most useful when neighboring values repeat for runs of meaningful length.

Arrow also permits a run value to be null. The boundary for that run remains a valid integer. According to the specification, the parent has no validity bitmap and its null count field is zero. A reader therefore needs to examine the values child to tell which runs represent nulls. Counting run boundaries alone does not reveal which values are missing.

A run boundary is a position in the sequence

Dictionary encoding uses an index to refer to a value stored elsewhere in a dictionary. A run end instead refers to a position in the logical sequence. The same value can occur in distinct runs if it reappears after a different value. A technical record can identify the two children, the logical length, and the convention used for boundary positions. Related examples appear in the robot data systems archive and the technical article directory.

The figure uses a base array with no slice offset. A view with an offset still needs to interpret logical positions relative to its storage, so a debugger should identify the view before reading its physical run indices.

The choice of integer width applies to the cumulative positions. Several individually short runs can still reach a large final boundary. The last boundary in an unsliced array represents the total expanded length. Checking the maximum boundary therefore answers a different question from measuring the length of any one run or counting how many run entries exist.

Primary references

See the Apache Arrow columnar format's run-end encoded layout and the Rust Arrow RunArray representation and lookup documentation.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我