0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Trino (Presto) running UU

Posted at
WITH
data_source AS (
    SELECT user_id, g -- group
    FROM source_table
)

SELECT g
     , approx_distinct(user_id) as uu
     , cardinality(
         merge(approx_set(user_id)) OVER (order by g)
       ) as uu_accumurated
     , cardinality(
         merge(approx_set(user_id)) OVER (order by g)
       ) * 1.0000
       / (cardinality(merge(approx_set(user_id)) OVER ()))
        as uu_acccumurated_rate

Reference

Trino implements the approx_distinct() function using the HyperLogLog data structure.

merge(HyperLogLog) → HyperLogLog#

Returns the HyperLogLog of the aggregate union of the individual hll HyperLogLog structures.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?