Merge pull request #1905 from joaquincasares/cql_support

Add support for cql and ddl files
This commit is contained in:
Adam Roben
2015-01-08 10:45:15 -05:00
3 changed files with 172 additions and 0 deletions

View File

@@ -2628,6 +2628,8 @@ SQL:
ace_mode: sql
extensions:
- .sql
- .cql
- .ddl
- .prc
- .tab
- .udf

85
samples/SQL/videodb.cql Normal file
View File

@@ -0,0 +1,85 @@
CREATE KEYSPACE videodb WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
use videodb;
// Basic entity table
// Object mapping ?
CREATE TABLE users (
username varchar,
firstname varchar,
lastname varchar,
email varchar,
password varchar,
created_date timestamp,
total_credits int,
credit_change_date timeuuid,
PRIMARY KEY (username)
);
// One-to-many entity table
CREATE TABLE videos (
videoid uuid,
videoname varchar,
username varchar,
description varchar,
tags list<varchar>,
upload_date timestamp,
PRIMARY KEY (videoid)
);
// One-to-many from the user point of view
// Also know as a lookup table
CREATE TABLE username_video_index (
username varchar,
videoid uuid,
upload_date timestamp,
videoname varchar,
PRIMARY KEY (username, videoid)
);
// Counter table
CREATE TABLE video_rating (
videoid uuid,
rating_counter counter,
rating_total counter,
PRIMARY KEY (videoid)
);
// Creating index tables for tab keywords
CREATE TABLE tag_index (
tag varchar,
videoid uuid,
timestamp timestamp,
PRIMARY KEY (tag, videoid)
);
// Comments as a many-to-many
// Looking from the video side to many users
CREATE TABLE comments_by_video (
videoid uuid,
username varchar,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (videoid,comment_ts,username)
) WITH CLUSTERING ORDER BY (comment_ts DESC, username ASC);
// looking from the user side to many videos
CREATE TABLE comments_by_user (
username varchar,
videoid uuid,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (username,comment_ts,videoid)
) WITH CLUSTERING ORDER BY (comment_ts DESC, videoid ASC);
// Time series wide row with reverse comparator
CREATE TABLE video_event (
videoid uuid,
username varchar,
event varchar,
event_timestamp timeuuid,
video_timestamp bigint,
PRIMARY KEY ((videoid,username), event_timestamp,event)
) WITH CLUSTERING ORDER BY (event_timestamp DESC,event ASC);

85
samples/SQL/videodb.ddl Normal file
View File

@@ -0,0 +1,85 @@
CREATE KEYSPACE videodb WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
use videodb;
// Basic entity table
// Object mapping ?
CREATE TABLE users (
username varchar,
firstname varchar,
lastname varchar,
email varchar,
password varchar,
created_date timestamp,
total_credits int,
credit_change_date timeuuid,
PRIMARY KEY (username)
);
// One-to-many entity table
CREATE TABLE videos (
videoid uuid,
videoname varchar,
username varchar,
description varchar,
tags list<varchar>,
upload_date timestamp,
PRIMARY KEY (videoid)
);
// One-to-many from the user point of view
// Also know as a lookup table
CREATE TABLE username_video_index (
username varchar,
videoid uuid,
upload_date timestamp,
videoname varchar,
PRIMARY KEY (username, videoid)
);
// Counter table
CREATE TABLE video_rating (
videoid uuid,
rating_counter counter,
rating_total counter,
PRIMARY KEY (videoid)
);
// Creating index tables for tab keywords
CREATE TABLE tag_index (
tag varchar,
videoid uuid,
timestamp timestamp,
PRIMARY KEY (tag, videoid)
);
// Comments as a many-to-many
// Looking from the video side to many users
CREATE TABLE comments_by_video (
videoid uuid,
username varchar,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (videoid,comment_ts,username)
) WITH CLUSTERING ORDER BY (comment_ts DESC, username ASC);
// looking from the user side to many videos
CREATE TABLE comments_by_user (
username varchar,
videoid uuid,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (username,comment_ts,videoid)
) WITH CLUSTERING ORDER BY (comment_ts DESC, videoid ASC);
// Time series wide row with reverse comparator
CREATE TABLE video_event (
videoid uuid,
username varchar,
event varchar,
event_timestamp timeuuid,
video_timestamp bigint,
PRIMARY KEY ((videoid,username), event_timestamp,event)
) WITH CLUSTERING ORDER BY (event_timestamp DESC,event ASC);