Class View

java.lang.Object
org.apache.cassandra.db.view.View

public class View extends 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 the ViewManager to ensure that if a view needs to be updated, the updates are properly created and fed into the view.
  • Field Details

  • Constructor Details

  • Method Details

    • 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 return null 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 return null 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 a false 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 inserting update for key partitionKey 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 if baseRow matches the view filters, false otherwise.
    • build

      public void build()
    • findBaseTable

      @Nullable public static TableMetadataRef findBaseTable(String keyspace, String viewName)
    • findAll

      public static Iterable<ViewMetadata> findAll(String keyspace, 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.