forked from llooker/demo_segment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_B_mapped_events.view.lkml
89 lines (77 loc) · 2.19 KB
/
_B_mapped_events.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
view: mapped_events {
derived_table: {
sortkeys: ["event_id"]
distribution: "tenantbase_visitor_id"
sql_trigger_value: SELECT current_date ;;
sql: SELECT *
, datediff(minutes, lag("timestamp") OVER(PARTITION BY tenantbase_visitor_id ORDER BY "timestamp"), "timestamp") AS idle_time_minutes
FROM (
SELECT
CONCAT(t."timestamp", t.uuid) || '-t' AS event_id
, COALESCE(a2v.tenantbase_visitor_id, a2v.alias) AS tenantbase_visitor_id
, t.anonymous_id
, t.uuid
, t."timestamp"
, NULL AS referrer
, 'tracks' AS event_source
FROM production.tracks AS t
INNER JOIN ${page_aliases_mapping.SQL_TABLE_NAME} AS a2v
ON a2v.alias = COALESCE(t.user_id, t.anonymous_id)
UNION ALL
SELECT
CONCAT(t."timestamp", t.uuid) || '-p' AS event_id
, COALESCE(a2v.tenantbase_visitor_id, a2v.alias) AS tenantbase_visitor_id
, t.anonymous_id
, t.uuid
, t."timestamp"
, t.referrer AS referrer
, 'pages' AS event_source
FROM production.pages AS t
INNER JOIN ${page_aliases_mapping.SQL_TABLE_NAME} AS a2v
ON a2v.alias = coalesce(t.user_id, t.anonymous_id)
) AS e
;;
}
dimension: event_id {
sql: ${TABLE}.event_id ;;
}
dimension: tenantbase_visitor_id {
type: string
sql: ${TABLE}.tenantbase_visitor_id ;;
}
dimension: anonymous_id {
sql: ${TABLE}.anonymous_id ;;
}
dimension: uuid {
sql: ${TABLE}.uuid ;;
}
dimension_group: timestamp {
type: time
timeframes: [time, date, week, month]
sql: ${TABLE}."timestamp" ;;
}
dimension: event {
sql: ${TABLE}.event ;;
}
dimension: referrer {
sql: ${TABLE}.referrer ;;
}
dimension: event_source {
sql: ${TABLE}.event_source ;;
}
dimension: idle_time_minutes {
type: number
sql: ${TABLE}.idle_time_minutes ;;
}
set: detail {
fields: [
event_id,
tenantbase_visitor_id,
timestamp_date,
event,
referrer,
event_source,
idle_time_minutes
]
}
}