2016-04-06 23 views
2

操作我有一个表结构卡桑德拉:与Apache Cassandra的列表

CREATE TABLE statistics (
    clientId VARCHAR, 
    hits LIST<text>, 
    PRIMARY KEY (clientId) 
); 

INSERT INTO statistics(clientId, hits) VALUES ('clientId', [{'referer': 'http://example.com/asd', 'type': 'PAGE', 'page': '{"title": "Page title"}'}, {'referer': 'http://example.com/dsa', 'type': 'EVENT', 'event': '{"title": "Click on big button"}'}, {'referer': 'http://example.com/fgd', 'type': 'PAGE', 'page': '{"title": "Page title second"}'}]); 

我想选择与类型=“页面”命中计数。

我该怎么办?

回答

3

列表是不正确的结构,使用情况,考虑以下架构

CREATE TABLE statistics(
    client_id VARCHAR, 
    hit_type text, 
    referer text, 
    page text, 
    event text, 
    PRIMARY KEY ((client_id,hit_type), referer) 
); 

// Insert hits 
INSERT INTO statistics(client_id, hit_type, referer, page) 
VALUES('client1','PAGE', 'http://example.com/asd', '{"title": "Page title"}'); 

INSERT INTO statistics(client_id, hit_type, referer, event) 
VALUES('client1','EVENT', 'http://example.com/dsa', '{"title": "Click on big button"}'); 

INSERT INTO statistics(client_id, hit_type, referer, page) 
VALUES('client1','PAGE', 'http://example.com/fgd', '{"title": "Page title second"}'); 

//Select all hits for a given client and hit type: 
SELECT * FROM statistics WHERE client_id='xxx' AND hit_type='PAGE'; 

请注意,上面的架构,不建议有超过100个百万参照网址为每对情侣(client_id,hit_type)