An exploratory look into KairosDB (OpenTSDB) connected to Cassandra (CCM) and using AlchemyAPI for entity, topic and sentiment extraction.
Sprinkled in is a bit of Data Modeling, Truth Tables, Primary Keys, Partition Keys and Cluster Keys.
All written in Python!
15. Keys in C*
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
1. First part of composite key [inside the inner brackets] is called
“Partition Key”, rest [no inside the inner brackets] are “Cluster
Keys”.
2. Cassandra stores columns differently when composite keys
are used. Partition key becomes row key. Remaining keys are
concatenated with each column name (“:” as separator) to form
column names (cluster keys). Column values remain
unchanged.
3. Cluster keys (other than partition keys) are ordered, and you
cannot allowed search on random columns, you have to specify
the entire cluster key and can run a range query on the final
portion of it.
16. A bit of data modelling
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
USER ACTIVITY DATA MODEL
CREATE TABLE user_activity (
… username varchar,
… interaction_time timeuuid,
… activity_code varchar,
… detail varchar
… PRIMARY KEY (username, interaction time)
… )
CREATE TABLE user_activity_history (
… username varchar,
… interaction_date varchar,
… interaction_time timeuuid,
… activity_code varchar,
… detail varchar,
… PRIMARY KEY ( ,interaction_time)
… );
17. Data modelling 4 QUERIES
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
FIND A CAR IN A LOT
CREATE TABLE car_location_index (
… make varchar,
… model varchar,
… colour varchar,
… vehicle_id int,
… lot_id,
… PRIMARY KEY ((make,model,colour),vehicle_id)
… );
18. Data modelling 4 QUERIES
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
FIND A CAR IN A LOT
19. Data modelling 4 QUERIES
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
FIND A CAR IN A LOT
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘Ford’,’Mustang’,’Blue’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘Ford’,’Mustang’,’’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘Ford’,’’,’Blue’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘Ford’,’’,’’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘’,’Mustang’,’Blue’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘’,’Mustang’,’’,1234,8675309)
INSERT INTO car_location_index (make,model,colour,vehicle_id,lot_id)
VALUES (‘’,’’,’Blue’,1234,8675309)
20. Data modelling 4 QUERIES
KEEP
TWEETING
@VictorFAnjos
@viafoura
@AlchemyAPI
@Datastax
@Data_for_Good
FIND A CAR IN A LOT
SELECT vehicle_id, lot_id
FROM car_location_index
WHERE make = ‘Ford’
AND model = ‘’
AND colour= ‘Blue’;
vehicle_id | lot_id
--------------+-----------
1234 | 8675309
SELECT vehicle_id, lot_id
FROM car_location_index
WHERE make = ‘’
AND model = ‘’
AND colour = ‘Blue’;
vehicle_id | lot_id
--------------+-----------
1234 | 8675309
8765 | 5551212