Raja's Exocortex

ClickHouse for Omnyk Backend

Draft ClickHouse SQL Schema

-- draft schema for omnyk data_points

CREATE TABLE fastball.data_points
(
  `tenantid`    LowCardinality(String)          CODEC(ZSTD(3)),
  `userid`      UUID                            CODEC(ZSTD(3)),
  `ringid`      LowCardinality(FixedString(17)) CODEC(ZSTD(3)), -- 4F:4D:4B:00:00:10
  `time`        DateTime64(3)                   CODEC(Delta, ZSTD(3)),

-- TODO: Test compression of below data points
  `heartrate`   Nullable(UInt8)        CODEC(Delta, ZSTD(3)),       -- 45-220
  `beatsmissed` Nullable(Bool)         CODEC(ZSTD(3)),              -- Boolean!
  `ibi`         Nullable(UInt16)       CODEC(Delta, ZSTD(3)),       -- Min 271 Max 4000
  `spo2`        Nullable(UInt8)        CODEC(T64, Delta, ZSTD(3)),  -- Min 75 Max 99
  `steps`       UInt8                  CODEC(T64, ZSTD(3))          -- Min 0 Max 40, not NULL
)
ENGINE = ReplacingMergeTree    -- need ReplacingMergeTree to delete duplicate values from ORDER BY below
PRIMARY KEY (tenantid, userid) -- TODO: is this correct? Will this create an explosion of table files? 
ORDER BY (tenantid, userid, ringid, time)

-- TODO: For Testing
-- TTL time + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(17)),
-- SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;

-- TODO: Last point problem -- materialized view for last 30 seconds data across all rings