org.apache.cassandra.config

## Class Schema

- java.lang.Object
- - org.apache.cassandra.config.Schema

    public class Schema
    extends java.lang.Object

### Field Summary

Fields
`static Schema` `instance`

### Constructor Summary

Constructors
Constructor and Description
`Schema()` Initialize empty schema object and load the hardcoded system tables

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addAggregate(UDAggregate uda)`
`void` `addFunction(UDFunction udf)`
`void` `addKeyspace(KeyspaceMetadata ksm)`
`void` `addTable(CFMetaData cfm)`
`void` `addType(UserType ut)`
`void` `addView(ViewDefinition view)`
`void` `clear()` Clear all KS/CF metadata and reset version.
`void` `clearKeyspaceMetadata(KeyspaceMetadata ksm)` Remove keyspace definition from system
`void` `dropAggregate(UDAggregate uda)`
`void` `dropFunction(UDFunction udf)`
`void` `dropKeyspace(java.lang.String ksName)`
`void` `dropTable(java.lang.String ksName, java.lang.String tableName)`
`void` `dropType(UserType ut)`
`void` `dropView(java.lang.String ksName, java.lang.String viewName)`
`java.util.Optional<Function>` `findFunction(FunctionName name, java.util.List<AbstractType<?>> argTypes)` Find the function with the specified name
`java.util.UUID` `getAltVersion()` The "alternative" schema version, compatible to 3.0, always excludes the `cdc` column.
`Pair<java.lang.String,java.lang.String>` `getCF(java.util.UUID cfId)`
`CFMetaData` `getCFMetaData(Descriptor descriptor)`
`CFMetaData` `getCFMetaData(java.lang.String keyspaceName, java.lang.String cfName)` Given a keyspace name and column family name, get the column family meta data.
`CFMetaData` `getCFMetaData(java.util.UUID cfId)` Get ColumnFamily metadata by its identifier
`ColumnFamilyStore` `getColumnFamilyStoreIncludingIndexes(Pair<java.lang.String,java.lang.String> ksNameAndCFName)` Retrieve a CFS by name even if that CFS is an index An index is identified by looking for '.' in the CF name and separating to find the base table containing the index
`ColumnFamilyStore` `getColumnFamilyStoreInstance(java.util.UUID cfId)`
`java.util.Collection<Function>` `getFunctions(FunctionName name)` Get all function overloads with the specified name
`java.util.UUID` `getId(java.lang.String ksName, java.lang.String cfName)` Lookup keyspace/ColumnFamily identifier
`Keyspace` `getKeyspaceInstance(java.lang.String keyspaceName)` Get keyspace instance by name
`java.util.Set<java.lang.String>` `getKeyspaces()`
`Keyspaces` `getKeyspaces(java.util.Set<java.lang.String> includedKeyspaceNames)`
`KeyspaceMetadata` `getKSMetaData(java.lang.String keyspaceName)` Get metadata about keyspace by its name
`java.util.List<java.lang.String>` `getNonLocalStrategyKeyspaces()`
`java.util.List<java.lang.String>` `getNonSystemKeyspaces()`
`int` `getNumberOfTables()`
`java.util.UUID` `getRealVersion()` The 3.11 schema version, always includes the `cdc` column.
`Keyspaces` `getReplicatedKeyspaces()`
`java.lang.Iterable<CFMetaData>` `getTablesAndViews(java.lang.String keyspaceName)` Get metadata about keyspace inner ColumnFamilies
`java.util.List<java.lang.String>` `getUserKeyspaces()`
`java.util.UUID` `getVersion()` The schema version to announce.
`ViewDefinition` `getView(java.lang.String keyspaceName, java.lang.String viewName)`
`boolean` `hasCF(Pair<java.lang.String,java.lang.String> ksAndCFName)`
`boolean` `isEmpty()` Checks whether the current schema is empty.
`boolean` `isSameVersion(java.util.UUID schemaVersion)` Checks whether the given schema version is the same as the current local schema version, either the 3.0 compatible or "real" one.
`void` `load(CFMetaData cfm)` Load individual ColumnFamily Definition to the schema (to make ColumnFamily lookup faster)
`Schema` `load(java.lang.Iterable<KeyspaceMetadata> keyspaceDefs)` Load up non-system keyspaces
`Schema` `load(KeyspaceMetadata keyspaceDef)` Load specific keyspace into Schema
`void` `load(ViewDefinition view)` Load individual View Definition to the schema (to make View lookup faster)
`Schema` `loadFromDisk()` load keyspace (keyspace) definitions, but do not initialize the keyspace instances.
`Schema` `loadFromDisk(boolean updateVersion)` Load schema definitions from disk.
`Keyspace` `removeKeyspaceInstance(java.lang.String keyspaceName)` Remove keyspace from schema
`static java.lang.String` `schemaVersionToString(java.util.UUID version)` Converts the given schema version to a string.
`void` `setKeyspaceMetadata(KeyspaceMetadata ksm)` Update (or insert) new keyspace definition
`void` `storeKeyspaceInstance(Keyspace keyspace)` Store given Keyspace instance to the schema
`void` `unload(CFMetaData cfm)` Used for ColumnFamily data eviction out from the schema
`void` `updateAggregate(UDAggregate uda)`
`void` `updateFunction(UDFunction udf)`
`void` `updateKeyspace(java.lang.String ksName, KeyspaceParams newParams)`
`void` `updateTable(CFMetaData table)`
`void` `updateType(UserType ut)`
`void` `updateVersion()` Read schema from system keyspace and calculate MD5 digest of every row, resulting digest will be converted into UUID which would act as content-based version of the schema.
`void` `updateVersionAndAnnounce()` Like updateVersion, but also announces via gossip 3.11 note: we announce the "current" schema version, which can be either the 3.0 compatible one, if at least one node is still running 3.0, or the "real" schema version.
`void` `updateView(ViewDefinition view)`

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

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

### Field Detail

#### instance

    public static final Schema instance

### Constructor Detail

#### Schema

    public Schema()

Initialize empty schema object and load the hardcoded system tables

### Method Detail

#### loadFromDisk

    public Schema loadFromDisk()

load keyspace (keyspace) definitions, but do not initialize the keyspace instances. Schema version may be updated as the result.

#### loadFromDisk

    public Schema loadFromDisk(boolean updateVersion)

Load schema definitions from disk.

Parameters:
  `updateVersion` - true if schema version needs to be updated

#### load

    public Schema load(java.lang.Iterable<KeyspaceMetadata> keyspaceDefs)

Load up non-system keyspaces

Parameters:
  `keyspaceDefs` - The non-system keyspace definitions
Returns:
  self to support chaining calls

#### load

    public Schema load(KeyspaceMetadata keyspaceDef)

Load specific keyspace into Schema

Parameters:
  `keyspaceDef` - The keyspace to load up
Returns:
  self to support chaining calls

#### getKeyspaceInstance

    public Keyspace getKeyspaceInstance(java.lang.String keyspaceName)

Get keyspace instance by name

Parameters:
  `keyspaceName` - The name of the keyspace
Returns:
  Keyspace object or null if keyspace was not found

#### getColumnFamilyStoreIncludingIndexes

    public ColumnFamilyStore getColumnFamilyStoreIncludingIndexes(Pair<java.lang.String,java.lang.String> ksNameAndCFName)

Retrieve a CFS by name even if that CFS is an index An index is identified by looking for '.' in the CF name and separating to find the base table containing the index

Parameters:
  `ksNameAndCFName` -
Returns:
  The named CFS or null if the keyspace, base table, or index don't exist

#### getColumnFamilyStoreInstance

    public ColumnFamilyStore getColumnFamilyStoreInstance(java.util.UUID cfId)

#### storeKeyspaceInstance

    public void storeKeyspaceInstance(Keyspace keyspace)

Store given Keyspace instance to the schema

Parameters:
  `keyspace` - The Keyspace instance to store
Throws:
  `java.lang.IllegalArgumentException` - if Keyspace is already stored

#### removeKeyspaceInstance

    public Keyspace removeKeyspaceInstance(java.lang.String keyspaceName)

Remove keyspace from schema

Parameters:
  `keyspaceName` - The name of the keyspace to remove
Returns:
  removed keyspace instance or null if it wasn't found

#### clearKeyspaceMetadata

    public void clearKeyspaceMetadata(KeyspaceMetadata ksm)

Remove keyspace definition from system

Parameters:
  `ksm` - The keyspace definition to remove

#### getCFMetaData

    public CFMetaData getCFMetaData(java.lang.String keyspaceName,
                                    java.lang.String cfName)

Given a keyspace name and column family name, get the column family meta data. If the keyspace name or column family name is not valid this function returns null.

Parameters:
  `keyspaceName` - The keyspace name
  `cfName` - The ColumnFamily name
Returns:
  ColumnFamily Metadata object or null if it wasn't found

#### getCFMetaData

    public CFMetaData getCFMetaData(java.util.UUID cfId)

Get ColumnFamily metadata by its identifier

Parameters:
  `cfId` - The ColumnFamily identifier
Returns:
  metadata about ColumnFamily

#### getCFMetaData

    public CFMetaData getCFMetaData(Descriptor descriptor)

#### getNumberOfTables

    public int getNumberOfTables()

#### getView

    public ViewDefinition getView(java.lang.String keyspaceName,
                                  java.lang.String viewName)

#### getKSMetaData

    public KeyspaceMetadata getKSMetaData(java.lang.String keyspaceName)

Get metadata about keyspace by its name

Parameters:
  `keyspaceName` - The name of the keyspace
Returns:
  The keyspace metadata or null if it wasn't found

#### getNonSystemKeyspaces

    public java.util.List<java.lang.String> getNonSystemKeyspaces()

Returns:
  collection of the non-system keyspaces (note that this count as system only the non replicated keyspaces, so keyspace like system_traces which are replicated are actually returned. See getUserKeyspace() below if you don't want those)

#### getNonLocalStrategyKeyspaces

    public java.util.List<java.lang.String> getNonLocalStrategyKeyspaces()

Returns:
  a collection of keyspaces that do not use LocalStrategy for replication

#### getUserKeyspaces

    public java.util.List<java.lang.String> getUserKeyspaces()

Returns:
  collection of the user defined keyspaces

#### getReplicatedKeyspaces

    public Keyspaces getReplicatedKeyspaces()

#### getTablesAndViews

    public java.lang.Iterable<CFMetaData> getTablesAndViews(java.lang.String keyspaceName)

Get metadata about keyspace inner ColumnFamilies

Parameters:
  `keyspaceName` - The name of the keyspace
Returns:
  metadata about ColumnFamilies the belong to the given keyspace

#### getKeyspaces

    public java.util.Set<java.lang.String> getKeyspaces()

Returns:
  collection of the all keyspace names registered in the system (system and non-system)

#### getKeyspaces

    public Keyspaces getKeyspaces(java.util.Set<java.lang.String> includedKeyspaceNames)

#### setKeyspaceMetadata

    public void setKeyspaceMetadata(KeyspaceMetadata ksm)

Update (or insert) new keyspace definition

Parameters:
  `ksm` - The metadata about keyspace

#### getCF

    public Pair<java.lang.String,java.lang.String> getCF(java.util.UUID cfId)

Parameters:
  `cfId` - The identifier of the ColumnFamily to lookup
Returns:
  The (ksname,cfname) pair for the given id, or null if it has been dropped.

#### hasCF

    public boolean hasCF(Pair<java.lang.String,java.lang.String> ksAndCFName)

Parameters:
  `ksAndCFName` - The identifier of the ColumnFamily to lookup
Returns:
  true if the KS and CF pair is a known one, false otherwise.

#### getId

    public java.util.UUID getId(java.lang.String ksName,
                                java.lang.String cfName)

Lookup keyspace/ColumnFamily identifier

Parameters:
  `ksName` - The keyspace name
  `cfName` - The ColumnFamily name
Returns:
  The id for the given (ksname,cfname) pair, or null if it has been dropped.

#### load

    public void load(CFMetaData cfm)

Load individual ColumnFamily Definition to the schema (to make ColumnFamily lookup faster)

Parameters:
  `cfm` - The ColumnFamily definition to load

#### load

    public void load(ViewDefinition view)

Load individual View Definition to the schema (to make View lookup faster)

Parameters:
  `view` - The View definition to load

#### unload

    public void unload(CFMetaData cfm)

Used for ColumnFamily data eviction out from the schema

Parameters:
  `cfm` - The ColumnFamily Definition to evict

#### getFunctions

    public java.util.Collection<Function> getFunctions(FunctionName name)

Get all function overloads with the specified name

Parameters:
  `name` - fully qualified function name
Returns:
  an empty list if the keyspace or the function name are not found; a non-empty collection of `Function` otherwise

#### findFunction

    public java.util.Optional<Function> findFunction(FunctionName name,
                                                     java.util.List<AbstractType<?>> argTypes)

Find the function with the specified name

Parameters:
  `name` - fully qualified function name
  `argTypes` - function argument types
Returns:
  an empty `Optional` if the keyspace or the function name are not found; a non-empty optional of `Function` otherwise

#### getVersion

    public java.util.UUID getVersion()

The schema version to announce. This will be either the "real" schema version including the `cdc` column, if no node in the cluster is running at 3.0, or a 3.0 compatible schema version, with the `cdc` column excluded, if at least one node is running 3.0.

Returns:
  "current" schema version

#### getRealVersion

    public java.util.UUID getRealVersion()

The 3.11 schema version, always includes the `cdc` column.

#### getAltVersion

    public java.util.UUID getAltVersion()

The "alternative" schema version, compatible to 3.0, always excludes the `cdc` column.

#### isSameVersion

    public boolean isSameVersion(java.util.UUID schemaVersion)

Checks whether the given schema version is the same as the current local schema version, either the 3.0 compatible or "real" one.

#### isEmpty

    public boolean isEmpty()

Checks whether the current schema is empty.

#### updateVersion

    public void updateVersion()

Read schema from system keyspace and calculate MD5 digest of every row, resulting digest will be converted into UUID which would act as content-based version of the schema. 3.11 note: we calculate the "real" schema version and the 3.0 compatible schema version here.

#### updateVersionAndAnnounce

    public void updateVersionAndAnnounce()

Like updateVersion, but also announces via gossip 3.11 note: we announce the "current" schema version, which can be either the 3.0 compatible one, if at least one node is still running 3.0, or the "real" schema version.

#### clear

    public void clear()

Clear all KS/CF metadata and reset version.

#### addKeyspace

    public void addKeyspace(KeyspaceMetadata ksm)

#### updateKeyspace

    public void updateKeyspace(java.lang.String ksName,
                               KeyspaceParams newParams)

#### dropKeyspace

    public void dropKeyspace(java.lang.String ksName)

#### addTable

    public void addTable(CFMetaData cfm)

#### updateTable

    public void updateTable(CFMetaData table)

#### dropTable

    public void dropTable(java.lang.String ksName,
                          java.lang.String tableName)

#### addView

    public void addView(ViewDefinition view)

#### updateView

    public void updateView(ViewDefinition view)

#### dropView

    public void dropView(java.lang.String ksName,
                         java.lang.String viewName)

#### addType

    public void addType(UserType ut)

#### updateType

    public void updateType(UserType ut)

#### dropType

    public void dropType(UserType ut)

#### addFunction

    public void addFunction(UDFunction udf)

#### updateFunction

    public void updateFunction(UDFunction udf)

#### dropFunction

    public void dropFunction(UDFunction udf)

#### addAggregate

    public void addAggregate(UDAggregate uda)

#### updateAggregate

    public void updateAggregate(UDAggregate uda)

#### dropAggregate

    public void dropAggregate(UDAggregate uda)

#### schemaVersionToString

    public static java.lang.String schemaVersionToString(java.util.UUID version)

Converts the given schema version to a string. Returns `unknown`, if `version` is `null` or `"(empty)"`, if `version` refers to an {@link SchemaConstants#emptyVersion empty) schema.