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 the `ViewManager` to ensure that if a view needs to be updated, the updates are properly created and fed into the view.

### Field Summary

Fields
`java.util.List<ColumnDefinition>` `baseNonPKColumnsInViewPK`
`java.lang.String` `name`

### Constructor Summary

Constructors
Constructor and Description
`View(ViewDefinition definition, ColumnFamilyStore baseCfs)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `build()`
`static java.lang.String` `buildSelectStatement(java.lang.String cfName, java.util.Collection<ColumnDefinition> includedColumns, java.lang.String whereClause)` Builds the string text for a materialized view's SELECT statement.
`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<ViewDefinition>` `findAll(java.lang.String keyspace, java.lang.String baseTable)`
`static CFMetaData` `findBaseTable(java.lang.String keyspace, java.lang.String viewName)`
`ColumnDefinition` `getBaseColumn(ColumnDefinition viewColumn)` The base column corresponding to the provided view column.
`ViewDefinition` `getDefinition()`
`ReadQuery` `getReadQuery()` Returns the ReadQuery used to filter this view.
`SelectStatement` `getSelectStatement()` Returns the SelectStatement used to populate and filter this view.
`ColumnDefinition` `getViewColumn(ColumnDefinition baseColumn)` The view column corresponding to the provided base column.
`boolean` `hasSamePrimaryKeyColumnsAsBaseTable()`
`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).
`boolean` `mayBeAffectedBy(DecoratedKey partitionKey, Row update)` Whether the view might be affected by the provided update.
`static java.lang.String` `relationsToWhereClause(java.util.List<Relation> whereClause)`
`void` `updateDefinition(ViewDefinition definition)` This updates the columns stored which are dependent on the base CFMetaData.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### name

    public final java.lang.String name

#### baseNonPKColumnsInViewPK

    public volatile java.util.List<ColumnDefinition> baseNonPKColumnsInViewPK

### Constructor Detail

#### View

    public View(ViewDefinition definition,
                ColumnFamilyStore baseCfs)

### Method Detail

#### getDefinition

    public ViewDefinition getDefinition()

#### updateDefinition

    public void updateDefinition(ViewDefinition definition)

This updates the columns stored which are dependent on the base CFMetaData.

#### getViewColumn

    public ColumnDefinition getViewColumn(ColumnDefinition baseColumn)

The view column corresponding to the provided base column. This can return `null` if the column is denormalized in the view.

#### getBaseColumn

    public ColumnDefinition getBaseColumn(ColumnDefinition 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,
                                     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:
  `true` if `baseRow` matches the view filters, `false` otherwise.

#### getSelectStatement

    public SelectStatement getSelectStatement()

Returns the SelectStatement used to populate and filter this view. Internal users should access the select statement this way to ensure it has been prepared.

#### getReadQuery

    public ReadQuery getReadQuery()

Returns the ReadQuery used to filter this view. Internal users should access the query this way to ensure it has been prepared.

#### build

    public void build()

#### findBaseTable

    @Nullable
    public static CFMetaData findBaseTable(java.lang.String keyspace,
                                                     java.lang.String viewName)

#### findAll

    public static java.lang.Iterable<ViewDefinition> findAll(java.lang.String keyspace,
                                                             java.lang.String baseTable)

#### buildSelectStatement

    public static java.lang.String buildSelectStatement(java.lang.String cfName,
                                                        java.util.Collection<ColumnDefinition> includedColumns,
                                                        java.lang.String whereClause)

Builds the string text for a materialized view's SELECT statement.

#### relationsToWhereClause

    public static java.lang.String relationsToWhereClause(java.util.List<Relation> whereClause)

#### 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.