Assuming you have movies as a row, and a list of categories, i.e.
create table movie(
uuid timeuuid,
name text,
category list<text>
primary key (uuid)
);
insert into movie (uuid,name,category) values(now(), 'my movie', ['romance','comedy']);
insert into movie (uuid,name,category) values(now(), 'other movie', ['action','comedy']);
Is it possible to efficiently do something like:
select * from movie where category='comedy'
select * from movie where category='comedy' and category='action'
This use case is the most common query against our MySQL database.
CQL provides the facility of using Collection data types. Using these Collection types, you can store multiple values in a single variable.
Query languages are computer languages used to make queries in databases and information systems. Cassandra Query Language is the primary query language for communicating with the Apache Cassandra database. SQL (Structured Query Language) is the standard query language for dealing with Relational Databases.
Cassandra cannot do joins or subqueries. Rather, Casssandra emphasizes denormalization through features like collections. A column family (called "table" since CQL 3) resembles a table in a RDBMS (Relational Database Management system).
You can fine-tune the display order using the ORDER BY clause. The partition key must be defined in the WHERE clause and the ORDER BY clause defines the clustering column to use for ordering. cqlsh> CREATE TABLE cycling.
As of cassandra 2.1, yes it is:
create table cinema.movie(
id timeuuid,
name text,
category list<text>,
primary key (id)
);
CREATE index ON cinema.movie (category);
INSERT INTO cinema.movie (id, name, category) VALUES (now(), 'my movie', ['romance','comedy']);
SELECT * FROM cinema.movie WHERE category CONTAINS 'romance';
uuid | category | name
--------------------------------------+------------------------+----------
b9e0d7f0-995f-11e3-b11c-c5d4ddc8930a | ['romance', 'comed`y'] | my movie
(1 rows)
P.S. you have errors in your queries, you are missing a ,
in your create table statement after category's declaration and you cant use the now()
function on UUID, you are looking for the TIMEUUID type instead.
Bare in mind that performance wont be magnificent (how's that for quantitative) when it come's to using these collections, it might be better to create a separate table for this sort of thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With