Package org.apache.cassandra.db.view
Class View
- java.lang.Object
-
- org.apache.cassandra.db.view.View
-
public class View extends java.lang.ObjectA View copies data from a base table into a view table which can be queried independently from the base. Every update which targets the base table must be fed through theViewManagerto ensure that if a view needs to be updated, the updates are properly created and fed into the view.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.List<ColumnMetadata>baseNonPKColumnsInViewPKjava.lang.Stringnamestatic java.lang.StringUSAGE_WARNING
-
Constructor Summary
Constructors Constructor Description View(ViewMetadata definition, ColumnFamilyStore baseCfs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuild()booleanenforceStrictLiveness()When views contains a primary key column that is not part of the base table primary key, we use that column liveness info as the view PK, to ensure that whenever that column is not live in the base, the row is not live in the view.static java.lang.Iterable<ViewMetadata>findAll(java.lang.String keyspace, java.lang.String baseTable)static TableMetadataReffindBaseTable(java.lang.String keyspace, java.lang.String viewName)ColumnMetadatagetBaseColumn(ColumnMetadata viewColumn)The base column corresponding to the provided view column.ViewMetadatagetDefinition()ColumnMetadatagetViewColumn(ColumnMetadata baseColumn)The view column corresponding to the provided base column.booleanhasSamePrimaryKeyColumnsAsBaseTable()booleanmatchesViewFilter(DecoratedKey partitionKey, Row baseRow, int nowInSec)Whether a given base row matches the view filter (and thus if is should have a corresponding entry).booleanmayBeAffectedBy(DecoratedKey partitionKey, Row update)Whether the view might be affected by the provided update.voidupdateDefinition(ViewMetadata definition)This updates the columns stored which are dependent on the base TableMetadata.
-
-
-
Field Detail
-
USAGE_WARNING
public static final java.lang.String USAGE_WARNING
- See Also:
- Constant Field Values
-
name
public final java.lang.String name
-
baseNonPKColumnsInViewPK
public volatile java.util.List<ColumnMetadata> baseNonPKColumnsInViewPK
-
-
Constructor Detail
-
View
public View(ViewMetadata definition, ColumnFamilyStore baseCfs)
-
-
Method Detail
-
getDefinition
public ViewMetadata getDefinition()
-
updateDefinition
public void updateDefinition(ViewMetadata definition)
This updates the columns stored which are dependent on the base TableMetadata.
-
getViewColumn
public ColumnMetadata getViewColumn(ColumnMetadata baseColumn)
The view column corresponding to the provided base column. This can returnnullif the column is denormalized in the view.
-
getBaseColumn
public ColumnMetadata getBaseColumn(ColumnMetadata viewColumn)
The base column corresponding to the provided view column. This should never returnnullsince a view can't have its "own" columns.
-
mayBeAffectedBy
public boolean mayBeAffectedBy(DecoratedKey partitionKey, Row update)
Whether the view might be affected by the provided update.Note that having this method return
trueis not an absolute guarantee that the view will be updated, just that it most likely will, but afalsereturn guarantees it won't be affected).- Parameters:
partitionKey- the partition key that is updated.update- the update being applied.- Returns:
falseif we can guarantee that insertingupdatefor keypartitionKeywon't affect the view in any way,trueotherwise.
-
matchesViewFilter
public boolean matchesViewFilter(DecoratedKey partitionKey, Row baseRow, int nowInSec)
Whether a given base row matches the view filter (and thus if is should have a corresponding entry).Note that this differs from
mayBeAffectedBy(org.apache.cassandra.db.DecoratedKey, org.apache.cassandra.db.rows.Row)in that the provide row must be the current state of the base row, not just some updates to it. This method also has no false positive: a base row either do or don't match the view filter.- Parameters:
partitionKey- the partition key that is updated.baseRow- the current state of a particular base row.nowInSec- the current time in seconds (to decide what is live and what isn't).- Returns:
trueifbaseRowmatches the view filters,falseotherwise.
-
build
public void build()
-
findBaseTable
@Nullable public static TableMetadataRef findBaseTable(java.lang.String keyspace, java.lang.String viewName)
-
findAll
public static java.lang.Iterable<ViewMetadata> findAll(java.lang.String keyspace, java.lang.String baseTable)
-
hasSamePrimaryKeyColumnsAsBaseTable
public boolean hasSamePrimaryKeyColumnsAsBaseTable()
-
enforceStrictLiveness
public boolean enforceStrictLiveness()
When views contains a primary key column that is not part of the base table primary key, we use that column liveness info as the view PK, to ensure that whenever that column is not live in the base, the row is not live in the view. This is done to prevent cells other than the view PK from making the view row alive when the view PK column is not live in the base. So in this case we tie the row liveness, to the primary key liveness. See CASSANDRA-11500 for context.
-
-