Interface Validity
Per-item nullability over a run of items, shared by the reader and the writer: the
reader returns it (a column-reader leaf or STRUCT / REPEATED layer scope), and the
writer accepts it as a column's null mask.
A Validity is one of two shapes:
- No nulls — every item at that scope is non-null in the current
batch. The
NO_NULLSsingleton, returned for the no-nulls fast path; no per-batch allocation. - Backed — a packed
long[]bitmap with set-bit = present polarity: bitiis set iff itemiis present (non-null). Wordwcovers items[w*64, w*64+64), low bit = lowest item.
Consumer-side predicates (isNull(i) / isNotNull(i) / hasNulls())
describe nullability; the storage uses set-bit = present internally.
hasNulls() makes the no-nulls fast path explicit:
if (!validity.hasNulls()) {
// tight loop, skip per-item check
} else {
// checked loop
}
This API is Experimental: the shape may change in future releases.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNulls()booleanisNotNull(int i) trueiff the item at indexiis not null.booleanisNull(int i) trueiff the item at indexiis null.intnextNotNull(int from, int count) Index of the next non-null item in[from, count), or-1if every item in that range is null.intnextNull(int from, int count) Index of the next null item in[from, count), or-1if every item in that range is non-null.intnullCount(int count) Number of null items in this batch.static Validityof(long[] words) Wraps a packedlong[]bitmap (set-bit = present storage).static ValidityofNulls(boolean[] nulls) Builds aValidityover a per-item null mask, wherenulls[i] == truemarks iteminull — the null-centric polarity ofisNull(int).long[]words()The word array (set-bit = present polarity).
-
Field Details
-
NO_NULLS
Singleton signalling "no item at this scope is null in the current batch." Identity-stable across calls.
-
-
Method Details
-
of
Wraps a packed
long[]bitmap (set-bit = present storage). ReturnsNO_NULLSwhenwordsisnull; otherwise returns a fresh backed instance holding the given bitmap. The caller passesnullwhen no item is null: this method does not inspect the words, so a bitmap with every bit set still yields a backed instance, whosehasNulls()answerstrue. The wrapper does not copy — callers must not mutate the bitmap after handing it to aValidity.The caller is responsible for sizing the array to at least
(count + 63) >>> 6words for anycountthey later pass tonullCount(int)/nextNull(int, int)/nextNotNull(int, int), and for keeping indices intoisNull(int)/isNotNull(int)within the same bound. -
ofNulls
Builds aValidityover a per-item null mask, wherenulls[i] == truemarks iteminull — the null-centric polarity ofisNull(int). ReturnsNO_NULLSwhen no item is null, so the all-present fast path is preserved. This is the convenience bridge for callers holding a plainboolean[]; the packedof(long[])and future sparse factories give more compact shapes for their respective cases.- Parameters:
nulls- the per-item null mask; not retained- Returns:
- a
Validitywith the given nulls, orNO_NULLSif there are none
-
hasNulls
boolean hasNulls()falseforNO_NULLS;truefor a backed validity, regardless of its bits. Atrueanswer therefore means the batch may hold nulls, and afalseanswer means it holds none. O(1). May help on hot loops as a per-batch fast-path gate:if (!validity.hasNulls()) { // tight loop, no per-item check } else { // checked loop } -
isNull
boolean isNull(int i) trueiff the item at indexiis null. -
isNotNull
boolean isNotNull(int i) trueiff the item at indexiis not null. -
nullCount
int nullCount(int count) Number of null items in this batch.countis the total item count at this scope — required because the no-nulls shape has no intrinsic length. -
nextNull
int nextNull(int from, int count) Index of the next null item in[from, count), or-1if every item in that range is non-null. -
nextNotNull
int nextNotNull(int from, int count) Index of the next non-null item in[from, count), or-1if every item in that range is null.countis the total item count at this scope — required because the no-nulls shape has no intrinsic length. -
words
long[] words()The word array (set-bit = present polarity). Returnsnullwhen there are no nulls. Otherwise returns the backing array directly — no copy. Callers must not mutate it; mirroring the inbound contract on [#of(long[])], theValidityowns the bitmap once handed in. Bits at indices>= countare undefined and must not be read.
-