Cassandra Interpreter V2 Test data
CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION = { | |
'class' : 'org.apache.cassandra.locator.SimpleStrategy', | |
'replication_factor': '1' } | |
AND DURABLE_WRITES = true; | |
CREATE TABLE IF NOT EXISTS test.test_max ( | |
id int, | |
val1 int, | |
val2 int, | |
PRIMARY KEY (id) | |
); | |
CREATE FUNCTION IF NOT EXISTS test.maxOf( | |
val1 int, | |
val2 int) | |
RETURNS NULL ON NULL INPUT | |
RETURNS int | |
LANGUAGE java | |
AS $$ | |
return Math.max(val1, val2); | |
$$; | |
TRUNCATE test.test_max; | |
INSERT INTO test.test_max(id,val1,val2) VALUES(1,100,110); | |
INSERT INTO test.test_max(id,val1,val2) VALUES(2,200,110); | |
INSERT INTO test.test_max(id,val1) VALUES(3,100); | |
CREATE TABLE IF NOT EXISTS test.items ( | |
shop_id text, | |
day int, | |
category text, | |
sales_count int, | |
PRIMARY KEY (shop_id, day, category) | |
); | |
CREATE FUNCTION IF NOT EXISTS test.accumulator( | |
state map<text, int>, | |
category text, | |
count int) | |
RETURNS NULL ON NULL INPUT | |
RETURNS map<text, int> | |
LANGUAGE java | |
AS $$ | |
if(state.containsKey(category)) { | |
state.put(category, (Integer)state.get(category) + count); | |
} else { | |
state.put(category, count); | |
} | |
return state; | |
$$; | |
CREATE AGGREGATE IF NOT EXISTS test.group_by(text,int) | |
SFUNC accumulator | |
STYPE map<text, int> | |
INITCOND {}; | |
TRUNCATE test.items; | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151201,'BOOKS',345); | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151201,'DVD',5000); | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151201,'GAMES',734); | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151202,'BOOKS',120); | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151202,'DVD',7483); | |
INSERT INTO test.items(shop_id,day,category,sales_count) VALUES('AMAZON',20151202,'GAMES',1340); | |
CREATE TABLE IF NOT EXISTS test.user ( | |
id int, | |
country text, | |
firstname text, | |
lastname text, | |
login text, | |
PRIMARY KEY (id) | |
); | |
CREATE MATERIALIZED VIEW IF NOT EXISTS test.user_by_country AS | |
SELECT * FROM test.user | |
WHERE id IS NOT NULL AND country IS NOT NULL | |
PRIMARY KEY (country, id); | |
TRUNCATE test.user; | |
INSERT INTO test.user(id,login,firstname,lastname,country) VALUES(1, 'jdoe', 'John', 'DOE', 'US'); | |
INSERT INTO test.user(id,login,firstname,lastname,country) VALUES(2, 'hsue', 'Helen', 'SUE', 'US'); | |
INSERT INTO test.user(id,login,firstname,lastname,country) VALUES(3, 'rsmith', 'Richard', 'SMITH', 'UK'); | |
INSERT INTO test.user(id,login,firstname,lastname,country) VALUES(4, 'doanduyhai', 'DuyHai', 'DOAN', 'FR'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment