Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Cassandra static field

I learn Cassandra through its documentation. Now I'm learning about batch and static fields.

In their example at the end of the page, they somehow managed to make balance have two different values (-200, -208) even though it's a static field.

Could someone explain to me how this is possible? I've read the whole page but I did not catch on.

like image 389
Alon Avatar asked Jul 14 '26 07:07

Alon


1 Answers

In Cassandra static field is static under a partition key.
Example : Let's define a table

CREATE TABLE static_test (
    pk int,
    ck int,
    d int,
    s int static,
    PRIMARY KEY (pk, ck)
);

Here pk is the partition key and ck is the clustering key.

Let's insert some data :

INSERT INTO static_test (pk , ck , d , s ) VALUES ( 1, 10, 100, 1000);
INSERT INTO static_test (pk , ck , d , s ) VALUES ( 2, 20, 200, 2000);

If we select the data

 pk | ck | s    | d
----+----+------+-----
  1 | 10 | 1000 | 100
  2 | 20 | 2000 | 200

here for partition key pk = 1 static field s value is 1000 and for partition key pk = 2 static field s value is 2000

If we insert/update static field s value of partition key pk = 1

INSERT INTO static_test (pk , ck , d , s ) VALUES ( 1, 11, 101, 1001);

Then static field s value will change for all the rows of the partition key pk = 1

 pk | ck | s    | d
----+----+------+-----
  1 | 10 | 1001 | 100
  1 | 11 | 1001 | 101
  2 | 20 | 2000 | 200
like image 67
Ashraful Islam Avatar answered Jul 15 '26 20:07

Ashraful Islam