So now we have a sparse, multidimensional array structure that looks like Figure 4-4. Instead of storing null for those values we don’t know, which would waste space, we just won’t store that column at all for that row. For example, some people have a second phone number and some don’t, and in an online form backed by Cassandra, there may be some fields that are optional and some that are required. Maybe we don’t know the values for every column for a given entity. Now we don’t need to store a value for every column every time we store a new entity. In this way, a Cassandra table is analogous to a table in the relational world. For example, we might have a user table, a hotel table, an address book table, and so on. Figure 4-3 shows the contents of a simple row: a primary key, which is itself one or more columns, and additional columns.Ĭassandra defines a table to be a logical division that associates similar data. And the unique identifier for each row could be called a row key or primary key. We could call each separate entity that holds some set of columns rows. We could call these name/value pairs columns. Then, if we get a single row, we can get all of the name/value pairs for a single entity at once, or just get the values for the names we’re interested in. We need a key to reference a group of columns that should be treated together as a set. So we need something that will group some of the column values together in a distinctly addressable group. There’s nothing to unify some collection of name/value pairs, and no way to repeat the same column names. It doesn’t give us much if we want to store multiple entities with the same structure, which is certainly what we want to do. This is a somewhat richer structure to work with.īut the structure we’ve built so far works only if we have one instance of a given entity, such as a single person, user, hotel, or tweet. So if we decided that our map would hold User information, we could have column names like first_name, last_name, phone, email, and so on. This is an improvement because we can know the names of our values. Along the way we’ll get more familiar with CQL and learn how it implements this data model. So in this chapter, we start from relational database terminology and introduce Cassandra’s view of the world. For those familiar with NoSQL technologies such as Dynamo or Bigtable, it can also be confusing, because although Cassandra may be based on those technologies, its own data model is significantly different. The syntax of CQL is similar in many ways to SQL, but with some important differences. Some terms, such as “keyspace,” are completely new, and some, such as “column,” exist in both worlds but have slightly different meanings. We’ll show how CQL supports Cassandra’s design goals and look at some general behavior characteristics.įor developers and administrators coming from the relational world, the Cassandra data model can be difficult to understand initially. > ENUM('RED','GREEN','BLUE','YELLOW','ORANGE','PINK') Ĭheck the description of the table to ensure that the values are added or not.In this chapter, you’ll gain an understanding of Cassandra’s data model and how that data model is implemented by the Cassandra Query Language (CQL). The following is the query to add a new value to enum column ‘Colors’ − mysql> ALTER TABLE addingnewvaluetoenumcolumn MODIFY COLUMN Colors Look at the enum column ‘Colors’ with the value 'RED','GREEN','BLUE' and if you want another value, then use the ALTER command as discussed above. ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci `Colors` enum('RED','GREEN','BLUE') DEFAULT NULL, The query is as follows − mysql> show create table AddingNewValueToEnumColumn\G To check the DDL of the above table, use the show create command. The query to create a table is as follows − mysql> create table AddingNewValueToEnumColumn To understand the above syntax, let us create a table. The syntax is as follows − ALTER TABLE yourTableName MODIFY COLUMN yourEnumColumnNameĮNUM('yourExistingValue1','yourExistingValue2'.N,'yourNewValue1',’yourNewValue2’.N) If you want the existing value of enum, then you need to manually write the existing enum value at the time of adding a new value to column of data type enum. You can add a new value to a column of data type enum using ALTER MODIFY command.