|Cassandra tools / Using CLI|
In a relational database, you must specify a data type for each column when you define a table. The data type constrains the values that can be inserted into that column. For example, if you have a column defined as an integer datatype, you would not be allowed to insert character data into that column. Column names in a relational database are typically fixed labels (strings) that are assigned when you define the table schema.
In Cassandra CLI and Thrift, the data type for a column (or row key) value is called a validator. The data type for a column name is called a comparator. Cassandra validates that data type of the keys of rows.
Columns are sorted, and stored in sorted order on disk, so you have to specify a comparator for columns. You can define the validator and comparator when you create your table schema (which is recommended), but Cassandra does not require it. Internally, Cassandra stores column names and values as hex byte arrays (BytesType). This is the default client encoding used if data types are not defined in the table schema (or if not specified by the client request).
|Internal /CLI Type||CQL Name||Description|
|BytesType||blob||Arbitrary hexadecimal bytes (no validation)|
|AsciiType||ascii||US-ASCII character string|
|UTF8Type||text, varchar||UTF-8 encoded string|
|InetAddressType||inet||IP address string in IPv4 or IPv6 format|
|TimeUUIDType||timeuuid||Type 1 UUID only (CQL3)|
|DateType||timestamp||Date plus time, encoded as 8 bytes since epoch|
|BooleanType||boolean||true or false|
|FloatType||float||4-byte floating point|
|DoubleType||double||8-byte floating point|
|CounterColumnType||counter||Distributed counter value (8-byte long)|
Using the CLI you can define a default row key validator for a table using the key_validation_class property. Using CQL, you use built-in key validators to validate row key values. For static tables, define each column and its associated type when you define the table using the column_metadata property.
Key and column validators may be added or changed in a table definition at any time. If you specify an invalid validator on your table, client requests that respect that metadata are confused, and data inserts or updates that do not conform to the specified validator are rejected.
You cannot know the column names of dynamic tables ahead of time, so specify a default_validation_class instead of defining the per-column data types.
Key and column validators can be added or changed in a table definition at any time. If you specify an invalid validator on the table, client requests that respect that metadata get confused, and data inserts or updates that do not conform to the specified validator are rejected.
Within a row, columns are always stored in sorted order by their column name. A comparator specifies the data type for the column name, as well as the sort order in which columns are stored within a row. Unlike a validator, the comparator may not be changed after the table is defined, so this is an important consideration when defining a table in Cassandra.
Typically, static table names will be strings, and the sort order of columns is not important in that case. For dynamic tables, however, sort order is important. For example, in a table that stores time series data (the column names are timestamps), having the data in sorted order is required for slicing result sets out of a row of columns.