Package com.illumon.iris.db.v2.updateby
Interface UpdateByOperator
- All Known Implementing Classes:
BaseByteUpdateByOperator
,BaseCharUpdateByOperator
,BaseDoubleUpdateByOperator
,BaseFloatUpdateByOperator
,BaseIntUpdateByOperator
,BaseLongUpdateByOperator
,BaseObjectBinaryOperator
,BaseObjectUpdateByOperator
,BasePrimitiveEMAOperator
,BaseShortUpdateByOperator
,BigDecimalCumProdOperator
,BigDecimalCumSumOperator
,BigDecimalDeltaOperator
,BigDecimalEMAOperator
,BigIntegerCumProdOperator
,BigIntegerCumSumOperator
,BigIntegerDeltaOperator
,BigIntegerEMAOperator
,BigNumberEMAOperator
,BooleanFillByOperator
,ByteCumMinMaxOperator
,ByteCumProdOperator
,ByteCumSumOperator
,ByteDeltaOperator
,ByteEMAOperator
,ByteFillByOperator
,CharFillByOperator
,ComparableCumMinMaxOperator
,DoubleCumMinMaxOperator
,DoubleCumProdOperator
,DoubleCumSumOperator
,DoubleDeltaOperator
,DoubleEMAOperator
,DoubleFillByOperator
,FloatCumMinMaxOperator
,FloatCumProdOperator
,FloatCumSumOperator
,FloatDeltaOperator
,FloatEMAOperator
,FloatFillByOperator
,IntCumMinMaxOperator
,IntCumProdOperator
,IntCumSumOperator
,IntDeltaOperator
,IntEMAOperator
,IntFillByOperator
,LongCumMinMaxOperator
,LongCumProdOperator
,LongCumSumOperator
,LongDeltaOperator
,LongEMAOperator
,LongFillByOperator
,LongRecordingUpdateByOperator
,ObjectFillByOperator
,ShortCumMinMaxOperator
,ShortCumProdOperator
,ShortCumSumOperator
,ShortDeltaOperator
,ShortEMAOperator
,ShortFillByOperator
public interface UpdateByOperator
An operator that performs a specific computation for
Table.updateBy(com.illumon.iris.db.v2.updateby.UpdateByControl, java.util.Collection<com.illumon.iris.db.v2.updateby.UpdateByClause>, com.illumon.iris.db.tables.select.MatchPair...)
. When adding implementations
of this interface, the pattern of calls will be as follows.
- Removes
- Shifts
- Modifies
- Adds
- Reprocess
Additionally, implementations are responsible for notifying the update model if any rows
have been modified beyond what was passed through in the upstream update via the
anyModified(UpdateContext)
and getAdditionalModifications(UpdateContext)
methods
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A context item for use withTable.updateBy(UpdateByControl, Collection, MatchPair...)
for non-bucketed updates. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChunk
(UpdateByOperator.UpdateContext context, Chunk<Attributes.Values> values, LongChunk<? extends Attributes.KeyIndices> keyChunk, IntChunk<Attributes.KeyIndices> bucketPositions, IntChunk<Attributes.ChunkPositions> startPositions, IntChunk<Attributes.ChunkLengths> runLengths) Add a chunk of bucketed items to the operation.void
addChunk
(UpdateByOperator.UpdateContext context, OrderedKeys inputKeys, LongChunk<Attributes.OrderedKeyIndices> keyChunk, Chunk<Attributes.Values> values, long bucketPosition) Add a chunk of non-bucketed items to the operation.boolean
Check if the update has modified any rows for this operator.void
applyOutputShift
(UpdateByOperator.UpdateContext context, ReadOnlyIndex subIndexToShift, long delta) Apply a shift to the operation.void
applyShift
(UpdateByOperator.UpdateContext context, ReadOnlyIndex prevIndex, IndexShiftData shifted) Apply a shift to the operation.boolean
Query if this operator can process the update normally, or if it can only reprocess.static long
determineSmallestVisitedKey
(ShiftAwareListener.Update upstream, ReadOnlyIndex affected) Find the smallest valued key that participated in the upstreamShiftAwareListener.Update
.static long
determineSmallestVisitedKey
(ReadOnlyIndex added, ReadOnlyIndex modified, ReadOnlyIndex removed, IndexShiftData shifted, ReadOnlyIndex affectedIndex) Find the smallest valued key that participated in the upstreamShiftAwareListener.Update
.void
finishFor
(UpdateByOperator.UpdateContext context, UpdateBy.UpdateType type) Perform and bookkeeping required at the end of a single part of the update.Get an index of rows that were modified beyond the input set of modifications from the upstream.String[]
Get an array of column names that, when modified, affect the result of this computation.Get the name of the input column this operator depends on.String[]
Get an array of the output column names.Map<String,
ColumnSource<?>> Get a map of outputName to outputColumnSource
for this operation.void
initializeFor
(UpdateByOperator.UpdateContext context, ReadOnlyIndex updateIndex, UpdateBy.UpdateType type) Initialize the context for the specified stage of the update process.void
initializeForUpdate
(UpdateByOperator.UpdateContext context, ShiftAwareListener.Update upstream, ReadOnlyIndex resultSourceIndex, boolean usingBuckets, boolean isUpstreamAppendOnly) Initialize the operator for an update cycle.static boolean
isAppendOnly
(ShiftAwareListener.Update update, long lastKnownKey) Check if the specifiedShiftAwareListener.Update
was append-only given the last known key within some other index.makeUpdateContext
(int chunkSize) Make anUpdateByOperator.UpdateContext
suitable for use with non-bucketed updates.void
modifyChunk
(UpdateByOperator.UpdateContext context, LongChunk<Attributes.OrderedKeyIndices> prevKeyChunk, LongChunk<Attributes.OrderedKeyIndices> keyChunk, Chunk<Attributes.Values> prevValuesChunk, Chunk<Attributes.Values> postValuesChunk, long bucketPosition) Modify a chunk of values with the operation.void
onBucketsRemoved
(ReadOnlyIndex removedBuckets) Called when some buckets have been completely emptied.void
removeChunk
(UpdateByOperator.UpdateContext context, LongChunk<Attributes.OrderedKeyIndices> keyChunk, Chunk<Attributes.Values> prevValuesChunk, long bucketPosition) Remove a chunk of values from the operation.void
reprocessChunk
(UpdateByOperator.UpdateContext context, OrderedKeys inputKeys, Chunk<Attributes.Values> values, LongChunk<? extends Attributes.KeyIndices> keyChunk, IntChunk<Attributes.KeyIndices> bucketPositions, IntChunk<Attributes.ChunkPositions> runStartPositions, IntChunk<Attributes.ChunkLengths> runLengths) Reprocess a chunk of data for a bucketed table.void
reprocessChunk
(UpdateByOperator.UpdateContext context, OrderedKeys inputKeys, LongChunk<Attributes.OrderedKeyIndices> keyChunk, Chunk<Attributes.Values> valuesChunk, ReadOnlyIndex postUpdateSourceIndex) Reprocess a chunk of data for a non-bucketed table.boolean
Query if the operator requires key values for the current stage.boolean
Query if the operator requires values for the current stage.void
resetForReprocess
(UpdateByOperator.UpdateContext context, ReadOnlyIndex sourceIndex, ColumnSource<?> inputSource, long firstUnmodifiedKey) Reset the operator to the state at the `firstModifiedKey` for non-bucketed operation.void
resetForReprocess
(UpdateByOperator.UpdateContext context, ReadOnlyIndex bucketIndex, ColumnSource<?> inputSource, long bucketPosition, long firstUnmodifiedKey) Reset the operator to the state at the `firstModifiedKey` for the specified bucket.void
setBucketCapacity
(int capacity) Notify the operator of the current maximum bucket.void
setChunkSize
(UpdateByOperator.UpdateContext context, int chunkSize) Set the chunk size to be used for operations.void
Indicate that the operation should start tracking previous values for ticking updates.
-
Field Details
-
ZERO_LENGTH_OP_ARRAY
-
-
Method Details
-
isAppendOnly
Check if the specifiedShiftAwareListener.Update
was append-only given the last known key within some other index.- Parameters:
update
- the update to checklastKnownKey
- the last known key from some other index.- Returns:
- if the update was append-only given the last known key
-
determineSmallestVisitedKey
static long determineSmallestVisitedKey(@NotNull ShiftAwareListener.Update upstream, @NotNull ReadOnlyIndex affected) Find the smallest valued key that participated in the upstreamShiftAwareListener.Update
.- Parameters:
upstream
- the update- Returns:
- the smallest key that participated in any part of the update.
-
determineSmallestVisitedKey
static long determineSmallestVisitedKey(@NotNull ReadOnlyIndex added, @NotNull ReadOnlyIndex modified, @NotNull ReadOnlyIndex removed, @NotNull IndexShiftData shifted, @NotNull ReadOnlyIndex affectedIndex) Find the smallest valued key that participated in the upstreamShiftAwareListener.Update
.- Parameters:
added
- the added rowsmodified
- the modified rowsremoved
- the removed rowsshifted
- the shifted rows- Returns:
- the smallest key that participated in any part of the update.
-
setBucketCapacity
void setBucketCapacity(int capacity) Notify the operator of the current maximum bucket.- Parameters:
capacity
- the capacity
-
getInputColumnName
Get the name of the input column this operator depends on.- Returns:
- the name of the input column
-
getAffectingColumnNames
Get an array of column names that, when modified, affect the result of this computation.- Returns:
- an array of column names that affect this operator.
-
getOutputColumnNames
Get an array of the output column names.- Returns:
- the output column names.
-
getOutputColumns
Get a map of outputName to outputColumnSource
for this operation.- Returns:
- a map of output column name to output column source
-
startTrackingPrev
void startTrackingPrev()Indicate that the operation should start tracking previous values for ticking updates. -
makeUpdateContext
Make anUpdateByOperator.UpdateContext
suitable for use with non-bucketed updates.- Parameters:
chunkSize
- The expected size of chunks that will be provided during the update,- Returns:
- a new context
-
initializeForUpdate
void initializeForUpdate(@NotNull UpdateByOperator.UpdateContext context, @NotNull ShiftAwareListener.Update upstream, @NotNull ReadOnlyIndex resultSourceIndex, boolean usingBuckets, boolean isUpstreamAppendOnly) Initialize the operator for an update cycle. This is invoked before any other update processing occurs.- Parameters:
context
- the context objectupstream
- the upstream update to processresultSourceIndex
- the result index of the source tableusingBuckets
- if the update is bucketed or notisUpstreamAppendOnly
- if the upstream update was detected to be append-only.
-
initializeFor
void initializeFor(@NotNull UpdateByOperator.UpdateContext context, @NotNull ReadOnlyIndex updateIndex, @NotNull UpdateBy.UpdateType type) Initialize the context for the specified stage of the update process. This will always be followed by a call to
finishFor(UpdateContext, UpdateType)
at the end of each successful update.- Parameters:
context
- the context objectupdateIndex
- the index of rows associated with the update.type
- the type of update being applied
-
finishFor
Perform and bookkeeping required at the end of a single part of the update. This is always preceded with a call toinitializeFor(UpdateContext, ReadOnlyIndex, UpdateType)
- Parameters:
context
- the context objecttype
- the type of update being applied
-
getAdditionalModifications
Get an index of rows that were modified beyond the input set of modifications from the upstream. This is invoked once at the end of a complete update cycle (that is, after all adds, removes, modifies and shifts have been processed) ifanyModified(UpdateContext)
has returned true.- Parameters:
context
- the context object- Returns:
- a
index
of additional rows that were modified
-
anyModified
Check if the update has modified any rows for this operator. This is invoked once at the end of a complete update cycle (that is, after all adds, removes, modifies and shifts have been processed).- Parameters:
context
- the context object- Returns:
- true if the update modified any rows.
-
requiresKeys
boolean requiresKeys()Query if the operator requires key values for the current stage. This method will always be invoked after an appropriate invocation ofinitializeFor(UpdateContext, ReadOnlyIndex, UpdateType)
- Returns:
- true if the operator requires keys for this operation
-
requiresValues
Query if the operator requires values for the current stage.- Parameters:
context
- the context object- Returns:
- true if values are required for compuitation
-
canProcessNormalUpdate
Query if this operator can process the update normally, or if it can only reprocess. This method is guaranteed to be invoked afterinitializeForUpdate(UpdateContext, ShiftAwareListener.Update, ReadOnlyIndex, boolean, boolean)
so the operator is aware of the upstreamShiftAwareListener.Update
.- Parameters:
context
- the context- Returns:
- true if this operator can process the update normally.
-
setChunkSize
Set the chunk size to be used for operations. This is used during theUpdateBy.UpdateType.Reprocess
phase when the chunks allocated during the normal processing phase may not be large enough.- Parameters:
context
- the context objectchunkSize
- the new chunk size
-
onBucketsRemoved
Called when some buckets have been completely emptied. Operators can use this to reset internal states.- Parameters:
removedBuckets
- an index of removed bucket positions.
-
addChunk
void addChunk(@NotNull UpdateByOperator.UpdateContext context, @NotNull OrderedKeys inputKeys, @Nullable LongChunk<Attributes.OrderedKeyIndices> keyChunk, @NotNull Chunk<Attributes.Values> values, long bucketPosition) Add a chunk of non-bucketed items to the operation.- Parameters:
context
- the context objectkeyChunk
- a chunk of keys for the rows being added. If the operator returnsfalse
forrequiresKeys()
this will be null.values
- the chunk of values for the rows being addedbucketPosition
- the group position
-
addChunk
void addChunk(@NotNull UpdateByOperator.UpdateContext context, @NotNull Chunk<Attributes.Values> values, @NotNull LongChunk<? extends Attributes.KeyIndices> keyChunk, @NotNull IntChunk<Attributes.KeyIndices> bucketPositions, @NotNull IntChunk<Attributes.ChunkPositions> startPositions, @NotNull IntChunk<Attributes.ChunkLengths> runLengths) Add a chunk of bucketed items to the operation.- Parameters:
context
- the context objectvalues
- the value chunkkeyChunk
- a chunk of keys for the rows being addedbucketPositions
- a chunk of hash bucket positions for each keyrunLengths
- the runLengths of each run of bucket valuesstartPositions
- the start position of a run within the chunk
-
modifyChunk
void modifyChunk(@NotNull UpdateByOperator.UpdateContext context, @Nullable LongChunk<Attributes.OrderedKeyIndices> prevKeyChunk, @Nullable LongChunk<Attributes.OrderedKeyIndices> keyChunk, @NotNull Chunk<Attributes.Values> prevValuesChunk, @NotNull Chunk<Attributes.Values> postValuesChunk, long bucketPosition) Modify a chunk of values with the operation.- Parameters:
context
- the context objectprevKeyChunk
- a chunk of pre-shift keys. This will be equal tokeyChunk
if no shift is presentkeyChunk
- a chunk of post-shift space keys for the update.prevValuesChunk
- a chunk of previous values for the updatepostValuesChunk
- a chunk of current values for the updatebucketPosition
- the position of the current group being processed
-
removeChunk
void removeChunk(@NotNull UpdateByOperator.UpdateContext context, @Nullable LongChunk<Attributes.OrderedKeyIndices> keyChunk, @NotNull Chunk<Attributes.Values> prevValuesChunk, long bucketPosition) Remove a chunk of values from the operation.- Parameters:
context
- the context objectkeyChunk
- a chunk of keys being removed.prevValuesChunk
- the chunk of values being removedbucketPosition
- the position of the current group being processed
-
applyShift
void applyShift(@NotNull UpdateByOperator.UpdateContext context, @NotNull ReadOnlyIndex prevIndex, @NotNull IndexShiftData shifted) Apply a shift to the operation.- Parameters:
context
- the context objectprevIndex
- the pre-shifted indexshifted
- the shifts being applied
-
applyOutputShift
void applyOutputShift(@NotNull UpdateByOperator.UpdateContext context, @NotNull ReadOnlyIndex subIndexToShift, long delta) Apply a shift to the operation.- Parameters:
context
- the context object
-
reprocessChunk
void reprocessChunk(@NotNull UpdateByOperator.UpdateContext context, @NotNull OrderedKeys inputKeys, @Nullable LongChunk<Attributes.OrderedKeyIndices> keyChunk, @NotNull Chunk<Attributes.Values> valuesChunk, @NotNull ReadOnlyIndex postUpdateSourceIndex) Reprocess a chunk of data for a non-bucketed table.- Parameters:
context
- the context objectinputKeys
- the keys contained in the chunkkeyChunk
- aLongChunk
containing the keys if requested byrequiresKeys()
or null.valuesChunk
- the current chunk of working values.postUpdateSourceIndex
- the resulting source index af
-
reprocessChunk
void reprocessChunk(@NotNull UpdateByOperator.UpdateContext context, @NotNull OrderedKeys inputKeys, @NotNull Chunk<Attributes.Values> values, @NotNull LongChunk<? extends Attributes.KeyIndices> keyChunk, @NotNull IntChunk<Attributes.KeyIndices> bucketPositions, @NotNull IntChunk<Attributes.ChunkPositions> runStartPositions, @NotNull IntChunk<Attributes.ChunkLengths> runLengths) Reprocess a chunk of data for a bucketed table.- Parameters:
context
- the context objectinputKeys
- the keys contained in the chunkvalues
- the current chunk of working values.keyChunk
- aLongChunk
containing the keys.bucketPositions
- aIntChunk
containing the bucket position of each key. Parallel to `keyChunk` and `valuesrunStartPositions
- the starting positions of each run within the key and value chunkrunLengths
- the run runLengths of each run in the key and value chunks. Parallel to `runStartPositions`
-
resetForReprocess
void resetForReprocess(@NotNull UpdateByOperator.UpdateContext context, @NotNull ReadOnlyIndex sourceIndex, @NotNull ColumnSource<?> inputSource, long firstUnmodifiedKey) Reset the operator to the state at the `firstModifiedKey` for non-bucketed operation. This is invoked immediately prior to calls toreprocessChunk(UpdateContext, OrderedKeys, LongChunk, Chunk, ReadOnlyIndex)
.
A `firstUnmodifiedKey` ofReadOnlyIndex.NULL_KEY
indicates that the entire table needs to be recomputed.- Parameters:
context
- the context objectsourceIndex
- the current index of the source tableinputSource
- the most primitive form of the input column sourcefirstUnmodifiedKey
- the first unmodified key after which we will reprocess rows.
-
resetForReprocess
void resetForReprocess(@NotNull UpdateByOperator.UpdateContext context, @NotNull ReadOnlyIndex bucketIndex, @NotNull ColumnSource<?> inputSource, long bucketPosition, long firstUnmodifiedKey) Reset the operator to the state at the `firstModifiedKey` for the specified bucket. This is invoked immediately prior to calls toreprocessChunk(UpdateContext, OrderedKeys, Chunk, LongChunk, IntChunk, IntChunk, IntChunk)
.- Parameters:
context
- the context objectbucketIndex
- the current index of the specified bucketinputSource
- the most primitive form of the input column sourcefirstUnmodifiedKey
- the first unmodified key in the bucket after which we will reprocess rows.
-