Class SchemaCQLHelper


  • public class SchemaCQLHelper
    extends java.lang.Object
    Helper methods to represent TableMetadata and related objects in CQL format
    • Constructor Detail

      • SchemaCQLHelper

        public SchemaCQLHelper()
    • Method Detail

      • reCreateStatementsForSchemaCql

        public static java.util.stream.Stream<java.lang.String> reCreateStatementsForSchemaCql​(TableMetadata metadata,
                                                                                               KeyspaceMetadata keyspaceMetadata)
        Generates the DDL statement for a schema.cql snapshot file.
      • getTableMetadataAsCQL

        public static java.lang.String getTableMetadataAsCQL​(TableMetadata metadata,
                                                             KeyspaceMetadata keyspaceMetadata)
        Build a CQL String representation of Column Family Metadata. *Note*: this is _only_ visible for testing; you generally shouldn't re-create a single table in isolation as that will not contain everything needed for user types.
      • getUserTypesAsCQL

        public static java.util.stream.Stream<java.lang.String> getUserTypesAsCQL​(TableMetadata metadata,
                                                                                  Types types,
                                                                                  boolean ifNotExists)
        Build a CQL String representation of User Types used in the given table. Type order is ensured as types are built incrementally: from the innermost (most nested) to the outermost.
        Parameters:
        metadata - the table for which to extract the user types CQL statements.
        types - the user types defined in the keyspace of the dumped table (which will thus contain any user type used by metadata).
        ifNotExists - set to true if IF NOT EXISTS should be appended after CREATE TYPE string.
        Returns:
        a list of CREATE TYPE statements corresponding to all the types used in metadata.
      • getIndexesAsCQL

        public static java.util.stream.Stream<java.lang.String> getIndexesAsCQL​(TableMetadata metadata,
                                                                                boolean ifNotExists)
        Build a CQL String representation of Indexes on columns in the given Column Family
        Parameters:
        metadata - the table for which to extract the index CQL statements.
        ifNotExists - set to true if IF NOT EXISTS should be appended after CREATE INDEX string.
        Returns:
        a list of CREATE INDEX statements corresponding to table metadata.
      • toCqlType

        public static java.lang.String toCqlType​(AbstractType<?> type)
        Converts the type to a CQL type. This method special cases empty and UDTs so the string can be used in a create statement. Special cases
        • empty - replaces with 'org.apache.cassandra.db.marshal.EmptyType'. empty is the tostring of the type in CQL but not allowed to create as empty, but fully qualified name is allowed
        • UserType - replaces with TupleType