forked from llooker/demo_segment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_aliases_mapping.view.lkml
46 lines (40 loc) · 1.02 KB
/
1_aliases_mapping.view.lkml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
view: aliases_mapping {
derived_table: {
sql_trigger_value: select current_date ;;
sortkeys: ["tenantbase_visitor_id", "alias"]
distribution: "alias"
sql: with
all_mappings as (
select anonymous_id
, user_id
, received_at as received_at
from production.tracks
union
select user_id
, null
, received_at
from production.tracks
)
select
distinct anonymous_id as alias
, first_value(user_id ignore nulls) OVER ()
, coalesce(first_value(user_id ignore nulls)
over(
partition by anonymous_id
order by received_at
rows between unbounded preceding and unbounded following),anonymous_id) as tenantbase_visitor_id
from all_mappings
;;
}
# Anonymous ID
dimension: alias {
primary_key: yes
type: string
sql: ${TABLE}.alias ;;
}
# User ID
dimension: tenantbase_visitor_id {
type: string
sql: ${TABLE}.tenantbase_visitor_id ;;
}
}