Class TableMetadata

java.lang.Object
org.apache.cassandra.schema.TableMetadata
All Implemented Interfaces:
SchemaElement
Direct Known Subclasses:
TableMetadata.CompactTableMetadata

public class TableMetadata extends Object implements SchemaElement
  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static TableMetadata.Builder builder(String keyspace, String table)
    • builder

      public static TableMetadata.Builder builder(String keyspace, String table, TableId id)
    • unbuild

      public TableMetadata.Builder unbuild()
    • isIndex

      public boolean isIndex()
    • withSwapped

      public TableMetadata withSwapped(TableParams params)
    • withSwapped

      public TableMetadata withSwapped(Set<TableMetadata.Flag> flags)
    • withSwapped

      public TableMetadata withSwapped(Triggers triggers)
    • withSwapped

      public TableMetadata withSwapped(Indexes indexes)
    • isView

      public boolean isView()
    • isVirtual

      public boolean isVirtual()
    • indexName

      public Optional<String> indexName()
    • isCounter

      public boolean isCounter()
    • isCompactTable

      public boolean isCompactTable()
    • isIncrementalBackupsEnabled

      public boolean isIncrementalBackupsEnabled()
    • isStaticCompactTable

      public boolean isStaticCompactTable()
    • columns

      public com.google.common.collect.ImmutableCollection<ColumnMetadata> columns()
    • primaryKeyColumns

      public Iterable<ColumnMetadata> primaryKeyColumns()
    • partitionKeyColumns

      public com.google.common.collect.ImmutableList<ColumnMetadata> partitionKeyColumns()
    • clusteringColumns

      public com.google.common.collect.ImmutableList<ColumnMetadata> clusteringColumns()
    • regularAndStaticColumns

      public RegularAndStaticColumns regularAndStaticColumns()
    • regularColumns

      public Columns regularColumns()
    • staticColumns

      public Columns staticColumns()
    • allColumnsInSelectOrder

      public Iterator<ColumnMetadata> allColumnsInSelectOrder()
    • allColumnsInCreateOrder

      public Iterator<ColumnMetadata> allColumnsInCreateOrder()
      Returns an iterator over all column definitions that respect the order of the CREATE statement.
    • getColumn

      public ColumnMetadata getColumn(ColumnIdentifier name)
      Returns the ColumnMetadata for name.
    • getExistingColumn

      public ColumnMetadata getExistingColumn(ColumnIdentifier name)
      Returns the column of the provided name if it exists, but throws a user-visible exception if that column doesn't exist.

      This method is for finding columns from a name provided by the user, and as such it does _not_ returne hidden columns (throwing that the column is unknown instead).

      Parameters:
      name - the name of an existing non-hidden column of this table.
      Returns:
      the column metadata corresponding to name.
      Throws:
      InvalidRequestException - if there is no non-hidden column named name in this table.
    • getColumn

      public ColumnMetadata getColumn(ByteBuffer name)
    • getDroppedColumn

      public ColumnMetadata getDroppedColumn(ByteBuffer name)
    • getDroppedColumn

      public ColumnMetadata getDroppedColumn(ByteBuffer name, boolean isStatic)
      Returns a "fake" ColumnMetadata corresponding to the dropped column name of null if there is no such dropped column.
      Parameters:
      name - - the column name
      isStatic - - whether the column was a static column, if known
    • hasStaticColumns

      public boolean hasStaticColumns()
    • hasMaskedColumns

      public boolean hasMaskedColumns()
      Returns:
      true if the table has any masked column, false otherwise.
    • dependsOn

      public boolean dependsOn(Function function)
      Parameters:
      function - a user function
      Returns:
      true if the table has any masked column depending on the specified user function, false otherwise.
    • validate

      public void validate()
    • validateCompatibility

      public void validateCompatibility(TableMetadata previous)
    • partitionKeyAsClusteringComparator

      public ClusteringComparator partitionKeyAsClusteringComparator()
    • indexTableName

      public String indexTableName(IndexMetadata info)
      Generate a table name for an index corresponding to the given column. This is NOT the same as the index's name! This is only used in sstable filenames and is not exposed to users.
      Parameters:
      info - A definition of the column with index
      Returns:
      name of the index table
    • getTableName

      public String getTableName()
      Returns the table part of the index table name or the entire table name if not an index table.
      Returns:
      table name part
    • getTableDirectoryName

      public String getTableDirectoryName()
      Generates a directory name for the table by using table part of the (index) table name and table id.
      Returns:
      directory name
    • getIndexNameWithDot

      @Nullable public String getIndexNameWithDot()
      Returns the index name from the name of an index table including the dot prefixing the index name, see indexTableName(org.apache.cassandra.schema.IndexMetadata). If not an index table, returns null.
      Returns:
      index name prefixed with dot prefix or null
    • minimal

      public static TableMetadata minimal(String keyspace, String name)
      There is a couple of places in the code where we need a TableMetadata object and don't have one readily available and know that only the keyspace and name matter. This creates such "fake" metadata. Use only if you know what you're doing.
    • updateIndexTableMetadata

      public TableMetadata updateIndexTableMetadata(TableParams baseTableParams)
    • withUpdatedUserType

      public TableMetadata withUpdatedUserType(UserType udt)
    • except

      protected void except(String format, Object... args)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toDebugString

      public String toDebugString()
    • enforceStrictLiveness

      public boolean enforceStrictLiveness()
      A table with strict liveness filters/ignores rows without PK liveness info, effectively tying the row liveness to its primary key liveness. Currently this is only used by views with normal base column as PK column so updates to other columns do not make the row live when the base column is not live. See CASSANDRA-11500. TODO: does not belong here, should be gone
    • getReferencedUserTypes

      public Set<ByteBuffer> getReferencedUserTypes()
      Returns the names of all the user types referenced by this table.
      Returns:
      the names of all the user types referenced by this table.
    • elementType

      public SchemaElement.SchemaElementType elementType()
      Description copied from interface: SchemaElement
      Return the schema element type
      Specified by:
      elementType in interface SchemaElement
      Returns:
      the schema element type
    • elementKeyspace

      public String elementKeyspace()
      Description copied from interface: SchemaElement
      Returns the CQL name of the keyspace to which this schema element belong.
      Specified by:
      elementKeyspace in interface SchemaElement
      Returns:
      the keyspace name.
    • elementName

      public String elementName()
      Description copied from interface: SchemaElement
      Returns the CQL name of this schema element.
      Specified by:
      elementName in interface SchemaElement
      Returns:
      the name of this schema element.
    • toCqlString

      public String toCqlString(boolean withInternals, boolean ifNotExists)
      Description copied from interface: SchemaElement
      Returns a CQL representation of this element
      Specified by:
      toCqlString in interface SchemaElement
      Parameters:
      withInternals - if the internals part of the CQL should be exposed.
      ifNotExists - if "IF NOT EXISTS" should be included.
      Returns:
      a CQL representation of this element
    • toCqlString

      public String toCqlString(boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
    • appendCqlTo

      public void appendCqlTo(CqlBuilder builder, boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
    • partitionKeyAsCQLLiteral

      public String partitionKeyAsCQLLiteral(ByteBuffer partitionKey)
      Returns a string representation of a partition in a CQL-friendly format. For non-composite types it returns the result of CQL3Type.toCQLLiteral(java.nio.ByteBuffer) applied to the partition key. For composite types it applies CQL3Type.toCQLLiteral(java.nio.ByteBuffer) to each subkey and combines the results into a tuple.
      Parameters:
      partitionKey - a partition key
      Returns:
      CQL-like string representation of a partition key
    • primaryKeyAsCQLLiteral

      public String primaryKeyAsCQLLiteral(ByteBuffer partitionKey, Clustering<?> clustering)
      Returns a string representation of a primary key in a CQL-friendly format.
      Parameters:
      partitionKey - the partition key part of the primary key
      clustering - the clustering key part of the primary key
      Returns:
      a CQL-like string representation of the specified primary key