umami/db/clickhouse/schema.sql

97 lines
2.3 KiB
MySQL
Raw Normal View History

2022-09-01 06:44:49 +02:00
SET allow_experimental_object_type = 1;
2022-09-12 18:55:34 +02:00
-- Create Event
CREATE TABLE event
(
2022-10-09 01:12:33 +02:00
website_id UUID,
session_id UUID,
event_id Nullable(UUID),
2022-11-08 03:03:27 +01:00
rev_id UInt32,
2022-09-12 18:55:34 +02:00
--session
hostname LowCardinality(String),
browser LowCardinality(String),
os LowCardinality(String),
device LowCardinality(String),
screen LowCardinality(String),
language LowCardinality(String),
2022-09-12 18:55:34 +02:00
country LowCardinality(String),
subdivision1 LowCardinality(String),
2023-02-16 18:52:07 +01:00
subdivision2 LowCardinality(String),
2023-02-15 18:40:49 +01:00
city String,
2022-09-12 18:55:34 +02:00
--pageview
2023-03-15 01:27:17 +01:00
url_path String,
url_query String,
referrer_path String,
referrer_query String,
referrer_domain String,
2023-02-15 18:40:49 +01:00
page_title String,
2022-09-12 18:55:34 +02:00
--event
event_type UInt32,
2022-09-12 18:55:34 +02:00
event_name String,
created_at DateTime('UTC')
)
2022-09-12 18:55:34 +02:00
engine = MergeTree
2022-10-12 06:02:15 +02:00
ORDER BY (website_id, session_id, created_at)
SETTINGS index_granularity = 8192;
2022-09-12 18:55:34 +02:00
CREATE TABLE event_queue (
2022-10-09 01:12:33 +02:00
website_id UUID,
session_id UUID,
event_id Nullable(UUID),
2022-11-08 03:03:27 +01:00
rev_id UInt32,
2023-02-15 18:40:49 +01:00
--session
hostname LowCardinality(String),
browser LowCardinality(String),
os LowCardinality(String),
device LowCardinality(String),
screen LowCardinality(String),
language LowCardinality(String),
2022-09-12 18:55:34 +02:00
country LowCardinality(String),
2023-02-16 18:52:07 +01:00
subdivision1 LowCardinality(String),
subdivision2 LowCardinality(String),
2023-02-15 18:40:49 +01:00
city String,
--pageview
2023-03-15 01:27:17 +01:00
url_path String,
url_query String,
referrer_path String,
referrer_query String,
referrer_domain String,
2023-02-15 18:40:49 +01:00
page_title String,
--event
event_type UInt32,
2022-08-17 00:27:59 +02:00
event_name String,
2022-09-12 18:55:34 +02:00
created_at DateTime('UTC')
)
ENGINE = Kafka
2022-10-12 08:10:32 +02:00
SETTINGS kafka_broker_list = 'domain:9092,domain:9093,domain:9094', -- input broker list
kafka_topic_list = 'event',
kafka_group_name = 'event_consumer_group',
kafka_format = 'JSONEachRow',
kafka_max_block_size = 1048576,
kafka_skip_broken_messages = 1;
CREATE MATERIALIZED VIEW event_queue_mv TO event AS
2022-10-12 06:02:15 +02:00
SELECT website_id,
session_id,
2022-10-09 01:12:33 +02:00
event_id,
2022-11-08 03:03:27 +01:00
rev_id,
2022-09-12 18:55:34 +02:00
hostname,
browser,
os,
device,
screen,
language,
country,
2023-02-16 18:52:07 +01:00
subdivision1,
subdivision2,
2023-02-15 18:40:49 +01:00
city,
2023-03-15 01:27:17 +01:00
url_path String,
url_query String,
referrer_path String,
referrer_query String,
referrer_domain String,
2023-02-15 18:40:49 +01:00
page_title,
event_type,
2022-08-17 00:27:59 +02:00
event_name,
2022-09-12 18:55:34 +02:00
created_at
FROM event_queue;