Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
SELECT
variation_id as variationID,
COUNT(DISTINCT user_id) as evaluationUser,
COUNT(id) as evaluationTotal
-- DISTINCT by event ID: BigQuery has no primary keys, so an at-least-once
-- Pub/Sub redelivery can append the same event twice. Each legitimate
-- event has its own unique ID, so this still counts repeat evaluations
-- by the same user.
COUNT(DISTINCT id) as evaluationTotal
FROM
`%s`
WHERE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
WITH grouped_by_user_evaluation AS (
SELECT
WITH deduped_events AS (
-- BigQuery has no primary keys, so an at-least-once Pub/Sub redelivery
-- can append the same event twice. Deduplicate by event ID before any
-- aggregation, otherwise duplicates inflate event_count and value_sum.
-- Duplicates are expected to be identical rows; DISTINCT collapses exact
-- duplicates for the columns used downstream without changing the
-- aggregation semantics.
SELECT DISTINCT
id,
user_id,
variation_id,
COUNT(id) as event_count,
IFNULL(SUM(value), 0) as value_sum
value
FROM
`%s`
WHERE
Expand All @@ -12,9 +18,18 @@ WITH grouped_by_user_evaluation AS (
AND goal_id = @goalID
AND feature_id = @featureID
AND feature_version = @featureVersion
GROUP BY
user_id,
variation_id
),
grouped_by_user_evaluation AS (
SELECT
user_id,
variation_id,
COUNT(id) as event_count,
IFNULL(SUM(value), 0) as value_sum
FROM
deduped_events
GROUP BY
user_id,
variation_id
),
cap_level AS (
-- Winsorization threshold: the configurable percentile
Expand Down
Loading