Interface DictionaryWriterState
- All Known Implementing Classes:
LocalDictionaryWriterState,SharedDictionaryWriterState
public interface DictionaryWriterState
Tracks the cumulative dictionary for one Arrow dictionary id within a barrage stream. Shared by all
DictionaryChunkWriter instances that reference the same id.
fillIndexChunk(io.deephaven.chunk.Chunk<io.deephaven.chunk.attributes.Values>, io.deephaven.engine.rowset.RowSet, io.deephaven.extensions.barrage.BarrageOptions, io.deephaven.chunk.WritableIntChunk<io.deephaven.chunk.attributes.Values>) is called once per batch (non-null rows only) while building a batch. After the batch's
DictionaryBatch has been emitted, call resetDelta() to advance the delta
boundary.
Two concrete implementations exist:
LocalDictionaryWriterState— for viewport subscriptions and snapshots.resetDelta()clears the delta list entirely; only newly-seen values since the last reset are tracked.SharedDictionaryWriterState— for full subscriptions and growing subscriptions. The full cumulative value list is retained so that a new subscriber joining mid-stream can receive all current values as an initialisDelta=falsebatch.
Thread-safety: an instance serves a single subscriber, whose writes use the instance from one thread at a time, so
the instance does not need to be thread-safe. The SharedDictionaryWriterState instances of different
subscribers share a SharedWriterDictionary, which is thread-safe.
-
Method Summary
Modifier and TypeMethodDescription@NotNull WritableChunk<Values> Builds and returns a typed chunk containing the current delta values (values added since the lastresetDelta()call, or all values if this is the first batch for this subscriber).voidfillIndexChunk(@NotNull Chunk<Values> source, @Nullable RowSet subset, @NotNull BarrageOptions options, @NotNull WritableIntChunk<Values> out) Fillsoutwith one dictionary index per logical row insource/subset.longbooleanhasDelta()Returnstrueif a DictionaryBatch message needs to be emitted before the current RecordBatch — either because this is the first batch for this subscriber (isDelta=false) or because new values have been added since the last reset.booleanvoidreset()Resets the dictionary to an empty state, as if no values had ever been seen.voidAccepts the batch just written.intCurrent number of distinct values in the dictionary (resets to zero afterreset()).
-
Method Details
-
getDictId
long getDictId() -
fillIndexChunk
void fillIndexChunk(@NotNull @NotNull Chunk<Values> source, @Nullable @Nullable RowSet subset, @NotNull @NotNull BarrageOptions options, @NotNull @NotNull WritableIntChunk<Values> out) Fillsoutwith one dictionary index per logical row insource/subset. Null rows (in non-deephaven-nulls mode) produceQueryConstants.NULL_INT; non-null rows produce a non-negative dictionary index, registering new values as needed.- Parameters:
source- the source chunk containing column valuessubset- row positions withinsourceto include;nullmeans all rowsoptions- barrage serialization options (e.g.useDeephavenNulls)out- pre-sized output chunk to fill with dictionary indices
-
hasDelta
boolean hasDelta()Returnstrueif a DictionaryBatch message needs to be emitted before the current RecordBatch — either because this is the first batch for this subscriber (isDelta=false) or because new values have been added since the last reset. A subscriber is owed values that others added to a shared dictionary only once a batch of its own references the dictionary; seeSharedDictionaryWriterState. -
needsFullBatch
boolean needsFullBatch() -
buildDeltaChunk
Builds and returns a typed chunk containing the current delta values (values added since the lastresetDelta()call, or all values if this is the first batch for this subscriber). The returned chunk is owned by the caller and must be closed when no longer needed. -
resetDelta
void resetDelta()Accepts the batch just written. Advances the delta boundary past the values that the lastbuildDeltaChunk()covered, once the DictionaryBatch built from them has been emitted, so that they are excluded from future delta batches. This is called after every accepted batch, whether or not a DictionaryBatch was built for this state; without a precedingbuildDeltaChunk()call, the shared implementation's boundary does not move. Unlikereset(), this does not discard the accumulated value-to-index mapping, so the client's cached dictionary remains valid after this call. -
totalSize
int totalSize()Current number of distinct values in the dictionary (resets to zero afterreset()). -
reset
void reset()Resets the dictionary to an empty state, as if no values had ever been seen. The next DictionaryBatch emitted will beisDelta=falsewith only the values encountered in the next batch. Call this when the cumulative dictionary size exceeds the live row count and compaction is needed.
-