Last active
February 18, 2019 09:33
-
-
Save tzach/05b39cfb22cfcf7b06885be07df70f19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### First Try | |
CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; | |
USE mykeyspace; | |
CREATE TABLE heartrate ( | |
pet_chip_id uuid, | |
time timestamp, | |
heart_rate int, | |
PRIMARY KEY (pet_chip_id, time)); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:01:00', 100); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:02:00', 103); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:03:00', 130); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:04:00', 131); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:05:00', 111); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:06:00', 99); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05 07:04:00', 100); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05 07:05:00', 99); | |
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05 07:06:00', 100); | |
SELECT * from heartrate WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23; | |
SELECT * from heartrate WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00'; | |
### Second | |
CREATE TABLE heartrate2 ( | |
pet_chip_id uuid, | |
date text, | |
time timestamp, | |
heart_rate int, | |
PRIMARY KEY ((pet_chip_id, date), time)); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:01:00', 100); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:02:00', 103); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:03:00', 130); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:04:00', 131); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:05:00', 111); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04', '2019-03-04 07:06:00', 99); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05', '2019-03-05 07:04:00', 100); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05', '2019-03-05 07:05:00', 99); | |
INSERT INTO heartrate2(pet_chip_id, date, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-05', '2019-03-05 07:06:00', 100); | |
SELECT * from heartrate2 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00'; | |
> InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING" | |
* Full Scan | |
SELECT * from heartrate2 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00' ALLOW FILTERING; | |
* WHERE on Date | |
SELECT * from heartrate2 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND date = '2019-03-04' AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00'; | |
SELECT * from heartrate2 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND date = '2019-03-05' AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00'; | |
* IN | |
SELECT * from heartrate2 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23 AND date IN('2019-03-05', '2019-03-04') AND time>='2019-03-04 07:03:00' AND time <= '2019-03-05 07:05:00'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment