Hello, everybody! I create keyspace in Cassandra:
CREATE KEYSPACE monitoring WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' }; CREATE TABLE monitoring.data ( number text, day timestamp, last_day timestamp static, ids text static, PRIMARY KEY (number, day) ) WITH CLUSTERING ORDER BY (day DESC);
Later i insert data:
INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('12345678901', '2017-05-26', '2017-05-26', '["1","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('12345678901', '2017-10-26', '2017-10-26', '["1","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('12345678901', '2017-05-01', '2017-05-01', '["1","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('123456AA901', '2017-05-01', '2017-05-01', '["A","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('123456BB901', '2017-05-01', '2017-05-01', '["B","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('123456CC901', '2017-05-01', '2017-05-01', '["C","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('123456DD901', '2017-05-01', '2017-05-01', '["D","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('12345678901', '2017-05-23', '2017-05-23', '["1","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('12345678901', '2018-05-26', '2018-05-26', '["1","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('23456789012', '2017-04-01', '2017-04-01', '["6","2","11"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('34567890123', '2017-03-28', '2017-03-28', '["1","5","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('45678901234', '2017-04-03', '2017-04-03', '["12","2","3"]'); INSERT INTO monitoring.data (number, day, last_day, ids) VALUES ('56789012345', '2018-01-26', '2018-01-26', '["3","2","1"]');
Next i make query:
select distinct number,last_day,ids from monitoring.data WHERE number in ('12345678901','56789012345','45678901234');
Why Cassandra answer is and number 45678901234 between 12345678901 and 56789012345?
number | last_day | ids -------------+--------------------------+---------------- 12345678901 | 2018-05-25 21:00:00+0000 | ["1","2","3"] 45678901234 | 2017-04-02 21:00:00+0000 | ["12","2","3"] 56789012345 | 2018-01-25 21:00:00+0000 | ["3","2","1"]
How get right answer? Replication factor it's important in this situation? Later i will use LIMIT 10...