Package org.apache.cassandra.db.view
Class View
- java.lang.Object
-
- org.apache.cassandra.db.view.View
-
public class View extends java.lang.Object
A 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 theViewManager
to 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>
baseNonPKColumnsInViewPK
java.lang.String
name
static java.lang.String
USAGE_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 void
build()
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.static java.lang.Iterable<ViewMetadata>
findAll(java.lang.String keyspace, java.lang.String baseTable)
static TableMetadataRef
findBaseTable(java.lang.String keyspace, java.lang.String viewName)
ColumnMetadata
getBaseColumn(ColumnMetadata viewColumn)
The base column corresponding to the provided view column.ViewMetadata
getDefinition()
ColumnMetadata
getViewColumn(ColumnMetadata baseColumn)
The view column corresponding to the provided base column.boolean
hasSamePrimaryKeyColumnsAsBaseTable()
boolean
matchesViewFilter(DecoratedKey partitionKey, Row baseRow, long nowInSec)
Whether a given base row matches the view filter (and thus if is should have a corresponding entry).boolean
mayBeAffectedBy(DecoratedKey partitionKey, Row update)
Whether the view might be affected by the provided update.void
updateDefinition(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 returnnull
if 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 returnnull
since 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
true
is not an absolute guarantee that the view will be updated, just that it most likely will, but afalse
return guarantees it won't be affected).- Parameters:
partitionKey
- the partition key that is updated.update
- the update being applied.- Returns:
false
if we can guarantee that insertingupdate
for keypartitionKey
won't affect the view in any way,true
otherwise.
-
matchesViewFilter
public boolean matchesViewFilter(DecoratedKey partitionKey, Row baseRow, long 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:
true
ifbaseRow
matches the view filters,false
otherwise.
-
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.
-
-