Skip to content

Commit

Permalink
add UUID field
Browse files Browse the repository at this point in the history
  • Loading branch information
aspicer committed Oct 17, 2024
1 parent 20d3fa6 commit a0b61d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
6 changes: 6 additions & 0 deletions posthog/hogql_queries/insights/funnels/funnel_trends_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@


class FunnelTrendsUDF(FunnelTrends):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# In base, these fields only get added if you're running an actors query
if "uuid" not in self._extra_event_fields:
self._extra_event_fields.append("uuid")

def get_step_counts_query(self):
max_steps = self.context.max_steps
return self._get_step_counts_query(
Expand Down
15 changes: 0 additions & 15 deletions posthog/hogql_queries/insights/funnels/funnel_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ def __init__(self, *args, **kwargs):
# In base, these fields only get added if you're running an actors query
if "uuid" not in self._extra_event_fields:
self._extra_event_fields.append("uuid")
for property in ("$session_id", "$window_id"):
if property not in self._extra_event_properties:
self._extra_event_properties.append(property)

# I think I can delete this
def get_step_counts_query(self):
max_steps = self.context.max_steps
return self._get_step_counts_query(
outer_select=[
*self._get_matching_event_arrays(max_steps),
],
inner_select=[
*self._get_matching_events(max_steps),
],
)

def conversion_window_limit(self) -> int:
return int(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
if(ifNull(greater(reached_from_step_count, 0), 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,
data.breakdown AS prop
FROM
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends_v1(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,
af_tuple.2 AS success_bool,
af_tuple.3 AS breakdown
af_tuple.3 AS breakdown,
aggregation_target AS aggregation_target
FROM
(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,
if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,
e.uuid AS uuid,
if(equals(e.event, 'step one'), 1, 0) AS step_0,
if(equals(e.event, 'step two'), 1, 0) AS step_1,
if(equals(e.event, 'step three'), 1, 0) AS step_2
Expand Down Expand Up @@ -53,14 +55,16 @@
if(ifNull(greater(reached_from_step_count, 0), 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,
data.breakdown AS prop
FROM
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'US/Pacific')), [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends_v1(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'US/Pacific')), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
toTimeZone(toDateTime(toUInt64(af_tuple.1), 'US/Pacific'), 'US/Pacific') AS entrance_period_start,
af_tuple.2 AS success_bool,
af_tuple.3 AS breakdown
af_tuple.3 AS breakdown,
aggregation_target AS aggregation_target
FROM
(SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,
if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,
e.uuid AS uuid,
if(equals(e.event, 'step one'), 1, 0) AS step_0,
if(equals(e.event, 'step two'), 1, 0) AS step_1,
if(equals(e.event, 'step three'), 1, 0) AS step_2
Expand Down Expand Up @@ -99,14 +103,16 @@
if(ifNull(greater(reached_from_step_count, 0), 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,
data.breakdown AS prop
FROM
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfWeek(timestamp, 0), 'UTC')), [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends_v1(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfWeek(timestamp, 0), 'UTC')), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,
arrayJoin(aggregate_funnel_array_trends(0, 3, 1209600, 'first_touch', 'ordered', [[]], events_array)) AS af_tuple,
toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,
af_tuple.2 AS success_bool,
af_tuple.3 AS breakdown
af_tuple.3 AS breakdown,
aggregation_target AS aggregation_target
FROM
(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,
if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,
e.uuid AS uuid,
if(equals(e.event, 'step one'), 1, 0) AS step_0,
if(equals(e.event, 'step two'), 1, 0) AS step_1,
if(equals(e.event, 'step three'), 1, 0) AS step_2
Expand Down

0 comments on commit a0b61d1

Please sign in to comment.