Package org.apache.cassandra.schema
Class TableMetadata
- java.lang.Object
-
- org.apache.cassandra.schema.TableMetadata
-
- All Implemented Interfaces:
SchemaElement
- Direct Known Subclasses:
TableMetadata.CompactTableMetadata
public class TableMetadata extends java.lang.Object implements SchemaElement
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableMetadata.Builder
static class
TableMetadata.CompactTableMetadata
static class
TableMetadata.Flag
static class
TableMetadata.Kind
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.SchemaElement
SchemaElement.SchemaElementType
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.collect.ImmutableList<ColumnMetadata>
clusteringColumns
ClusteringComparator
comparator
com.google.common.collect.ImmutableMap<java.nio.ByteBuffer,DroppedColumn>
droppedColumns
com.google.common.collect.ImmutableSet<TableMetadata.Flag>
flags
TableId
id
Indexes
indexes
java.lang.String
keyspace
TableMetadata.Kind
kind
java.lang.String
name
TableParams
params
IPartitioner
partitioner
protected com.google.common.collect.ImmutableList<ColumnMetadata>
partitionKeyColumns
AbstractType<?>
partitionKeyType
protected RegularAndStaticColumns
regularAndStaticColumns
DataResource
resource
Triggers
triggers
-
Fields inherited from interface org.apache.cassandra.cql3.SchemaElement
NAME_COMPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TableMetadata(TableMetadata.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<ColumnMetadata>
allColumnsInCreateOrder()
Returns an iterator over all column definitions that respect the order of the CREATE statement.java.util.Iterator<ColumnMetadata>
allColumnsInSelectOrder()
void
appendCqlTo(CqlBuilder builder, boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
static TableMetadata.Builder
builder(java.lang.String keyspace, java.lang.String table)
static TableMetadata.Builder
builder(java.lang.String keyspace, java.lang.String table, TableId id)
com.google.common.collect.ImmutableList<ColumnMetadata>
clusteringColumns()
com.google.common.collect.ImmutableCollection<ColumnMetadata>
columns()
boolean
dependsOn(Function function)
java.lang.String
elementKeyspace()
Returns the CQL name of the keyspace to which this schema element belong.java.lang.String
elementName()
Returns the CQL name of this schema element.SchemaElement.SchemaElementType
elementType()
Return the schema element typeboolean
enforceStrictLiveness()
A table with strict liveness filters/ignores rows without PK liveness info, effectively tying the row liveness to its primary key liveness.boolean
equals(java.lang.Object o)
protected void
except(java.lang.String format, java.lang.Object... args)
ColumnMetadata
getColumn(java.nio.ByteBuffer name)
ColumnMetadata
getColumn(ColumnIdentifier name)
Returns the ColumnMetadata forname
.ColumnMetadata
getDroppedColumn(java.nio.ByteBuffer name)
ColumnMetadata
getDroppedColumn(java.nio.ByteBuffer name, boolean isStatic)
Returns a "fake" ColumnMetadata corresponding to the dropped columnname
ofnull
if there is no such dropped column.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.java.util.Set<java.nio.ByteBuffer>
getReferencedUserTypes()
Returns the names of all the user types referenced by this table.int
hashCode()
boolean
hasMaskedColumns()
boolean
hasStaticColumns()
java.util.Optional<java.lang.String>
indexName()
java.lang.String
indexTableName(IndexMetadata info)
Generate a table name for an index corresponding to the given column.boolean
isCompactTable()
boolean
isCounter()
boolean
isIncrementalBackupsEnabled()
boolean
isIndex()
boolean
isStaticCompactTable()
boolean
isView()
boolean
isVirtual()
static TableMetadata
minimal(java.lang.String keyspace, java.lang.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.ClusteringComparator
partitionKeyAsClusteringComparator()
java.lang.String
partitionKeyAsCQLLiteral(java.nio.ByteBuffer partitionKey)
Returns a string representation of a partition in a CQL-friendly format.com.google.common.collect.ImmutableList<ColumnMetadata>
partitionKeyColumns()
java.lang.String
primaryKeyAsCQLLiteral(java.nio.ByteBuffer partitionKey, Clustering<?> clustering)
Returns a string representation of a primary key in a CQL-friendly format.java.lang.Iterable<ColumnMetadata>
primaryKeyColumns()
RegularAndStaticColumns
regularAndStaticColumns()
Columns
regularColumns()
Columns
staticColumns()
java.lang.String
toCqlString(boolean withInternals, boolean ifNotExists)
Returns a CQL representation of this elementjava.lang.String
toCqlString(boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
java.lang.String
toDebugString()
java.lang.String
toString()
TableMetadata.Builder
unbuild()
TableMetadata
updateIndexTableMetadata(TableParams baseTableParams)
void
validate()
void
validateCompatibility(TableMetadata previous)
TableMetadata
withSwapped(java.util.Set<TableMetadata.Flag> flags)
TableMetadata
withSwapped(Indexes indexes)
TableMetadata
withSwapped(TableParams params)
TableMetadata
withSwapped(Triggers triggers)
TableMetadata
withUpdatedUserType(UserType udt)
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.cql3.SchemaElement
elementKeyspaceQuotedIfNeeded, elementNameQuotedIfNeeded
-
-
-
-
Field Detail
-
keyspace
public final java.lang.String keyspace
-
name
public final java.lang.String name
-
id
public final TableId id
-
partitioner
public final IPartitioner partitioner
-
kind
public final TableMetadata.Kind kind
-
params
public final TableParams params
-
flags
public final com.google.common.collect.ImmutableSet<TableMetadata.Flag> flags
-
droppedColumns
public final com.google.common.collect.ImmutableMap<java.nio.ByteBuffer,DroppedColumn> droppedColumns
-
partitionKeyColumns
protected final com.google.common.collect.ImmutableList<ColumnMetadata> partitionKeyColumns
-
clusteringColumns
protected final com.google.common.collect.ImmutableList<ColumnMetadata> clusteringColumns
-
regularAndStaticColumns
protected final RegularAndStaticColumns regularAndStaticColumns
-
indexes
public final Indexes indexes
-
triggers
public final Triggers triggers
-
partitionKeyType
public final AbstractType<?> partitionKeyType
-
comparator
public final ClusteringComparator comparator
-
resource
public final DataResource resource
-
-
Constructor Detail
-
TableMetadata
protected TableMetadata(TableMetadata.Builder builder)
-
-
Method Detail
-
builder
public static TableMetadata.Builder builder(java.lang.String keyspace, java.lang.String table)
-
builder
public static TableMetadata.Builder builder(java.lang.String keyspace, java.lang.String table, TableId id)
-
unbuild
public TableMetadata.Builder unbuild()
-
isIndex
public boolean isIndex()
-
withSwapped
public TableMetadata withSwapped(TableParams params)
-
withSwapped
public TableMetadata withSwapped(java.util.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 java.util.Optional<java.lang.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 java.lang.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 java.util.Iterator<ColumnMetadata> allColumnsInSelectOrder()
-
allColumnsInCreateOrder
public java.util.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 forname
.
-
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 namedname
in this table.
-
getColumn
public ColumnMetadata getColumn(java.nio.ByteBuffer name)
-
getDroppedColumn
public ColumnMetadata getDroppedColumn(java.nio.ByteBuffer name)
-
getDroppedColumn
public ColumnMetadata getDroppedColumn(java.nio.ByteBuffer name, boolean isStatic)
Returns a "fake" ColumnMetadata corresponding to the dropped columnname
ofnull
if there is no such dropped column.- Parameters:
name
- - the column nameisStatic
- - 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 java.lang.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
-
minimal
public static TableMetadata minimal(java.lang.String keyspace, java.lang.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(java.lang.String format, java.lang.Object... args)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toDebugString
public java.lang.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 java.util.Set<java.nio.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 interfaceSchemaElement
- Returns:
- the schema element type
-
elementKeyspace
public java.lang.String elementKeyspace()
Description copied from interface:SchemaElement
Returns the CQL name of the keyspace to which this schema element belong.- Specified by:
elementKeyspace
in interfaceSchemaElement
- Returns:
- the keyspace name.
-
elementName
public java.lang.String elementName()
Description copied from interface:SchemaElement
Returns the CQL name of this schema element.- Specified by:
elementName
in interfaceSchemaElement
- Returns:
- the name of this schema element.
-
toCqlString
public java.lang.String toCqlString(boolean withInternals, boolean ifNotExists)
Description copied from interface:SchemaElement
Returns a CQL representation of this element- Specified by:
toCqlString
in interfaceSchemaElement
- 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 java.lang.String toCqlString(boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
-
appendCqlTo
public void appendCqlTo(CqlBuilder builder, boolean includeDroppedColumns, boolean withInternals, boolean ifNotExists)
-
partitionKeyAsCQLLiteral
public java.lang.String partitionKeyAsCQLLiteral(java.nio.ByteBuffer partitionKey)
Returns a string representation of a partition in a CQL-friendly format. For non-composite types it returns the result ofCQL3Type.toCQLLiteral(java.nio.ByteBuffer)
applied to the partition key. For composite types it appliesCQL3Type.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 java.lang.String primaryKeyAsCQLLiteral(java.nio.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 keyclustering
- the clustering key part of the primary key- Returns:
- a CQL-like string representation of the specified primary key
-
-