Database Reference
In-Depth Information
url TEXT,
count COUNTER,
PRIMARY KEY(hour, url)
);
Now that we have created the tables for event_metrics that contain our
counters, we can update the counters at the same time using a BATCH statement.
Listing 3.8 shows the insertion of the raw event and updating of the counters in a
single atomic batch.
Listing 3.8 Example of Using an Atomic Counter BATCH to Insert and Up-
date
Click here to view code image
INSERT INTO events (hour, id, time, event_type,
data)
VALUES ('2013-06-13 11:00:00', NOW(),
'2013-06-13 11:43:23',
'click', '{"url":"http://example.com"}')
BEGIN COUNTER BATCH
UPDATE event_metrics SET count = count + 1
WHERE hour = '2013-06-13 11:00:00'
AND event_type = 'click'
UPDATE url_metrics SET count = count + 1
WHERE hour = '2013-06-13 11:00:00'
AND url = 'http://example.com'
APPLY BATCH;
Collections
Cassandra also includes collections as part of its data model. Collections are a
complex type that can provide flexibility in querying.
 
Search WWH ::




Custom Search