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

tyuen_144153 avatar image
tyuen_144153 asked Erick Ramirez answered

Is there a way of storing all rows in one node?

Let say I have 6 nodes with replication factor of 3.

Column Family: table1

Clustering key: C1, C2

Sample Data (9 rows)

COL1 | COL2 | COL3
a1   | 01   | 'Hello'
a1   | 02   | 'Hi'
a1   | 03   | 'Good Morning'
b1   | 01   | 'Good Afternoon'
b1   | 02   | 'Lunch Time'
c1   | 01   | 'Night time'
c1   | 02   | 'Good night'
c1   | 03   | 'Bed time'
c1   | 04   | 'Tired'

is there a way to make all of "a1" to stored together in one node so that the coordinator does need to go across the cluster?

data modeling
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.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Yes, there is. If column 1 is the partition key of your table and col2 is the clustering key then all rows will be stored in the same partition.

The schema for the table will look something like this:

CREATE TABLE table1
    col1 text,
    col2 text,
    col2 text,
    PRIMARY KEY ((col1), col2)
)

If you're not familiar with partitions and clustering columns, I've explained them in a bit more detail in question #6171.

It also seems like you might be interested in learning more about how data is partitioned in Cassandra so I highly recommend you have a look at the short free interactive tutorials at https://www.datastax.com/learn/data-modeling-by-example. Cheers!

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.