Database Reference
In-Depth Information
Figure 3-7 . Composite column having imvivek as the partition key and remaining as the cluster key
While performing data modeling over Cassandra, one important point worth men-
tioning is that Ordering over the clustering key works only if the partition key is in EQ/
IN clause. Hence, while defining table structure, make sure that columns that need to
be sorted are part of the cluster columns. You can also ensure clustering order while
creating table as
create table users(user_id text,followers set<text>,
tweet_date timestamp, tweet_body text, first_name text,
PRIMARY KEY(user_id,tweet_date, first_name)) with
clustering order by (tweet_date DESC);
This would ensure keeping clustered data ordered by tweet_date in descending
order.
Allow Filtering
As discussed in the “Secondary Indexes” section, one constraint with a secondary in-
dex is only the EQ operator is allowed over indexed columns. We can perform range
queries over non-row key columns if those are defined as cluster columns. The query
below will work as tweet_date is part of the remaining clustering key.
By default Cassandra restricts execution of such queries and intelligently educates
them about performance overhead of such queries by explicitly asking to enable filter-
ing using allow filtering clause.
Users can run such queries by explicitly adding the ALLOW FILTERING clause
with select queries as
select * from users where tweet_date>='2013-12-31' allow
filtering;
Figure 3-8 shows the output from selecting users by tweet date with allow filtering
enabled.
 
Search WWH ::




Custom Search