Follow the timescale tutorial to install and run a timescale db instance. (https://docs.timescale.com/v0.9/getting-started/installation/mac/installation-homebrew)
Follow this tutorial to import a sample dataset. Here we are using New York City taxicab data. (https://docs.timescale.com/v0.9/tutorials/tutorial-hello-nyc). Follow this tutorial till the point to import data.
Follow https://docs.hasura.io to run the GraphQL engine - with the correct database credentials pointing to your timescaledb instance.
Open the console hasura console
, and track all the tables.
Create views with timescaledb specific functions, for timescale specific queries.
Use Run SQL in console to create these views and track them:
-- Average fare amount of rides with 2+ passengers by day
CREATE VIEW avg_fare_w_2_plus_passenger_by_day AS (
SELECT date_trunc('day', pickup_datetime) as day, avg(fare_amount) as avg_fare
FROM rides
WHERE passenger_count > 1
GROUP BY day ORDER BY day
);
-- Total number of rides by day for first 5 days
CREATE VIEW ride_count_by_day AS (
SELECT date_trunc('day', pickup_datetime) as day, COUNT(*) FROM rides
GROUP BY day ORDER BY day
);
-- Number of rides by 5 minute intervals
-- (using the TimescaleDB "time_bucket" function)
CREATE VIEW rides_in_5min_intervals AS (
SELECT time_bucket('5 minute', pickup_datetime) AS five_min_interval, count(*) as rides
FROM rides
GROUP BY five_min_interval ORDER BY five_min_interval
);
query {
avg_fare_w_2_plus_passenger_by_day(limit: 10) {
day
avg_fare
}
}
query FirstTenDaysWithRidesMoreThan30k {
ride_count_by_day(limit: 10, where: {count : {_gt: 30000}}) {
day
count
}
}
query NoOfRidesIn5minIntervalBefore02Jan {
rides_in_5min_intervals(where: {five_min_interval:{_lt: "2016-01-02 00:00"}}) {
five_min_interval
rides
}
}
See details in citus/README.md
.