blob: 6c09f67c647f265f6b3396cb0e20e5631ccdb3b7 [file]
CREATE DATABASE hotel_blog;
USE hotel_blog;
CREATE TABLE orders (
hotel_id STRING, order_id STRING, stay_date STRING,
observed_at STRING, created_at STRING, updated_at STRING,
cancelled BIGINT, amount_cents BIGINT, rate_code STRING,
PRIMARY KEY (hotel_id, order_id, stay_date) NOT ENFORCED
) WITH ('bucket.num'='1');
CREATE TABLE channels (rate_code STRING, selected BIGINT, PRIMARY KEY(rate_code) NOT ENFORCED) WITH ('bucket.num'='1');
CREATE TABLE window_totals (
hotel_id STRING,stay_date STRING,window_minutes INT,window_start TIMESTAMP(3),window_end TIMESTAMP(3),
nights BIGINT,revenue_cents BIGINT,channel_nights BIGINT,channel_revenue_cents BIGINT,
PRIMARY KEY(hotel_id,stay_date,window_minutes,window_start,window_end) NOT ENFORCED
) WITH ('bucket.num'='1','table.merge-engine'='aggregation',
'fields.nights.agg'='sum','fields.revenue_cents.agg'='sum','fields.channel_nights.agg'='sum','fields.channel_revenue_cents.agg'='sum');
CREATE TABLE baseline (
hotel_id STRING,stay_date STRING,window_minutes INT,window_start TIMESTAMP(3),window_end TIMESTAMP(3),
nights BIGINT,revenue_cents BIGINT,channel_nights BIGINT,channel_revenue_cents BIGINT,
PRIMARY KEY(hotel_id,stay_date,window_minutes,window_start,window_end) NOT ENFORCED
) WITH ('bucket.num'='1');
INSERT INTO channels VALUES ('DIRECT',0),('OTA',1);