@@ -9,61 +9,61 @@ TOKEN "dashboard" READ
99NODE timeseries
1010DESCRIPTION >
1111 Generate a timeseries for the specified time range, so we call fill empty data points.
12- Filters "future" data points.
12+ Filters "future" data points.
1313
1414SQL >
1515
1616 %
17- {% set _single_day = defined(date_from) and day_diff(date_from, date_to) == 0 %}
18- with
19- {% if defined(date_from) %}
20- toStartOfDay(
21- toDate(
22- {{
23- Date(
24- date_from,
25- description="Starting day for filtering a date range",
26- required=False,
27- )
28- }}
29- )
30- ) as start,
31- {% else %} toStartOfDay(timestampAdd(today(), interval -7 day)) as start,
32- {% end %}
33- {% if defined(date_to) %}
34- toStartOfDay(
35- toDate(
36- {{
37- Date(
38- date_to,
39- description="Finishing day for filtering a date range",
40- required=False,
17+ {% set _single_day = defined(date_from) and day_diff(date_from, date_to) == 0 %}
18+ with
19+ {% if defined(date_from) %}
20+ toStartOfDay(
21+ toDate(
22+ {{
23+ Date(
24+ date_from,
25+ description="Starting day for filtering a date range",
26+ required=False,
27+ )
28+ }}
29+ )
30+ ) as start,
31+ {% else %} toStartOfDay(timestampAdd(today(), interval -7 day)) as start,
32+ {% end %}
33+ {% if defined(date_to) %}
34+ toStartOfDay(
35+ toDate(
36+ {{
37+ Date(
38+ date_to,
39+ description="Finishing day for filtering a date range",
40+ required=False,
41+ )
42+ }}
43+ )
44+ ) as end
45+ {% else %} toStartOfDay(today()) as end
46+ {% end %}
47+ {% if _single_day %}
48+ select
49+ arrayJoin(
50+ arrayMap(
51+ x -> toDateTime(x),
52+ range(
53+ toUInt32(toDateTime(start)), toUInt32(timestampAdd(end, interval 1 day)), 3600
4154 )
42- }}
43- )
44- ) as end
45- {% else %} toStartOfDay(today()) as end
46- {% end %}
47- {% if _single_day %}
48- select
49- arrayJoin(
50- arrayMap(
51- x -> toDateTime(x),
52- range(
53- toUInt32(toDateTime(start)), toUInt32(timestampAdd(end, interval 1 day)), 3600
5455 )
55- )
56- ) as date
57- {% else %}
58- select
59- arrayJoin(
60- arrayMap(
61- x -> toDate(x),
62- range(toUInt32(start), toUInt32(timestampAdd(end, interval 1 day)), 24 * 3600)
63- )
64- ) as date
65- {% end %}
66- where date <= now()
56+ ) as date
57+ {% else %}
58+ select
59+ arrayJoin(
60+ arrayMap(
61+ x -> toDate(x),
62+ range(toUInt32(start), toUInt32(timestampAdd(end, interval 1 day)), 24 * 3600)
63+ )
64+ ) as date
65+ {% end %}
66+ where date <= now()
6767
6868
6969
@@ -74,37 +74,37 @@ DESCRIPTION >
7474SQL >
7575
7676 %
77- {% if defined(date_from) and day_diff(date_from, date_to) == 0 %}
78- select
79- toStartOfHour(timestamp) as date,
80- session_id,
81- uniq(session_id) as visits,
82- count() as pageviews,
83- case when min(timestamp) = max(timestamp) then 1 else 0 end as is_bounce,
84- max(timestamp) as latest_hit_aux,
85- min(timestamp) as first_hit_aux
86- from analytics_hits
87- where toDate(timestamp) = {{ Date(date_from) }}
88- group by toStartOfHour(timestamp), session_id
89- {% else %}
90- select
91- date,
92- session_id,
93- uniq(session_id) as visits,
94- countMerge(hits) as pageviews,
95- case when min(first_hit) = max(latest_hit) then 1 else 0 end as is_bounce,
96- max(latest_hit) as latest_hit_aux,
97- min(first_hit) as first_hit_aux
98- from analytics_sessions_mv
99- where
100- {% if defined(date_from) %} date >= {{ Date(date_from) }}
101- {% else %} date >= timestampAdd(today(), interval -7 day)
102- {% end %}
103- {% if defined(date_to) %} and date <= {{ Date(date_to) }}
104- {% else %} and date <= today()
105- {% end %}
106- group by date, session_id
107- {% end %}
77+ {% if defined(date_from) and day_diff(date_from, date_to) == 0 %}
78+ select
79+ toStartOfHour(timestamp) as date,
80+ session_id,
81+ uniq(session_id) as visits,
82+ count() as pageviews,
83+ case when min(timestamp) = max(timestamp) then 1 else 0 end as is_bounce,
84+ max(timestamp) as latest_hit_aux,
85+ min(timestamp) as first_hit_aux
86+ from analytics_hits
87+ where toDate(timestamp) = {{ Date(date_from) }}
88+ group by toStartOfHour(timestamp), session_id
89+ {% else %}
90+ select
91+ date,
92+ session_id,
93+ uniq(session_id) as visits,
94+ countMerge(hits) as pageviews,
95+ case when min(first_hit) = max(latest_hit) then 1 else 0 end as is_bounce,
96+ max(latest_hit) as latest_hit_aux,
97+ min(first_hit) as first_hit_aux
98+ from analytics_sessions_mv
99+ where
100+ {% if defined(date_from) %} date >= {{ Date(date_from) }}
101+ {% else %} date >= timestampAdd(today(), interval -7 day)
102+ {% end %}
103+ {% if defined(date_to) %} and date <= {{ Date(date_to) }}
104+ {% else %} and date <= today()
105+ {% end %}
106+ group by date, session_id
107+ {% end %}
108108
109109
110110
0 commit comments