Skip to content

Instantly share code, notes, and snippets.

@mlowicki
Created December 30, 2015 17:13
Show Gist options
  • Select an option

  • Save mlowicki/958ea828c90132240fe4 to your computer and use it in GitHub Desktop.

Select an option

Save mlowicki/958ea828c90132240fe4 to your computer and use it in GitHub Desktop.
cqlsh:test> desc table bucket;
CREATE TABLE test.bucket (
user_id text,
data_type_id int,
spot timestamp,
count int static,
PRIMARY KEY ((user_id, data_type_id), spot)
) WITH CLUSTERING ORDER BY (spot ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
cqlsh:test> insert into bucket (user_id, data_type_id, count) values ('foo', 1, 1) if not exists;
[applied]
-----------
True
cqlsh:test> select * from bucket;
user_id | data_type_id | spot | count
---------+--------------+------+-------
foo | 1 | null | 1
(1 rows)
cqlsh:test> insert into bucket (user_id, data_type_id, count) values ('foo', 1, 2) if not exists;
[applied] | user_id | data_type_id | spot | count
-----------+---------+--------------+------+-------
False | foo | 1 | null | 1
cqlsh:test> select * from bucket;
user_id | data_type_id | spot | count
---------+--------------+------+-------
foo | 1 | null | 1
(1 rows)
cqlsh:test> begin batch
... update bucket set count = 2 where user_id = 'foo' and data_type_id = 1 if count = 1;
... insert into bucket (user_id, data_type_id, spot) values ('foo', 1, 10000);
... apply batch;
[applied]
-----------
True
cqlsh:test> select * from bucket;
user_id | data_type_id | spot | count
---------+--------------+--------------------------+-------
foo | 1 | 1970-01-01 00:00:10+0000 | 2
(1 rows)
cqlsh:test> begin batch
... update bucket set count = 3 where user_id = 'foo' and data_type_id = 1 if count = 1;
... insert into bucket (user_id, data_type_id, spot) values ('foo', 1, 20000);
... apply batch;
[applied] | user_id | data_type_id | spot | count
-----------+---------+--------------+------+-------
False | foo | 1 | null | 2
cqlsh:test> select * from bucket;
user_id | data_type_id | spot | count
---------+--------------+--------------------------+-------
foo | 1 | 1970-01-01 00:00:10+0000 | 2
(1 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment