Class BTreeRow
- java.lang.Object
-
- org.apache.cassandra.db.rows.AbstractRow
-
- org.apache.cassandra.db.rows.BTreeRow
-
- All Implemented Interfaces:
java.lang.Iterable<ColumnData>,IMeasurableMemory,Clusterable,Row,Unfiltered
public class BTreeRow extends AbstractRow
Immutable implementation of a Row object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBTreeRow.Builder-
Nested classes/interfaces inherited from interface org.apache.cassandra.db.rows.Row
Row.Deletion, Row.Merger, Row.SimpleBuilder
-
Nested classes/interfaces inherited from interface org.apache.cassandra.db.rows.Unfiltered
Unfiltered.Kind
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <A> longaccumulate(BiLongAccumulator<A,ColumnData> accumulator, A arg, long initialValue)<A> longaccumulate(BiLongAccumulator<A,ColumnData> accumulator, A arg, java.util.Comparator<ColumnData> comparator, ColumnData from, long initialValue)longaccumulate(LongAccumulator<ColumnData> accumulator, long initialValue)Apply an accumulation funtion to every column in a rowlongaccumulate(LongAccumulator<ColumnData> accumulator, java.util.Comparator<ColumnData> comparator, ColumnData from, long initialValue)<A> voidapply(java.util.function.BiConsumer<A,ColumnData> function, A arg)Apply a function to every column in a rowvoidapply(java.util.function.Consumer<ColumnData> function)Apply a function to every column in a rowjava.lang.Iterable<Cell<?>>cells()An iterable over the cells of this row.java.lang.Iterable<Cell<?>>cellsInLegacyOrder(TableMetadata metadata, boolean reversed)An iterable over the cells of this row that return cells in "legacy order".Rowclone(Cloner cloner)Clustering<?>clustering()The clustering values for this row.intcolumnCount()The number of columns for which data (incl.java.util.Collection<ColumnData>columnData()A collection of the ColumnData representation of this row, for columns with some data (possibly not live) presentjava.util.Collection<ColumnMetadata>columns()An in-natural-order collection of the columns for which data (incl.static BTreeRowcreate(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo, Row.Deletion deletion, java.lang.Object[] btree)static BTreeRowcreate(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo, Row.Deletion deletion, java.lang.Object[] btree, int minDeletionTime)intdataSize()Row.Deletiondeletion()The row deletion.static BTreeRowemptyDeletedRow(Clustering<?> clustering, Row.Deletion deletion)static BTreeRowemptyRow(Clustering<?> clustering)Rowfilter(ColumnFilter filter, DeletionTime activeDeletion, boolean setActiveDeletionToRow, TableMetadata metadata)Returns a copy of this row that: 1) only includes the data for the column included byfilter.Rowfilter(ColumnFilter filter, TableMetadata metadata)Returns a copy of this row that: 1) only includes the data for the column included byfilter.Cell<?>getCell(ColumnMetadata c)Returns a cell for a simple column.Cell<?>getCell(ColumnMetadata c, CellPath path)Return a cell for a given complex column and cell path.ColumnDatagetColumnData(ColumnMetadata c)The data for a regular or complex column.ComplexColumnDatagetComplexColumnData(ColumnMetadata c)The data for a complex column.booleanhasComplex()Whether the row stores any (non-RT) data for any complex column.booleanhasComplexDeletion()Whether the row stores any (non-live) complex deletion for any complex column.booleanhasDeletion(int nowInSec)Whether the row has any deletion info (row deletion, cell tombstone, expired cell or complex deletion).booleanhasInvalidDeletions()Do a quick validation of the deletions of the unfiltered (if any)booleanisEmpty()Whether the row has no information whatsoever.java.util.Iterator<ColumnData>iterator()RowmarkCounterLocalToBeCleared()Returns a copy of this row where all counter cells have they "local" shard marked for clearing.static Rowmerge(BTreeRow existing, BTreeRow update, ColumnData.PostReconciliationFunction reconcileF)static BTreeRownoCellLiveRow(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo)LivenessInfoprimaryKeyLivenessInfo()Liveness information for the primary key columns of this row.Rowpurge(DeletionPurger purger, int nowInSec, boolean enforceStrictLiveness)Returns a copy of this row without any deletion info that should be purged according topurger.RowpurgeDataOlderThan(long timestamp, boolean enforceStrictLiveness)BTreeSearchIterator<ColumnMetadata,ColumnData>searchIterator()An iterator to efficiently search data for a given column.voidsetValue(ColumnMetadata column, CellPath path, java.nio.ByteBuffer value)static BTreeRowsingleCellRow(Clustering<?> clustering, Cell<?> cell)static Row.BuildersortedBuilder()Rowtransform(java.util.function.Function<ColumnData,ColumnData> function)RowtransformAndFilter(java.util.function.Function<ColumnData,ColumnData> function)Requires thatfunctionreturns eithernullorColumnDatafor the same column.RowtransformAndFilter(LivenessInfo info, Row.Deletion deletion, java.util.function.Function<ColumnData,ColumnData> function)Requires thatfunctionreturns eithernullorColumnDatafor the same column.longunsharedHeapSize()longunsharedHeapSizeExcludingData()static Row.BuilderunsortedBuilder()RowupdateAllTimestamp(long newTimestamp)Returns a copy of the row where all timestamps for live data have replaced bynewTimestampand all deletion timestamp bynewTimestamp - 1.RowwithOnlyQueriedData(ColumnFilter filter)Returns a copy of this row which only include the data queried byfilter, excluding anything _fetched_ for internal reasons but not queried by the user (seeColumnFilterfor details).RowwithRowDeletion(DeletionTime newDeletion)Returns a copy of this row with the new deletion as row deletion if it is more recent than the current row deletion.-
Methods inherited from class org.apache.cassandra.db.rows.AbstractRow
digest, equals, hashCode, hasLiveData, isStatic, kind, toString, toString, toString, toString, validateData
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.db.rows.Unfiltered
isRangeTombstoneMarker, isRow
-
-
-
-
Method Detail
-
create
public static BTreeRow create(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo, Row.Deletion deletion, java.lang.Object[] btree)
-
create
public static BTreeRow create(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo, Row.Deletion deletion, java.lang.Object[] btree, int minDeletionTime)
-
emptyRow
public static BTreeRow emptyRow(Clustering<?> clustering)
-
singleCellRow
public static BTreeRow singleCellRow(Clustering<?> clustering, Cell<?> cell)
-
emptyDeletedRow
public static BTreeRow emptyDeletedRow(Clustering<?> clustering, Row.Deletion deletion)
-
noCellLiveRow
public static BTreeRow noCellLiveRow(Clustering<?> clustering, LivenessInfo primaryKeyLivenessInfo)
-
apply
public void apply(java.util.function.Consumer<ColumnData> function)
Description copied from interface:RowApply a function to every column in a row
-
apply
public <A> void apply(java.util.function.BiConsumer<A,ColumnData> function, A arg)
Description copied from interface:RowApply a function to every column in a row
-
accumulate
public long accumulate(LongAccumulator<ColumnData> accumulator, long initialValue)
Description copied from interface:RowApply an accumulation funtion to every column in a row
-
accumulate
public long accumulate(LongAccumulator<ColumnData> accumulator, java.util.Comparator<ColumnData> comparator, ColumnData from, long initialValue)
-
accumulate
public <A> long accumulate(BiLongAccumulator<A,ColumnData> accumulator, A arg, long initialValue)
-
accumulate
public <A> long accumulate(BiLongAccumulator<A,ColumnData> accumulator, A arg, java.util.Comparator<ColumnData> comparator, ColumnData from, long initialValue)
-
clustering
public Clustering<?> clustering()
Description copied from interface:RowThe clustering values for this row.
-
columns
public java.util.Collection<ColumnMetadata> columns()
Description copied from interface:RowAn in-natural-order collection of the columns for which data (incl. simple tombstones) is present in this row.
-
columnCount
public int columnCount()
Description copied from interface:RowThe number of columns for which data (incl. simple tombstones) is present in this row.
-
primaryKeyLivenessInfo
public LivenessInfo primaryKeyLivenessInfo()
Description copied from interface:RowLiveness information for the primary key columns of this row.As a row is uniquely identified by its primary key, all its primary key columns share the same
LivenessInfo. This liveness information is what allows us to distinguish between a dead row (it has no live cells and its primary key liveness info is empty) and a live row but where all non PK columns are null (it has no live cells, but its primary key liveness is not empty). Please note that the liveness info (including it's eventually ttl/local deletion time) only apply to the primary key columns and has no impact on the row content.Note in particular that a row may have live cells but no PK liveness info, because the primary key liveness informations are only set on
INSERT(which makes sense in itself, see #6782) but live cells can be added throughUPDATEeven if the row wasn't pre-existing (which users are encouraged not to do, but we can't validate).
-
isEmpty
public boolean isEmpty()
Description copied from interface:RowWhether the row has no information whatsoever. This means no PK liveness info, no row deletion, no cells and no complex deletion info.- Returns:
trueif the row has no data,falseotherwise.
-
deletion
public Row.Deletion deletion()
Description copied from interface:RowThe row deletion. This correspond to the last row deletion done on this row.- Returns:
- the row deletion.
-
getCell
public Cell<?> getCell(ColumnMetadata c)
Description copied from interface:RowReturns a cell for a simple column.- Parameters:
c- the simple column for which to fetch the cell.- Returns:
- the corresponding cell or
nullif the row has no such cell.
-
getCell
public Cell<?> getCell(ColumnMetadata c, CellPath path)
Description copied from interface:RowReturn a cell for a given complex column and cell path.- Parameters:
c- the complex column for which to fetch the cell.path- the cell path for which to fetch the cell.- Returns:
- the corresponding cell or
nullif the row has no such cell.
-
getComplexColumnData
public ComplexColumnData getComplexColumnData(ColumnMetadata c)
Description copied from interface:RowThe data for a complex column.The returned object groups all the cells for the column, as well as it's complex deletion (if relevant).
- Parameters:
c- the complex column for which to return the complex data.- Returns:
- the data for
cornullif the row has no data for this column.
-
getColumnData
public ColumnData getColumnData(ColumnMetadata c)
Description copied from interface:RowThe data for a regular or complex column.- Parameters:
c- the column for which to return the complex data.- Returns:
- the data for
cornullif the row has no data for this column.
-
columnData
public java.util.Collection<ColumnData> columnData()
Description copied from interface:RowA collection of the ColumnData representation of this row, for columns with some data (possibly not live) presentThe data is returned in column order.
- Returns:
- a Collection of the non-empty ColumnData for this row.
-
iterator
public java.util.Iterator<ColumnData> iterator()
-
cells
public java.lang.Iterable<Cell<?>> cells()
Description copied from interface:RowAn iterable over the cells of this row.The iterable guarantees that cells are returned in order of
Cell.comparator.- Returns:
- an iterable over the cells of this row.
-
searchIterator
public BTreeSearchIterator<ColumnMetadata,ColumnData> searchIterator()
Description copied from interface:RowAn iterator to efficiently search data for a given column.- Returns:
- a search iterator for the cells of this row.
-
filter
public Row filter(ColumnFilter filter, TableMetadata metadata)
Description copied from interface:RowReturns a copy of this row that: 1) only includes the data for the column included byfilter. 2) doesn't include any data that belongs to a dropped column (recorded inmetadata).
-
filter
public Row filter(ColumnFilter filter, DeletionTime activeDeletion, boolean setActiveDeletionToRow, TableMetadata metadata)
Description copied from interface:RowReturns a copy of this row that: 1) only includes the data for the column included byfilter. 2) doesn't include any data that belongs to a dropped column (recorded inmetadata). 3) doesn't include any data that is shadowed/deleted byactiveDeletion. 4) usesactiveDeletionas row deletion iffsetActiveDeletionToRowandactiveDeletionsupersedes the row deletion.
-
withOnlyQueriedData
public Row withOnlyQueriedData(ColumnFilter filter)
Description copied from interface:RowReturns a copy of this row which only include the data queried byfilter, excluding anything _fetched_ for internal reasons but not queried by the user (seeColumnFilterfor details).- Parameters:
filter- theColumnFilterto use when deciding what is user queried. This should be the filter that was used when querying the row on which this method is called.- Returns:
- the row but with all data that wasn't queried by the user skipped.
-
hasComplex
public boolean hasComplex()
Description copied from interface:RowWhether the row stores any (non-RT) data for any complex column.
-
hasComplexDeletion
public boolean hasComplexDeletion()
Description copied from interface:RowWhether the row stores any (non-live) complex deletion for any complex column.
-
markCounterLocalToBeCleared
public Row markCounterLocalToBeCleared()
Description copied from interface:RowReturns a copy of this row where all counter cells have they "local" shard marked for clearing.
-
hasDeletion
public boolean hasDeletion(int nowInSec)
Description copied from interface:RowWhether the row has any deletion info (row deletion, cell tombstone, expired cell or complex deletion).- Parameters:
nowInSec- the current time in seconds to decid if a cell is expired.
-
hasInvalidDeletions
public boolean hasInvalidDeletions()
Description copied from interface:UnfilteredDo a quick validation of the deletions of the unfiltered (if any)- Specified by:
hasInvalidDeletionsin interfaceUnfiltered- Overrides:
hasInvalidDeletionsin classAbstractRow- Returns:
- true if any deletion is invalid
-
updateAllTimestamp
public Row updateAllTimestamp(long newTimestamp)
Returns a copy of the row where all timestamps for live data have replaced bynewTimestampand all deletion timestamp bynewTimestamp - 1. This exists for the Paxos path, seePartitionUpdate#updateAllTimestampfor additional details.- Parameters:
newTimestamp- the timestamp to use for all live data in the returned row.- See Also:
for why we need this.
-
withRowDeletion
public Row withRowDeletion(DeletionTime newDeletion)
Description copied from interface:RowReturns a copy of this row with the new deletion as row deletion if it is more recent than the current row deletion.WARNING: this method does not check that nothing in the row is shadowed by the provided deletion and if that is the case, the created row will be invalid. It is thus up to the caller to verify that this is not the case and the only reasonable use case of this is probably when the row and the deletion comes from the same
UnfilteredRowIteratorsince that gives use this guarantee.
-
purge
public Row purge(DeletionPurger purger, int nowInSec, boolean enforceStrictLiveness)
Description copied from interface:RowReturns a copy of this row without any deletion info that should be purged according topurger.- Parameters:
purger- theDeletionPurgerto use to decide what can be purged.nowInSec- the current time to decide what is deleted and what isn't (in the case of expired cells).enforceStrictLiveness- whether the row should be purged if there is no PK liveness info, normally retrieved fromTableMetadata.enforceStrictLiveness()When enforceStrictLiveness is set, rows with empty PK liveness info and no row deletion are purged. Currently this is only used by views with normal base column as PK column so updates to other base columns do not make the row live when the PK column is not live. See CASSANDRA-11500.- Returns:
- this row but without any deletion info purged by
purger. If the purged row is empty, returnsnull.
-
purgeDataOlderThan
public Row purgeDataOlderThan(long timestamp, boolean enforceStrictLiveness)
-
transformAndFilter
public Row transformAndFilter(LivenessInfo info, Row.Deletion deletion, java.util.function.Function<ColumnData,ColumnData> function)
Description copied from interface:RowRequires thatfunctionreturns eithernullorColumnDatafor the same column. Returns a copy of this row that: 1)functionhas been applied to the members of 2) doesn't include anynullresults offunction3) has precisely the providedLivenessInfoandDeletion
-
transformAndFilter
public Row transformAndFilter(java.util.function.Function<ColumnData,ColumnData> function)
Description copied from interface:RowRequires thatfunctionreturns eithernullorColumnDatafor the same column. Returns a copy of this row that: 1)functionhas been applied to the members of 2) doesn't include anynullresults offunction
-
transform
public Row transform(java.util.function.Function<ColumnData,ColumnData> function)
-
dataSize
public int dataSize()
-
unsharedHeapSize
public long unsharedHeapSize()
- Returns:
- the amount of on-heap memory retained by the object that might be reclaimed if the object were reclaimed, i.e. it should try to exclude globally cached data where possible, or counting portions of arrays that are referenced by the object but used by other objects only (e.g. slabbed byte-buffers), etc.
-
unsharedHeapSizeExcludingData
public long unsharedHeapSizeExcludingData()
-
sortedBuilder
public static Row.Builder sortedBuilder()
-
unsortedBuilder
public static Row.Builder unsortedBuilder()
-
setValue
public void setValue(ColumnMetadata column, CellPath path, java.nio.ByteBuffer value)
-
cellsInLegacyOrder
public java.lang.Iterable<Cell<?>> cellsInLegacyOrder(TableMetadata metadata, boolean reversed)
Description copied from interface:RowAn iterable over the cells of this row that return cells in "legacy order".In 3.0+, columns are sorted so that all simple columns are before all complex columns. Previously however, the cells where just sorted by the column name. This iterator return cells in that legacy order. It's only ever meaningful for backward/thrift compatibility code.
- Parameters:
metadata- the table this is a row of.reversed- if cells should returned in reverse order.- Returns:
- an iterable over the cells of this row in "legacy order".
-
merge
public static Row merge(BTreeRow existing, BTreeRow update, ColumnData.PostReconciliationFunction reconcileF)
-
-