Search code examples
cassandracql3

How can I use CQL in Cassandra 3 to determine if a table uses compact storage?


If I use the cqlsh tool that comes with Cassandra 3, it can tell me if a table was created WITH COMPACT STORAGE. All I have to do is describe table_name; and it shows me the CQL used to create the table.

The describe functionality is a feature of cqlsh, not of the CQL language. I need to determine if a table uses compact storage using just CQL. What do I need to query in the system_schema to determine if a table is using compact storage?


Solution

  • From the definition of the TableMetadataV3 class in the cassandra driver for python, the logic for determining compact storage is as follows

     flags = row.get('flags', set())
                if flags:
                    compact_static = False
                    table_meta.is_compact_storage = 'dense' in flags or 'super' in flags or 'compound' not in flags
                    is_dense = 'dense' in flags
                else:
                    compact_static = True
                    table_meta.is_compact_storage = True
                    is_dense = False
    

    The row object is a dictionary that is the result of the query "SELECT * FROM system_schema.tables"

    So to determine if a table uses compact storage, the following steps are necessary.

    1. Use CQL to query Select flags from system_schema.tables where keyspace_name=? and table_name=?. Substitute the keyspace and table in as parameters
    2. If flags is empty, then the table uses compact storage.
    3. If flags is present with 'dense' or 'super' as members of the set then the table uses compact storage.
    4. If 'compound' is not in the set then the table uses compact storage.
    5. Otherwise the table does not use compact storage.