Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(experiments): remove funnel step data from funnel queries (#66377)

Anders03b388ea4f37
diff --git a/products/experiments/backend/hogql_queries/experiment_funnel_query_builder.py b/products/experiments/backend/hogql_queries/experiment_funnel_query_builder.py
index 6401b8b0c1fd..953ea7258311 100644
--- a/products/experiments/backend/hogql_queries/experiment_funnel_query_builder.py
+++ b/products/experiments/backend/hogql_queries/experiment_funnel_query_builder.py
@@ -94,7 +94,6 @@ class FunnelQueryBuilder:
inject_step_columns = False
step_extracts = ", ".join(f"arrayElement(t.steps, {i + 1}) AS step_{i}" for i in range(num_steps))
entity_id_cast = "toUUID(t.entity_id)" if self._b.entity_key == "person_id" else "t.entity_id"
- session_id_col = "t.session_id AS session_id," if not self._b.funnel_steps_data_disabled else ""
# Filter by experiment date range: jobs can cover broader time ranges
# than the experiment for cache reusability, so we must filter on read.
@@ -112,7 +111,6 @@ class FunnelQueryBuilder:
{entity_id_cast} AS entity_id,
t.timestamp AS timestamp,
t.event_uuid AS uuid,
- {session_id_col}
{step_extracts}
FROM experiment_metric_events_preaggregated AS t
WHERE t.job_id IN {{metric_events_job_ids}}
@@ -131,20 +129,13 @@ class FunnelQueryBuilder:
)
"""
else:
- session_id_column = (
- """
- properties.$session_id AS session_id,"""
- if not self._b.funnel_steps_data_disabled
- else ""
- )
-
metric_events_cte_str = f"""
metric_events AS (
SELECT
{{entity_key}} AS entity_id,
{{variant_property}} as variant,
timestamp,
- uuid,{session_id_column}
+ uuid,
-- step_0, step_1, ... step_N columns added programmatically below
FROM events
WHERE ({{exposure_predicate}} OR {{funnel_steps_filter}})
@@ -172,25 +163,6 @@ class FunnelQueryBuilder:
else:
entity_id_join = "ON exposures.entity_id = metric_events.entity_id"
- if self._b.funnel_steps_data_disabled:
- # When steps data is disabled, we skip the expensive session/event maps and
- # the per-exposure columns that are only needed for steps_event_data.
- # The exposures CTE already deduplicates to one row per (entity_id, variant),
- # so removing these from GROUP BY doesn't change results.
- extra_select_columns = ""
- extra_group_by_columns = ""
- else:
- extra_select_columns = """,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- exposures.first_exposure_time AS exposure_timestamp,
- {uuid_to_session_map} AS uuid_to_session,
- {uuid_to_timestamp_map} AS uuid_to_timestamp"""
- extra_group_by_columns = """,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- exposures.first_exposure_time"""
-
ctes_sql = f"""
exposures AS (
{{exposure_select_query}}
@@ -202,7 +174,7 @@ class FunnelQueryBuilder:
SELECT
exposures.entity_id AS entity_id,
exposures.variant AS variant,
- {{funnel_aggregation}} AS value{extra_select_columns}
+ {{funnel_aggregation}} AS value
-- covariate_value added programmatically below when CUPED is enabled
FROM exposures
LEFT JOIN metric_events
@@ -210,7 +182,7 @@ class FunnelQueryBuilder:
{temporal_filter} -- Only for unordered: filters out events before exposure
GROUP BY
exposures.entity_id,
- exposures.variant{extra_group_by_columns}
+ exposures.variant
)
"""
@@ -245,10 +217,6 @@ class FunnelQueryBuilder:
"date_from": self._b.date_range_query.date_from_as_hogql(),
"date_to": self._b.date_range_query.date_to_as_hogql(),
}
- if not self._b.funnel_steps_data_disabled:
- placeholders["uuid_to_session_map"] = self.build_uuid_to_session_map()
- placeholders["uuid_to_timestamp_map"] = self.build_uuid_to_timestamp_map()
-
if self._b.metric_events_preaggregation_job_ids:
placeholders["metric_events_job_ids"] = ast.Constant(value=self._b.metric_events_preaggregation_job_ids)
placeholders["metric_events_team_id"] = ast.Constant(value=self._b.team.id)
@@ -270,7 +238,6 @@ class FunnelQueryBuilder:
countIf(entity_metrics.value.1 = {{num_steps_minus_1}}) AS total_sum_of_squares
-- CUPED aggregation columns added programmatically below
-- step_counts added programmatically below
- -- steps_event_data added programmatically below
-- breakdown columns added programmatically below
FROM entity_metrics
WHERE notEmpty(variant)
@@ -317,27 +284,6 @@ class FunnelQueryBuilder:
query.select.append(parse_expr(step_counts_expr))
- # For each step in the funnel, get at least 100 tuples of person_id, session_id, event uuid, and timestamp, that have
- # that step as their last step in the funnel.
- # For the users that have 0 matching steps in the funnel (-1), we return the event data for the exposure event.
- # This is skipped when funnel_steps_data_disabled is set, as it's expensive for high-traffic experiments.
- if not self._b.funnel_steps_data_disabled:
- event_uuids_exprs = []
- for i in range(1, num_steps + 1):
- event_uuids_expr = f"""
- groupArraySampleIf(100)(
- if(
- entity_metrics.value.2 != '',
- tuple(toString(entity_metrics.entity_id), uuid_to_session[entity_metrics.value.2], entity_metrics.value.2, toString(uuid_to_timestamp[entity_metrics.value.2])),
- tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(entity_metrics.exposure_timestamp))
- ),
- entity_metrics.value.1 = {i} - 1
- )
- """
- event_uuids_exprs.append(event_uuids_expr)
- event_uuids_exprs_sql = f"tuple({', '.join(event_uuids_exprs)}) as steps_event_data"
- query.select.append(parse_expr(event_uuids_exprs_sql))
-
return query
def build_funnel_query_optimized(self) -> ast.SelectQuery:
@@ -356,13 +302,6 @@ class FunnelQueryBuilder:
num_steps = len(self._b.metric.series) + 1 # +1 as we are including exposure criteria
- session_id_column = (
- """
- properties.$session_id AS session_id,"""
- if not self._b.funnel_steps_data_disabled
- else ""
- )
-
# CTE 1: base_events - single scan of events table
# WHERE admits both exposure and conversion events. Exclusion filters are
# embedded in step_0 only, not the WHERE clause, so conversion events from
@@ -373,7 +312,7 @@ class FunnelQueryBuilder:
{{entity_key}} AS entity_id,
{{variant_property}} AS variant_value,
timestamp,
- uuid,{session_id_column}
+ uuid,
-- step_0, step_1, ... step_N columns added programmatically below
FROM events
WHERE ({{exposure_predicate}} OR {{funnel_steps_filter}})
@@ -383,16 +322,6 @@ class FunnelQueryBuilder:
is_unordered_funnel = self._b.metric.funnel_order_type == StepOrderValue.UNORDERED
# CTE 2: entity_metrics - GROUP BY entity_id, no JOIN
- if self._b.funnel_steps_data_disabled:
- extra_select_columns = ""
- else:
- extra_select_columns = """,
- argMinIf(uuid, timestamp, step_0 = 1) AS exposure_event_uuid,
- argMinIf(session_id, timestamp, step_0 = 1) AS exposure_session_id,
- minIf(timestamp, step_0 = 1) AS exposure_timestamp,
- {uuid_to_session_map} AS uuid_to_session,
- {uuid_to_timestamp_map} AS uuid_to_timestamp"""
-
first_exposures_cte_str, temporal_join, having_clause = self.build_funnel_optimized_temporal_setup(
is_unordered_funnel
)
@@ -404,7 +333,7 @@ class FunnelQueryBuilder:
SELECT
base_events.entity_id AS entity_id,
{{variant_expr}} AS variant,
- {{funnel_aggregation}} AS value{extra_select_columns}
+ {{funnel_aggregation}} AS value
-- covariate_value added programmatically below when CUPED is enabled
FROM base_events
{temporal_join}
@@ -421,9 +350,6 @@ class FunnelQueryBuilder:
"funnel_aggregation": self.build_funnel_aggregation_expr_optimized(),
"num_steps_minus_1": ast.Constant(value=num_steps - 1),
}
- if not self._b.funnel_steps_data_disabled:
- placeholders["uuid_to_session_map"] = self.build_uuid_to_session_map_optimized()
- placeholders["uuid_to_timestamp_map"] = self.build_uuid_to_timestamp_map_optimized()
query = parse_select(
f"""
@@ -440,7 +366,6 @@ class FunnelQueryBuilder:
countIf(entity_metrics.value.1 = {{num_steps_minus_1}}) AS total_sum_of_squares
-- CUPED aggregation columns added programmatically below
-- step_counts added programmatically below
- -- steps_event_data added programmatically below
-- breakdown columns added programmatically below
FROM entity_metrics
WHERE notEmpty(variant)
@@ -493,24 +418,6 @@ class FunnelQueryBuilder:
query.select.append(parse_expr(step_counts_expr))
- # For each step in the funnel, get sample tuples of person_id, session_id, event uuid, and timestamp
- if not self._b.funnel_steps_data_disabled:
- event_uuids_exprs = []
- for i in range(1, num_steps + 1):
- event_uuids_expr = f"""
- groupArraySampleIf(100)(
- if(
- entity_metrics.value.2 != '',
- tuple(toString(entity_metrics.entity_id), uuid_to_session[entity_metrics.value.2], entity_metrics.value.2, toString(uuid_to_timestamp[entity_metrics.value.2])),
- tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(entity_metrics.exposure_timestamp))
- ),
- entity_metrics.value.1 = {i} - 1
- )
- """
- event_uuids_exprs.append(event_uuids_expr)
- event_uuids_exprs_sql = f"tuple({', '.join(event_uuids_exprs)}) as steps_event_data"
- query.select.append(parse_expr(event_uuids_exprs_sql))
-
return query
def build_funnel_optimized_temporal_setup(self, is_unordered_funnel: bool) -> tuple[str, str, str]:
@@ -709,22 +616,6 @@ class FunnelQueryBuilder:
assert isinstance(self._b.metric, ExperimentFunnelMetric)
return funnel_evaluation_expr(self._b.team, self._b.metric, events_alias="metric_events", include_exposure=True)
- def build_uuid_to_session_map(self) -> ast.Expr:
- """
- Creates a map from event UUID to session ID for funnel metrics.
- """
- return parse_expr(
- "mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), '')))"
- )
-
- def build_uuid_to_timestamp_map(self) -> ast.Expr:
- """
- Creates a map from event UUID to timestamp for funnel metrics.
- """
- return parse_expr(
- "mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(metric_events.timestamp, toDateTime(0))))"
- )
-
def has_datawarehouse_steps(self) -> bool:
"""
Check if funnel metric has any datawarehouse steps.
@@ -1043,22 +934,6 @@ class FunnelQueryBuilder:
assert isinstance(self._b.metric, ExperimentFunnelMetric)
return funnel_evaluation_expr(self._b.team, self._b.metric, events_alias="base_events", include_exposure=True)
- def build_uuid_to_session_map_optimized(self) -> ast.Expr:
- """
- UUID-to-session map for the optimized path. References base_events columns.
- """
- return parse_expr(
- "mapFromArrays(groupArray(coalesce(toString(uuid), '')), groupArray(coalesce(toString(session_id), '')))"
- )
-
- def build_uuid_to_timestamp_map_optimized(self) -> ast.Expr:
- """
- UUID-to-timestamp map for the optimized path. References base_events columns.
- """
- return parse_expr(
- "mapFromArrays(groupArray(coalesce(toString(uuid), '')), groupArray(coalesce(timestamp, toDateTime(0))))"
- )
-
def build_maturity_having_clause_optimized(self) -> Optional[ast.Expr]:
"""
Maturity HAVING clause for the optimized path.
diff --git a/products/experiments/backend/hogql_queries/experiment_query_builder.py b/products/experiments/backend/hogql_queries/experiment_query_builder.py
index 1d828ae1ec6f..e98c00de54b8 100644
--- a/products/experiments/backend/hogql_queries/experiment_query_builder.py
+++ b/products/experiments/backend/hogql_queries/experiment_query_builder.py
@@ -690,18 +690,6 @@ class ExperimentQueryBuilder:
"""
return self._funnel_query_builder().build_funnel_aggregation_expr()
- def _build_uuid_to_session_map(self) -> ast.Expr:
- """
- Creates a map from event UUID to session ID for funnel metrics.
- """
- return self._funnel_query_builder().build_uuid_to_session_map()
-
- def _build_uuid_to_timestamp_map(self) -> ast.Expr:
- """
- Creates a map from event UUID to timestamp for funnel metrics.
- """
- return self._funnel_query_builder().build_uuid_to_timestamp_map()
-
def _has_datawarehouse_steps(self) -> bool:
"""
Check if funnel metric has any datawarehouse steps.
@@ -801,18 +789,6 @@ class ExperimentQueryBuilder:
"""
return self._funnel_query_builder().build_funnel_aggregation_expr_optimized()
- def _build_uuid_to_session_map_optimized(self) -> ast.Expr:
- """
- UUID-to-session map for the optimized path. References base_events columns.
- """
- return self._funnel_query_builder().build_uuid_to_session_map_optimized()
-
- def _build_uuid_to_timestamp_map_optimized(self) -> ast.Expr:
- """
- UUID-to-timestamp map for the optimized path. References base_events columns.
- """
- return self._funnel_query_builder().build_uuid_to_timestamp_map_optimized()
-
def _build_maturity_having_clause_optimized(self) -> Optional[ast.Expr]:
"""
Maturity HAVING clause for the optimized path.
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
index 04ab8710b470..d57a9618643a 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr
@@ -6,7 +6,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
@@ -33,11 +32,6 @@
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp,
argMinIf(base_events.breakdown_value_1, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_1
FROM base_events
GROUP BY base_events.entity_id
@@ -47,10 +41,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant,
@@ -76,7 +67,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
coalesce(toString(events__person.properties___country), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
@@ -105,11 +95,6 @@
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 1209600, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp,
argMinIf(base_events.breakdown_value_1, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_1
FROM base_events
GROUP BY base_events.entity_id
@@ -119,11 +104,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant,
@@ -149,7 +130,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,
coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$os'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_2,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
@@ -177,11 +157,6 @@
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp,
argMinIf(base_events.breakdown_value_1, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_1,
argMinIf(base_events.breakdown_value_2, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_2
FROM base_events
@@ -193,10 +168,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant,
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr
index 88b6b69494ba..be22f649f5d9 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr
@@ -6,7 +6,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -32,12 +31,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -45,11 +39,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -74,7 +64,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -106,12 +95,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
INNER JOIN first_exposures ON equals(base_events.entity_id, first_exposures.entity_id)
WHERE greaterOrEquals(base_events.timestamp, toTimeZone(first_exposures.first_exposure_time, 'UTC'))
@@ -120,11 +104,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -149,7 +129,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'experiment-flag'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -175,12 +154,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -188,11 +162,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -217,7 +187,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-02 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-10 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -242,12 +211,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -255,10 +219,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -283,7 +244,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -309,12 +269,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -322,11 +277,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -351,7 +302,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -383,12 +333,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
INNER JOIN first_exposures ON equals(base_events.entity_id, first_exposures.entity_id)
WHERE greaterOrEquals(base_events.timestamp, toTimeZone(first_exposures.first_exposure_time, 'UTC'))
@@ -397,11 +342,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -426,7 +367,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -452,12 +392,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -465,11 +400,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -503,7 +434,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2
@@ -512,28 +442,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -559,7 +477,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -585,12 +502,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -598,11 +510,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -636,7 +544,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2
@@ -645,28 +552,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -692,7 +587,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -718,12 +612,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 86400, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 86400, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -731,11 +620,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -769,7 +654,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2
@@ -778,28 +662,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 86400, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 86400, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -825,7 +697,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'add to cart'), 1, 0) AS step_2,
@@ -855,12 +726,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(7, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2), multiply(4, base_events.step_3), multiply(5, base_events.step_4), multiply(6, base_events.step_5), multiply(7, base_events.step_6)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(7, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2), multiply(4, base_events.step_3), multiply(5, base_events.step_4), multiply(6, base_events.step_5), multiply(7, base_events.step_6)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -868,15 +734,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 6), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 6), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 4), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 5), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 6), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(4, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(4, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(5, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(5, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(6, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(6, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(7, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(7, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 4), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 5), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 6), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -910,7 +768,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2,
@@ -923,32 +780,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(7, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2), multiply(4, metric_events.step_3), multiply(5, metric_events.step_4), multiply(6, metric_events.step_5), multiply(7, metric_events.step_6)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(7, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2), multiply(4, metric_events.step_3), multiply(5, metric_events.step_4), multiply(6, metric_events.step_5), multiply(7, metric_events.step_6)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 6), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 6), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 4), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 5), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 6), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(4, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(4, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(5, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(5, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(6, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(6, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(7, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(7, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 4), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 5), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 6), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -974,7 +815,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2,
@@ -1001,12 +841,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(4, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2), multiply(4, base_events.step_3)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(4, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2), multiply(4, base_events.step_3)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -1014,12 +849,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 3), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 3), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(4, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(4, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1053,7 +883,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2,
@@ -1063,29 +892,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(4, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2), multiply(4, metric_events.step_3)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(4, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2), multiply(4, metric_events.step_3)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 3), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 3), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(4, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(4, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 3), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1111,7 +927,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(and(equals(events.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'wizard_step'), ''), 'null'), '^"|"$', ''), 'step_1'), 0)), 1, 0) AS step_1,
if(and(equals(events.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'wizard_step'), ''), 'null'), '^"|"$', ''), 'step_2'), 0)), 1, 0) AS step_2
@@ -1137,12 +952,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -1150,11 +960,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1188,7 +994,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2
@@ -1197,28 +1002,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1237,63 +1030,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestExperimentFunnelMetric.test_funnel_metric_with_steps_data_disabled
- '''
- WITH base_events AS
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
- toTimeZone(events.timestamp, 'UTC') AS timestamp,
- events.uuid AS uuid,
- and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
- if(equals(events.event, 'purchase'), 1, 0) AS step_1
- FROM events
- LEFT OUTER JOIN
- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
- person_distinct_id_overrides.distinct_id AS distinct_id
- FROM person_distinct_id_overrides
- WHERE equals(person_distinct_id_overrides.team_id, 99999)
- GROUP BY person_distinct_id_overrides.distinct_id
- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- LEFT JOIN
- (SELECT person.id AS id,
- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email
- FROM person
- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),
- (SELECT person.id AS id, max(person.version) AS version
- FROM person
- WHERE equals(person.team_id, 99999)
- GROUP BY person.id
- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
- WHERE and(equals(events.team_id, 99999), or(and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), equals(events.event, 'purchase'))))),
- entity_metrics AS
- (SELECT base_events.entity_id AS entity_id,
- if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
- FROM base_events
- GROUP BY base_events.entity_id
- HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
- SELECT entity_metrics.variant AS variant,
- count(entity_metrics.entity_id) AS num_users,
- countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
- countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
- FROM entity_metrics
- WHERE notEmpty(variant)
- GROUP BY entity_metrics.variant
- LIMIT 50000 SETTINGS readonly=2,
- max_execution_time=600,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=39728447488,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestExperimentFunnelMetric.test_funnel_metric_with_unordered_steps_0_direct
'''
WITH base_events AS
@@ -1301,7 +1037,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -1333,12 +1068,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
INNER JOIN first_exposures ON equals(base_events.entity_id, first_exposures.entity_id)
WHERE greaterOrEquals(base_events.timestamp, toTimeZone(first_exposures.first_exposure_time, 'UTC'))
@@ -1347,11 +1077,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1386,7 +1112,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -1412,28 +1137,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'unordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON and(equals(exposures.entity_id, metric_events.entity_id), greaterOrEquals(toTimeZone(metric_events.timestamp, 'UTC'), toTimeZone(exposures.first_exposure_time, 'UTC')))
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1459,7 +1172,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, '$pageview'), 1, 0) AS step_1,
if(equals(events.event, 'purchase'), 1, 0) AS step_2
@@ -1485,12 +1197,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 604800, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 604800, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING and(greater(countIf(equals(base_events.step_0, 1)), 0), lessOrEquals(plus(maxIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)), toIntervalSecond(604800)), parseDateTime64BestEffortOrNull('2020-01-15 12:00:00', 6, 'UTC'))))
@@ -1498,11 +1205,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1537,7 +1240,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1,
arrayElement(t.steps, 3) AS step_2
@@ -1546,28 +1248,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 604800, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 604800, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1630,28 +1320,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(toString(exposures.exposure_identifier), metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1714,28 +1392,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(toString(exposures.exposure_identifier), metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1798,28 +1464,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(toString(exposures.exposure_identifier), metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1882,28 +1536,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(toString(exposures.exposure_identifier), metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(3, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -1929,7 +1571,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -1954,12 +1595,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -1967,10 +1603,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2004,7 +1637,6 @@
(SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
toTimeZone(t.timestamp, 'UTC') AS timestamp,
t.event_uuid AS uuid,
- t.session_id AS session_id,
arrayElement(t.steps, 1) AS step_0,
arrayElement(t.steps, 2) AS step_1
FROM experiment_metric_events_preaggregated AS t
@@ -2012,27 +1644,16 @@
entity_metrics AS
(SELECT exposures.entity_id AS entity_id,
exposures.variant AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1)]))))))))[1] AS value,
- exposures.exposure_event_uuid AS exposure_event_uuid,
- exposures.exposure_session_id AS exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1)]))))))))[1] AS value
FROM exposures
LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)
GROUP BY exposures.entity_id,
- exposures.variant,
- exposures.exposure_event_uuid,
- exposures.exposure_session_id,
- toTimeZone(exposures.first_exposure_time, 'UTC'))
+ exposures.variant)
SELECT entity_metrics.variant AS variant,
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2058,7 +1679,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2083,12 +1703,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2096,10 +1711,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2169,7 +1781,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2184,12 +1795,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2197,10 +1803,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2342,7 +1945,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@earlierevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2357,12 +1959,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2370,10 +1967,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2515,7 +2109,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@laterevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2530,12 +2123,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2543,10 +2131,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2688,7 +2273,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2713,12 +2297,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2726,10 +2305,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -2871,7 +2447,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@earlierevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -2896,12 +2471,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -2909,10 +2479,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -3054,7 +2621,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@laterevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -3079,12 +2645,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -3092,10 +2653,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -3237,7 +2795,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -3245,12 +2802,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -3258,10 +2810,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -3403,7 +2952,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@earlierevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -3411,12 +2959,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -3424,10 +2967,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
@@ -3569,7 +3109,6 @@
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,
toTimeZone(events.timestamp, 'UTC') AS timestamp,
events.uuid AS uuid,
- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,
and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%@laterevent.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,
if(equals(events.event, 'purchase'), 1, 0) AS step_1
FROM events
@@ -3577,12 +3116,7 @@
entity_metrics AS
(SELECT base_events.entity_id AS entity_id,
if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,
- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,
- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,
- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,
- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,
- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp
+ arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value
FROM base_events
GROUP BY base_events.entity_id
HAVING greater(countIf(equals(base_events.step_0, 1)), 0))
@@ -3590,10 +3124,7 @@
count(entity_metrics.entity_id) AS num_users,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,
countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,
- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,
- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)
- and isNull(minus(2, 1))))) AS steps_event_data
+ tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts
FROM entity_metrics
WHERE notEmpty(variant)
GROUP BY entity_metrics.variant
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py
index 0990992d966f..98616947bc98 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py
@@ -1,5 +1,4 @@
import json
-import uuid
from datetime import datetime
from typing import cast
@@ -33,13 +32,11 @@ from posthog.schema import (
from posthog.constants import ExperimentNoResultsErrorKeys
from posthog.models.filters.utils import GroupTypeIndex
-from posthog.models.team.extensions import get_or_create_team_extension
from posthog.test.test_utils import create_group_type_mapping_without_created_at
from products.actions.backend.models.action import Action
from products.experiments.backend.hogql_queries.experiment_query_runner import ExperimentQueryRunner
from products.experiments.backend.hogql_queries.test.experiment_query_runner.base import ExperimentQueryRunnerBaseTest
-from products.experiments.backend.models.team_experiments_config import TeamExperimentsConfig
@override_settings(IN_UNIT_TESTING=True)
@@ -80,7 +77,6 @@ class TestExperimentFunnelMetric(ExperimentQueryRunnerBaseTest):
self._save_experiment_with_precomputation(experiment, use_precomputation)
# Control: 8 successes, 7 failures (15 total exposures)
- control_success_events = []
for i in range(15):
_create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)
_create_event(
@@ -95,11 +91,8 @@ class TestExperimentFunnelMetric(ExperimentQueryRunnerBaseTest):
},
)
if i < 8: # First 8 users make purchases
- event_uuid = str(uuid.uuid4())
- control_success_events.append(event_uuid)
_create_event(
team=self.team,
- event_uuid=event_uuid,
event="purchase",
distinct_id=f"user_control_{i}",
timestamp="2020-01-02T12:01:00Z",
@@ -167,156 +160,6 @@ class TestExperimentFunnelMetric(ExperimentQueryRunnerBaseTest):
# Check that we have the correct data for rendering the funnel chart
self.assertEqual(control_variant.step_counts, [8]) # contains data for funnel chart
- control_sampled_success_events = [s.event_uuid for s in control_variant.step_sessions[1]]
- self.assertEqual(sorted(control_success_events), sorted(control_sampled_success_events))
-
- @freeze_time("2020-01-01T12:00:00Z")
- @snapshot_clickhouse_queries
- def test_funnel_metric_with_steps_data_disabled(self):
- feature_flag = self.create_feature_flag()
- experiment = self.create_experiment(feature_flag=feature_flag)
- experiment.parameters = {"funnel_steps_data_disabled": True}
- experiment.save()
-
- feature_flag_property = f"$feature/{feature_flag.key}"
-
- metric = ExperimentFunnelMetric(
- series=[EventsNode(event="purchase")],
- )
-
- experiment_query = ExperimentQuery(
- experiment_id=experiment.id,
- kind="ExperimentQuery",
- metric=metric,
- )
-
- experiment.metrics = [metric.model_dump(mode="json")]
- experiment.save()
-
- for i in range(15):
- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)
- _create_event(
- team=self.team,
- event="$feature_flag_called",
- distinct_id=f"user_control_{i}",
- timestamp="2020-01-02T12:00:00Z",
- properties={
- feature_flag_property: "control",
- "$feature_flag_response": "control",
- "$feature_flag": feature_flag.key,
- },
- )
- if i < 8:
- _create_event(
- team=self.team,
- event="purchase",
- distinct_id=f"user_control_{i}",
- timestamp="2020-01-02T12:01:00Z",
- properties={feature_flag_property: "control"},
- )
-
- for i in range(15):
- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)
- _create_event(
- team=self.team,
- event="$feature_flag_called",
- distinct_id=f"user_test_{i}",
- timestamp="2020-01-02T12:00:00Z",
- properties={
- feature_flag_property: "test",
- "$feature_flag_response": "test",
- "$feature_flag": feature_flag.key,
- },
- )
- if i < 10:
- _create_event(
- team=self.team,
- event="purchase",
- distinct_id=f"user_test_{i}",
- timestamp="2020-01-02T12:01:00Z",
- properties={feature_flag_property: "test"},
- )
-
- flush_persons_and_events()
-
- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)
- result = query_runner.calculate()
-
- control_variant = result.baseline
- test_variant = result.variant_results[0]
-
- # Step counts should still be present
- self.assertEqual(control_variant.step_counts, [8])
- self.assertEqual(test_variant.step_counts, [10])
-
- # Step sessions should be absent
- self.assertIsNone(control_variant.step_sessions)
- self.assertIsNone(test_variant.step_sessions)
-
- @parameterized.expand(
- [
- # (name, experiment_parameters, team_config_value, expect_disabled)
- ("team_config_only", {}, True, True),
- ("experiment_overrides_team", {"funnel_steps_data_disabled": False}, True, False),
- ]
- )
- @freeze_time("2020-01-01T12:00:00Z")
- def test_funnel_metric_steps_data_disabled_team_config(
- self, name, experiment_parameters, team_config_value, expect_disabled
- ):
- feature_flag = self.create_feature_flag()
- experiment = self.create_experiment(feature_flag=feature_flag)
- experiment.parameters = experiment_parameters
- experiment.save()
-
- config = get_or_create_team_extension(self.team, TeamExperimentsConfig)
- config.funnel_steps_data_disabled = team_config_value
- config.save()
-
- feature_flag_property = f"$feature/{feature_flag.key}"
- metric = ExperimentFunnelMetric(series=[EventsNode(event="purchase")])
- experiment_query = ExperimentQuery(experiment_id=experiment.id, kind="ExperimentQuery", metric=metric)
- experiment.metrics = [metric.model_dump(mode="json")]
- experiment.save()
-
- for variant, convert_count in (("control", 8), ("test", 10)):
- for i in range(15):
- distinct_id = f"user_{variant}_{i}"
- _create_person(distinct_ids=[distinct_id], team_id=self.team.pk)
- _create_event(
- team=self.team,
- event="$feature_flag_called",
- distinct_id=distinct_id,
- timestamp="2020-01-02T12:00:00Z",
- properties={
- feature_flag_property: variant,
- "$feature_flag_response": variant,
- "$feature_flag": feature_flag.key,
- },
- )
- if i < convert_count:
- _create_event(
- team=self.team,
- event="purchase",
- distinct_id=distinct_id,
- timestamp="2020-01-02T12:01:00Z",
- properties={feature_flag_property: variant},
- )
-
- flush_persons_and_events()
-
- result = ExperimentQueryRunner(query=experiment_query, team=self.team).calculate()
- control_variant = result.baseline
- test_variant = result.variant_results[0]
-
- self.assertEqual(control_variant.step_counts, [8])
- self.assertEqual(test_variant.step_counts, [10])
- if expect_disabled:
- self.assertIsNone(control_variant.step_sessions)
- self.assertIsNone(test_variant.step_sessions)
- else:
- self.assertIsNotNone(control_variant.step_sessions)
- self.assertIsNotNone(test_variant.step_sessions)
@parameterized.expand(
[