Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created August 26, 2014 16:48

Revisions

  1. thinkerbot created this gist Aug 26, 2014.
    33 changes: 33 additions & 0 deletions xyz.cql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    DROP KEYSPACE IF EXISTS example;
    CREATE KEYSPACE example WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
    USE example;

    DROP TABLE IF EXISTS xyz;
    create table xyz (
    xpart int,
    x int,
    z int,
    y int,
    PRIMARY KEY (xpart, x, z)
    );

    insert into xyz (xpart, z, x, y) values (0, 1, 1, 1);
    insert into xyz (xpart, z, x, y) values (0, 1, 2, 2);
    insert into xyz (xpart, z, x, y) values (0, 2, 2, 1);
    insert into xyz (xpart, z, x, y) values (0, 2, 3, 2);
    insert into xyz (xpart, z, x, y) values (0, 3, 3, 1);
    insert into xyz (xpart, z, x, y) values (0, 3, 4, 2);

    -- TRACING ON;
    -- Queries using part key can be EQ/IN
    -- Queries on cluster key(s) may be chained as long as the preceding is EQ
    -- The final cluster key may use GT,LT,GTE,LTE
    --
    -- Can sort on the SECOND column, but that means you would have to always
    -- be able to specify the second column as EQ to get to the third column.
    select * from xyz;
    select * from xyz where xpart = 0;
    select * from xyz where xpart = 0 and x = 2;
    select * from xyz where xpart = 0 and x >= 2 and x < 4;
    select * from xyz where xpart = 0 and x = 3 and z > 2;
    select * from xyz where xpart IN (0,1) and x >= 2 and x < 4;