Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

mandardotkulkarni_162904 avatar image
mandardotkulkarni_162904 asked ·

is Clustering column mandatory

Hello,

Need to understand below

1. create table d(a int,b int,c int, primary key((a,b)));

Here Primary key = composite partition key with no clustering column.

2.create table e(a int,b int,c int, primary key(a,b));

Here Primary key = compound primary key where partition key=a and clustering key=b

Please let me know if above understanding is correct ?

cassandra
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

davebechberger avatar image
davebechberger answered ·

Your understanding is correct, a clustering key is not required.

In the first example, you will create a table with a composite partition key of a and b which means that your data will be partitioned by both those values. When running CQL queries on this table it includes both a and b as filtering columns in the WHERE clause.

In the second example, you will create a table with a compound primary key where the partition key is a and a clustering column is b. This means that your data will be partitioned by a and then sorted by b, in descending order. When running CQL queries on this table it must include a as a filtering column in the WHERE clause and filtering on b is optional.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

sainikhilguntur_181814 avatar image
sainikhilguntur_181814 answered ·

Basically clustering columns are used by cassandra to arrange the data in clusters by sorting on them.

Clustering column is not necessary.

If clustering column is not given, partition column is used to sort the data in cassandra clusters.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.