data layer
This commit is contained in:
60
data-layer/infra/clickhouse/event_explorer.sql.tmpl
Normal file
60
data-layer/infra/clickhouse/event_explorer.sql.tmpl
Normal file
@@ -0,0 +1,60 @@
|
||||
-- Event Explorer -- filter raw events for one workspace inside a time range.
|
||||
--
|
||||
-- Required parameters (clickhouse.Named):
|
||||
-- workspace_id : String
|
||||
-- from : DateTime64(3,'UTC')
|
||||
-- to : DateTime64(3,'UTC')
|
||||
-- limit : UInt32
|
||||
-- offset : UInt32
|
||||
--
|
||||
-- Optional parameters (controlled by template flags):
|
||||
-- user_id : String (when .HasUserID)
|
||||
-- anonymous_id : String (when .HasAnonymousID)
|
||||
-- event : String (when .HasEventName, events_track only)
|
||||
--
|
||||
-- Template inputs:
|
||||
-- .Table : whitelisted enum (events_track | events_identify | events_page | events_group)
|
||||
-- .HasUserID : bool
|
||||
-- .HasAnonymousID : bool
|
||||
-- .HasEventName : bool
|
||||
SELECT
|
||||
workspace_id,
|
||||
source_id,
|
||||
message_id,
|
||||
anonymous_id,
|
||||
user_id,
|
||||
{{- if eq .Table "events_track" }}
|
||||
event,
|
||||
{{- end }}
|
||||
{{- if eq .Table "events_page" }}
|
||||
name,
|
||||
category,
|
||||
path,
|
||||
url,
|
||||
{{- end }}
|
||||
{{- if eq .Table "events_group" }}
|
||||
group_id,
|
||||
{{- end }}
|
||||
timestamp,
|
||||
received_at,
|
||||
{{- if or (eq .Table "events_identify") (eq .Table "events_group") }}
|
||||
traits
|
||||
{{- else }}
|
||||
properties
|
||||
{{- end }}
|
||||
FROM {{ .Table }}
|
||||
WHERE workspace_id = {workspace_id:String}
|
||||
AND received_at >= {from:DateTime64(3,'UTC')}
|
||||
AND received_at < {to:DateTime64(3,'UTC')}
|
||||
{{- if .HasUserID }}
|
||||
AND user_id = {user_id:String}
|
||||
{{- end }}
|
||||
{{- if .HasAnonymousID }}
|
||||
AND anonymous_id = {anonymous_id:String}
|
||||
{{- end }}
|
||||
{{- if .HasEventName }}
|
||||
AND event = {event:String}
|
||||
{{- end }}
|
||||
ORDER BY received_at DESC
|
||||
LIMIT {limit:UInt32}
|
||||
OFFSET {offset:UInt32}
|
||||
Reference in New Issue
Block a user