remove unused session_data_pivot table
This commit is contained in:
@@ -55,60 +55,6 @@ SELECT
|
||||
FROM umami.event_data
|
||||
GROUP BY website_id, session_id, event_id, event_name, url_path, created_at;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS umami.session_data_pivot
|
||||
(
|
||||
website_id UUID,
|
||||
session_id UUID,
|
||||
distinct_id String,
|
||||
created_year_month UInt32,
|
||||
created_at AggregateFunction(max, DateTime('UTC')),
|
||||
property_keys AggregateFunction(groupArray, String),
|
||||
property_values AggregateFunction(groupArray, String),
|
||||
property_types AggregateFunction(groupArray, UInt32)
|
||||
)
|
||||
ENGINE = AggregatingMergeTree()
|
||||
PARTITION BY created_year_month
|
||||
ORDER BY (website_id, session_id, distinct_id)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS umami.session_data_pivot_mv
|
||||
TO umami.session_data_pivot
|
||||
AS SELECT
|
||||
website_id,
|
||||
session_id,
|
||||
ifNull(distinct_id, '') AS distinct_id,
|
||||
toYYYYMM(max(session_data.created_at)) AS created_year_month,
|
||||
maxState(session_data.created_at) AS created_at,
|
||||
groupArrayState(data_key) AS property_keys,
|
||||
groupArrayState(multiIf(
|
||||
data_type IN (1, 3, 5), ifNull(string_value, ''),
|
||||
data_type = 2, toString(ifNull(number_value, 0)),
|
||||
data_type = 4, toString(ifNull(date_value, toDateTime(0))),
|
||||
''
|
||||
)) AS property_values,
|
||||
groupArrayState(data_type) AS property_types
|
||||
FROM umami.session_data
|
||||
GROUP BY website_id, session_id, distinct_id;
|
||||
|
||||
-- Backfill existing session data
|
||||
INSERT INTO umami.session_data_pivot
|
||||
SELECT
|
||||
website_id,
|
||||
session_id,
|
||||
ifNull(distinct_id, '') AS distinct_id,
|
||||
toYYYYMM(max(session_data.created_at)) AS created_year_month,
|
||||
maxState(session_data.created_at) AS created_at,
|
||||
groupArrayState(data_key),
|
||||
groupArrayState(multiIf(
|
||||
data_type IN (1, 3, 5), ifNull(string_value, ''),
|
||||
data_type = 2, toString(ifNull(number_value, 0)),
|
||||
data_type = 4, toString(ifNull(date_value, toDateTime(0))),
|
||||
''
|
||||
)),
|
||||
groupArrayState(data_type)
|
||||
FROM umami.session_data
|
||||
GROUP BY website_id, session_id, distinct_id;
|
||||
|
||||
ALTER TABLE umami.session_data
|
||||
MODIFY SETTING deduplicate_merge_projection_mode = 'drop';
|
||||
|
||||
|
||||
@@ -364,38 +364,3 @@ AS SELECT
|
||||
FROM umami.event_data
|
||||
GROUP BY website_id, session_id, event_id, event_name, url_path, created_at;
|
||||
|
||||
-- Create session_data_pivot
|
||||
CREATE TABLE IF NOT EXISTS umami.session_data_pivot
|
||||
(
|
||||
website_id UUID,
|
||||
session_id UUID,
|
||||
distinct_id String,
|
||||
created_year_month UInt32,
|
||||
created_at AggregateFunction(max, DateTime('UTC')),
|
||||
property_keys AggregateFunction(groupArray, String),
|
||||
property_values AggregateFunction(groupArray, String),
|
||||
property_types AggregateFunction(groupArray, UInt32)
|
||||
)
|
||||
ENGINE = AggregatingMergeTree()
|
||||
PARTITION BY created_year_month
|
||||
ORDER BY (website_id, session_id, distinct_id)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS umami.session_data_pivot_mv
|
||||
TO umami.session_data_pivot
|
||||
AS SELECT
|
||||
website_id,
|
||||
session_id,
|
||||
ifNull(distinct_id, '') AS distinct_id,
|
||||
toYYYYMM(max(session_data.created_at)) AS created_year_month,
|
||||
maxState(session_data.created_at) AS created_at,
|
||||
groupArrayState(data_key) AS property_keys,
|
||||
groupArrayState(multiIf(
|
||||
data_type IN (1, 3, 5), ifNull(string_value, ''),
|
||||
data_type = 2, toString(ifNull(number_value, 0)),
|
||||
data_type = 4, toString(ifNull(date_value, toDateTime(0))),
|
||||
''
|
||||
)) AS property_values,
|
||||
groupArrayState(data_type) AS property_types
|
||||
FROM umami.session_data
|
||||
GROUP BY website_id, session_id, distinct_id;
|
||||
|
||||
Reference in New Issue
Block a user