Skip to content

Instantly share code, notes, and snippets.

@CremboC
Last active July 31, 2019 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CremboC/f6434187bd2e5b9817ac3efb3073d76f to your computer and use it in GitHub Desktop.
Save CremboC/f6434187bd2e5b9817ac3efb3073d76f to your computer and use it in GitHub Desktop.
WITH base_users AS ( ... ),
country_users AS ( ... ),
todays_users AS (
SELECT
HLL_COUNT.INIT(user_id, 19) as sketch
FROM pageview_events
WHERE
_PARTITIONTIME = TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)
country = ...
)
SELECT
HLL_COUNT.MERGE(a) + HLL_COUNT.MERGE(b) - HLL_COUNT.MERGE(ab) AS users_size
FROM (
(
SELECT
sketch AS a,
NULL AS b,
sketch AS ab
FROM base_users
) UNION ALL (
SELECT
NULL AS a,
sketch AS b,
sketch AS ab
FROM country_users
) UNION ALL (
SELECT
sketch AS a,
sketch AS b,
sketch AS ab
FROM todays_users
WHERE "[Include_Todays_Data|1]"="1"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment