: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(clickhouse): Bumped CH compatibility to 26.3 (#60421)
Rory Shanksd5d6df44d6ab
diff --git a/.github/clickhouse-versions.json b/.github/clickhouse-versions.jsonindex ce97d32dc6bf..110e67707cb7 100644--- a/.github/clickhouse-versions.json+++ b/.github/clickhouse-versions.json@@ -1,6 +1,6 @@{- "production_eu": "clickhouse/clickhouse-server:25.12.8",- "production_us": "clickhouse/clickhouse-server:25.12.8",- "local": "clickhouse/clickhouse-server:26.3.10.60",- "oldest_supported": "clickhouse/clickhouse-server:25.12.8"+ "production_eu": "clickhouse/clickhouse-server:26.3.10",+ "production_us": "clickhouse/clickhouse-server:26.3.10",+ "local": "clickhouse/clickhouse-server:26.3.10",+ "oldest_supported": "clickhouse/clickhouse-server:26.3.10"}diff --git a/docker/clickhouse/users-dev.xml b/docker/clickhouse/users-dev.xmlindex dc24e9f422f9..69a516d0506b 100644--- a/docker/clickhouse/users-dev.xml+++ b/docker/clickhouse/users-dev.xml@@ -22,7 +22,20 @@<allow_nondeterministic_mutations>1</allow_nondeterministic_mutations>- <compatibility>25.8</compatibility>+ <compatibility>26.3</compatibility>+ <!-- The funnel correlation query intentionally uses a materialized CTE+ to avoid re-running the actor subquery across UNION branches. -->+ <enable_materialized_cte>1</enable_materialized_cte>+ <!-- Keep inserts synchronous. Production configures async inserts explicitly+ (currently off); the 26.3 compatibility default turns them on, which makes+ every single-row test insert wait for the async flush and slows the suite. -->+ <async_insert>0</async_insert>+ <!-- 26.3 enables rewriting `col = ''` / `col != ''` into emptiness checks that+ skip DEFAULT-expression evaluation on parts written before the column was+ added. Materialized property columns rely on that evaluation for+ is_set / is_not_set filters on rows older than their backfill window, so+ pin the rewrite off until ClickHouse honors DEFAULTs there. -->+ <optimize_empty_string_comparisons>0</optimize_empty_string_comparisons><distributed_product_mode>global</distributed_product_mode><enable_parallel_replicas>0</enable_parallel_replicas><max_parallel_replicas>1</max_parallel_replicas>diff --git a/docker/clickhouse/users.xml b/docker/clickhouse/users.xmlindex 0462e8055fe3..43675e6fcc1b 100644--- a/docker/clickhouse/users.xml+++ b/docker/clickhouse/users.xml@@ -23,7 +23,20 @@<allow_nondeterministic_mutations>1</allow_nondeterministic_mutations>- <compatibility>25.8</compatibility>+ <compatibility>26.3</compatibility>+ <!-- The funnel correlation query intentionally uses a materialized CTE+ to avoid re-running the actor subquery across UNION branches. -->+ <enable_materialized_cte>1</enable_materialized_cte>+ <!-- Keep inserts synchronous. Production configures async inserts explicitly+ (currently off); the 26.3 compatibility default turns them on, which makes+ every single-row test insert wait for the async flush and slows the suite. -->+ <async_insert>0</async_insert>+ <!-- 26.3 enables rewriting `col = ''` / `col != ''` into emptiness checks that+ skip DEFAULT-expression evaluation on parts written before the column was+ added. Materialized property columns rely on that evaluation for+ is_set / is_not_set filters on rows older than their backfill window, so+ pin the rewrite off until ClickHouse honors DEFAULTs there. -->+ <optimize_empty_string_comparisons>0</optimize_empty_string_comparisons><distributed_product_mode>global</distributed_product_mode><enable_parallel_replicas>0</enable_parallel_replicas><max_parallel_replicas>1</max_parallel_replicas>diff --git a/posthog/hogql/printer/clickhouse.py b/posthog/hogql/printer/clickhouse.pyindex 5ce2abc69e64..9d3134a3bd5f 100644--- a/posthog/hogql/printer/clickhouse.py+++ b/posthog/hogql/printer/clickhouse.py@@ -66,6 +66,19 @@ INLINE_SENTINEL_LITERALS = frozenset({"", "null", "true", "false", '^"|"$'})class ClickHousePrinter(BasePrinter):DIALECT_NAME: ClassVar[HogQLDialect] = "clickhouse"+ def visit_cte(self, node: ast.CTE):+ if node.materialized is False:+ raise ImpossibleASTError("ClickHouse does not support NOT MATERIALIZED CTEs")+ if node.using_key is not None:+ raise ImpossibleASTError(f"CTE USING KEY is not supported in the '{self.DIALECT_NAME}' dialect")++ if node.cte_type == "subquery":+ if node.columns is not None:+ raise NotImplementedError("CTE column name lists are not supported in this dialect")+ materialized = " MATERIALIZED" if node.materialized else ""+ return f"{self._print_identifier(node.name)} AS{materialized} {self.visit(node.expr)}"+ return f"{self.visit(node.expr)} AS {self._print_identifier(node.name)}"+def _render_set_query_limit_percent(self, limit: ast.Expr, limit_str: str) -> str:return str(self._limit_percent_constant_value(limit))diff --git a/posthog/hogql/printer/hogql.py b/posthog/hogql/printer/hogql.pyindex f40c045e81fe..dd31c4ca4d7b 100644--- a/posthog/hogql/printer/hogql.py+++ b/posthog/hogql/printer/hogql.py@@ -15,6 +15,24 @@ class HogQLPrinter(BasePrinter):DIALECT_NAME: ClassVar[HogQLDialect] = "hogql"+ def visit_cte(self, node: ast.CTE) -> str:+ materialization_hint = (+ "" if node.materialized is None else ("MATERIALIZED " if node.materialized else "NOT MATERIALIZED ")+ )++ if node.cte_type == "subquery":+ columns_sql = (+ "" if node.columns is None else f"({', '.join(self._print_identifier(col) for col in node.columns)})"+ )+ using_key_sql = (+ ""+ if node.using_key is None+ else f" USING KEY ({', '.join(self._print_identifier(col) for col in node.using_key)})"+ )+ return f"{self._print_identifier(node.name)}{columns_sql}{using_key_sql} AS {materialization_hint}{self.visit(node.expr)}"++ return super().visit_cte(node)+def visit_property_access(self, node: ast.PropertyAccess) -> str:# A lowered `properties.$x` read prints back as the HogQL property chain it came from, not the ClickHouse# `JSONExtractRaw(...)` form the base renderer emits — so `dialect="hogql"` stays valid, re-parseable HogQLdiff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex 4ead4cd10703..9ef6628065b6 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -4123,15 +4123,27 @@ class TestPrinter(BaseTest):self._expr("accurateCast('1', concat('Int', '64'))")self.assertIn("constant string type name", str(ctx.exception))- def test_cte_materialization_hint_not_supported(self):- with self.assertRaises(ImpossibleASTError) as ctx:+ def test_cte_materialization_hint_materialized(self):+ self.assertEqual(self._select("""WITH some_cte AS MATERIALIZED (SELECT event FROM events)SELECT event FROM some_cte""",+ ),+ f"WITH some_cte AS MATERIALIZED (SELECT events.event AS event FROM events WHERE equals(events.team_id, {self.team.pk})) "+ "SELECT some_cte.event AS event FROM some_cte LIMIT 50000",+ )++ def test_cte_materialization_hint_not_materialized_not_supported(self):+ with self.assertRaises(ImpossibleASTError) as ctx:+ self._select(+ """+ WITH some_cte AS NOT MATERIALIZED (SELECT event FROM events)+ SELECT event FROM some_cte+ """,)- self.assertIn("not supported", str(ctx.exception))+ self.assertIn("NOT MATERIALIZED", str(ctx.exception))def test_cte_column_name_list_not_supported(self):with self.assertRaises(NotImplementedError):diff --git a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py b/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.pyindex 328e2948bbb1..f16392937a25 100644--- a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py+++ b/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py@@ -490,7 +490,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsevent_correlation_query = parse_select(f"""WITH- funnel_actors AS (+ funnel_actors AS MATERIALIZED ({{funnel_persons_query}}),{{date_from}} AS date_from,@@ -523,14 +523,6 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationRespons-- the funnel people CTE and count distinct actor_idsUNION ALL- -- :HACKY: HogQL does not have access to a CTE in the second union query, thus- -- we're repeating the CTE here. This likely is a big hit on query performance.- WITH- funnel_actors AS (- {{funnel_persons_query}}- ),- {target_step} AS target_step-SELECT-- We're not using WITH TOTALS because the resulting queries are-- not runnable in Metabase@@ -564,7 +556,8 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsraise ValidationError("Event Property Correlation expects atleast one event name to run correlation on")funnel_persons_query = self.get_funnel_actors_cte()- event_join_query = self._get_events_join_query()+ filtered_events_cte = self._get_filtered_events_cte("AND event IN {event_names}")+ event_right_join_query = self._get_events_right_join_query()target_step = self.context.max_stepsfunnel_step_names = self._get_funnel_step_names()date_from = self._date_range().date_from_as_hogql()@@ -579,19 +572,30 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsf"'{self.AUTOCAPTURE_EVENT_TYPE}'","properties",allow_denormalized_props=False,+ table_alias="event_table",)- array_join_query = f"""- 'elements_chain' as prop_key,- concat({event_type_expression}, '{self.ELEMENTS_DIVIDER}', elements_chain) as prop_value,- tuple(prop_key, prop_value) as prop+ # With join_use_nulls=0, unmatched join rows yield '' for event_table.event+ # rather than NULL, so guard with empty() instead of isNull().+ event_property_array_query = f"""+ if(+ empty(event_table.event),+ [],+ [tuple(event_table.event, 'elements_chain', concat({event_type_expression}, '{self.ELEMENTS_DIVIDER}', event_table.elements_chain))]+ )"""else:- array_join_query = f"""- arrayJoin(JSONExtractKeysAndValues(properties, 'String')) as prop+ event_property_array_query = """+ if(+ empty(event_table.event),+ [],+ arrayMap(prop -> tuple(event_table.event, prop.1, prop.2), JSONExtractKeysAndValues(event_table.properties, 'String'))+ )"""# Build exclude clause only if there are properties to exclude- exclude_clause = "AND prop.1 NOT IN {exclude_props}" if exclude_property_names else ""+ exclude_clause = (+ "AND (prop.1 = {total_identifier} OR prop.2 NOT IN {exclude_props})" if exclude_property_names else ""+ )query = parse_select(f"""@@ -599,61 +603,37 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsfunnel_actors AS ({{funnel_persons_query}}),- {{date_from}} AS date_from,- {{date_to}} AS date_to,- {target_step} AS target_step,- {funnel_step_names} AS funnel_step_names+ filtered_events AS (+ {filtered_events_cte}+ ),+ {target_step} AS target_step- SELECT concat(event_name, '::', prop.1, '::', prop.2) as name,+ SELECT+ if(prop.1 = {{total_identifier}}, {{total_identifier}}, concat(prop.1, '::', prop.2, '::', prop.3)) as name,countDistinctIf(actor_id, steps = target_step) as success_count,countDistinctIf(actor_id, steps <> target_step) as failure_countFROM (SELECTfunnel_actors.actor_id as actor_id,funnel_actors.steps as steps,- event.event as event_name,- -- Same as what we do in $all property queries- {array_join_query}- FROM events AS event- {event_join_query}- AND event.event IN {{event_names}}+ arrayJoin(arrayConcat(+ [tuple({{total_identifier}}, '', '')],+ {event_property_array_query}+ )) as prop+ FROM filtered_events AS event_table+ {event_right_join_query})GROUP BY name, prop-- Discard high cardinality / low hits properties-- This removes the long tail of random properties with empty, null, or very small values- HAVING (success_count + failure_count) > 2+ HAVING (name = {{total_identifier}} OR (success_count + failure_count) > 2){exclude_clause}-- UNION ALL- -- To get the total success/failure numbers, we do an aggregation on- -- the funnel people CTE and count distinct actor_ids-- -- :HACKY: HogQL does not have access to a CTE in the second union query, thus- -- we're repeating the CTE here. This likely is a big hit on query performance.- WITH- funnel_actors AS (- {{funnel_persons_query}}- ),- {target_step} AS target_step-- SELECT- {{total_identifier}} as name,-- countDistinctIf(- funnel_actors.actor_id,- funnel_actors.steps = target_step- ) AS success_count,-- countDistinctIf(- funnel_actors.actor_id,- funnel_actors.steps <> target_step- ) AS failure_count- FROM funnel_actors""",placeholders={"funnel_persons_query": funnel_persons_query,"date_from": date_from,"date_to": date_to,+ "funnel_step_names": ast.Tuple(exprs=[ast.Constant(value=e) for e in funnel_step_names]),"event_names": ast.Tuple(exprs=[ast.Constant(value=e) for e in event_names]),"total_identifier": ast.Constant(value=self.TOTAL_IDENTIFIER),**(@@ -675,7 +655,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponstarget_step = self.context.max_stepsexclude_property_names = self.query.funnelCorrelationExcludeNames or []- prop_clause = self._get_properties_prop_clause()+ prop_clause = self._get_properties_prop_clause(include_total=True)aggregation_join_query = self._get_aggregation_join_query()# Build exclude names as AST array for safe escaping@@ -689,7 +669,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationRespons),{target_step} AS target_stepSELECT- concat(prop.1, '::', prop.2) as name,+ if(prop.1 = {{total_identifier}}, {{total_identifier}}, concat(prop.1, '::', prop.2)) as name,-- We generate a unique identifier for each property value as: PropertyName::ValuecountDistinctIf(actor_id, steps = target_step) AS success_count,countDistinctIf(actor_id, steps <> target_step) AS failure_count@@ -728,23 +708,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationRespons) aggregation_target_with_props-- Group by the tuple items: (property_name, property_value) generated by zipGROUP BY prop.1, prop.2- HAVING prop.1 NOT IN {{exclude_names}}-- UNION ALL-- -- :HACKY: HogQL does not have access to a CTE in the second union query, thus- -- we're repeating the CTE here. This likely is a big hit on query performance.- WITH- funnel_actors AS (- {{funnel_persons_query}}- ),- {target_step} AS target_step-- SELECT- {{total_identifier}} as name,- countDistinctIf(actor_id, steps = target_step) AS success_count,- countDistinctIf(actor_id, steps <> target_step) AS failure_count- FROM funnel_actors+ HAVING prop.1 = {{total_identifier}} OR prop.1 NOT IN {{exclude_names}}""",placeholders={"funnel_persons_query": funnel_persons_query,@@ -757,7 +721,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsreturn querydef get_funnel_actors_cte(self, additional_properties: list[Any] | None = None) -> ast.SelectQuery:- extra_fields = ["steps", "final_timestamp", "first_timestamp"]+ extra_fields = ["steps"]for prop in self.properties_to_include:extra_fields.append(prop)@@ -822,6 +786,48 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsAND event.event NOT IN funnel_step_names"""+ def _get_filtered_events_cte(self, extra_event_conditions: str = "") -> str:+ return f"""+ SELECT *+ FROM events+ WHERE+ team_id = {self.context.team.pk}+ AND toTimeZone(toDateTime(timestamp), 'UTC') >= {{date_from}}+ AND toTimeZone(toDateTime(timestamp), 'UTC') < {{date_to}}+ AND event NOT IN {{funnel_step_names}}+ {extra_event_conditions}+ """++ def _get_events_right_join_query(self) -> str:+ """Join filtered events onto funnel_actors, preserving actors without events.++ Written as `FROM filtered_events RIGHT JOIN funnel_actors` rather than+ `FROM funnel_actors LEFT JOIN filtered_events`: the semantics are identical,+ but the right table is ClickHouse's hash-build side, and that must be the+ small funnel_actors set.+ """+ windowInterval = self.context.funnelWindowInterval+ windowIntervalUnit = funnel_window_interval_unit_to_sql(self.context.funnelWindowIntervalUnit)++ if self.funnels_query.aggregation_group_type_index is not None:+ join_condition = (+ f"funnel_actors.actor_id = event_table.$group_{self.funnels_query.aggregation_group_type_index}"+ )+ elif self._hogql_aggregation_expr() is not None:+ join_condition = "funnel_actors.actor_id = {aggregation_join_target}"+ else:+ join_condition = "event_table.person_id = funnel_actors.actor_id"++ return f"""+ RIGHT JOIN funnel_actors+ ON {join_condition}+ AND toTimeZone(toDateTime(event_table.timestamp), 'UTC') > funnel_actors.first_timestamp+ AND toTimeZone(toDateTime(event_table.timestamp), 'UTC') < coalesce(+ funnel_actors.final_timestamp,+ toTimeZone(funnel_actors.first_timestamp, 'UTC') + INTERVAL {windowInterval} {windowIntervalUnit},+ {{date_to}})+ """+def _get_aggregation_target_join_query(self) -> str:aggregation_person_join = f"""JOIN funnel_actors@@ -881,10 +887,9 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsON funnel_actors.actor_id == groups_{group_type_index}.key"""- def _get_properties_prop_clause(self) -> ast.Alias:+ def _get_properties_prop_array(self) -> ast.Expr:"""Build AST for property extraction, safely escaping user-provided property names.- Returns: arrayJoin(...) as prop"""assert self.query.funnelCorrelationNames is not None@@ -895,41 +900,42 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsproperties_field = ast.Field(chain=[f"groups_{group_idx}", "properties"])if "$all" in self.query.funnelCorrelationNames:- # arrayJoin(JSONExtractKeysAndValues(person_props, 'String')) as prop- return ast.Alias(- alias="prop",- expr=ast.Call(- name="arrayJoin",- args=[- ast.Call(- name="JSONExtractKeysAndValues",- args=[properties_field, ast.Constant(value="String")],- )- ],- ),- )- else:- # Build: arrayJoin(arrayZip(['prop1', 'prop2'], [JSONExtractString(...), ...])) as prop- # Property names as constants (safely escaped)- prop_names_array = ast.Array(exprs=[ast.Constant(value=name) for name in self.query.funnelCorrelationNames])- # Property value extractions- prop_values_array = ast.Array(- exprs=[- ast.Call(- name="JSONExtractString",- args=[properties_field, ast.Constant(value=name)],- )- for name in self.query.funnelCorrelationNames- ]+ return ast.Call(+ name="JSONExtractKeysAndValues",+ args=[properties_field, ast.Constant(value="String")],)- return ast.Alias(- alias="prop",- expr=ast.Call(- name="arrayJoin",- args=[ast.Call(name="arrayZip", args=[prop_names_array, prop_values_array])],- ),++ prop_names_array = ast.Array(exprs=[ast.Constant(value=name) for name in self.query.funnelCorrelationNames])+ prop_values_array = ast.Array(+ exprs=[+ ast.Call(+ name="JSONExtractString",+ args=[properties_field, ast.Constant(value=name)],+ )+ for name in self.query.funnelCorrelationNames+ ]+ )+ return ast.Call(name="arrayZip", args=[prop_names_array, prop_values_array])++ def _get_properties_prop_clause(self, include_total: bool = False) -> ast.Alias:+ prop_array = self._get_properties_prop_array()+ if include_total:+ prop_array = ast.Call(+ name="arrayConcat",+ args=[+ ast.Array(+ exprs=[+ ast.Tuple(+ exprs=[ast.Constant(value=self.TOTAL_IDENTIFIER), ast.Constant(value="")],+ )+ ]+ ),+ prop_array,+ ],)+ return ast.Alias(alias="prop", expr=ast.Call(name="arrayJoin", args=[prop_array]))+def _get_funnel_step_names(self) -> list[str]:events: set[str] = set()for entity in self.funnels_query.series:diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambrindex b7c2cdbcadd0..d730b17b473c 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr@@ -1,44 +1,19 @@# serializer version: 1# name: TestClickhouseFunnelCorrelation.test_action_events_are_excluded_from_correlations'''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ WITH funnel_actors AS MATERIALIZED+ (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS stepsFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)+ and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)+ and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)+ and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)+ and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_targetFROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_0,- if(and(equals(e.event, 'paid'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_1+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(and(equals(e.event, 'user signed up'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_0, if(and(equals(e.event, 'paid'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_1FROM events AS eLEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_id@@ -69,54 +44,7 @@WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))GROUP BY nameLIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_0,- if(and(equals(e.event, 'paid'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step+ UNION ALLSELECT 'Total_Values_In_Query' AS name,countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)and isNull(target_step))) AS success_count,@@ -144,9 +72,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -187,7 +113,7 @@WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -195,7 +121,7 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(arrayZip(['$browser'], [JSONExtractString(persons.person_props, '$browser')])) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['$browser'], [JSONExtractString(persons.person_props, '$browser')]))) AS propFROM funnel_actorsJOIN(SELECT persons.id AS id,@@ -211,62 +137,7 @@GROUP BY person.idHAVING 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 persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -293,9 +164,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -407,9 +276,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -521,9 +388,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -635,9 +500,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1326,9 +1189,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1356,16 +1217,57 @@if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT concat(ifNull(toString(event_name), ''), '::', ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), '')) AS name,+ filtered_events AS+ (SELECT events.event AS event,+ events.properties AS properties,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ events.`$group_1` AS `$group_1`,+ accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_issue_id'), ''), 'null'), '^"|"$', ''), 'UUID') AS event_issue_id,+ if(not(empty(events__exception_issue_override.issue_id)), events__exception_issue_override.issue_id, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_issue_id'), ''), 'null'), '^"|"$', ''), 'UUID')) AS issue_id,+ events__fingerprint_issue_state.issue_id AS issue_id_v2,+ events__fingerprint_issue_state.issue_name AS issue_name,+ events__fingerprint_issue_state.issue_description AS issue_description,+ events__fingerprint_issue_state.issue_status AS issue_status,+ events__fingerprint_issue_state.assigned_user_id AS issue_assigned_user_id,+ events__fingerprint_issue_state.assigned_role_id AS issue_assigned_role_id,+ events__fingerprint_issue_state.first_seen AS issue_first_seen+ FROM events+ LEFT OUTER JOIN+ (SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_id), error_tracking_fingerprint_issue_state.version), 1)) AS issue_id,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_name), error_tracking_fingerprint_issue_state.version), 1)) AS issue_name,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_description), error_tracking_fingerprint_issue_state.version), 1)) AS issue_description,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_status), error_tracking_fingerprint_issue_state.version), 1)) AS issue_status,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_user_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_user_id,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_role_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_role_id,+ toNullable(tupleElement(argMax(tuple(toTimeZone(error_tracking_fingerprint_issue_state.first_seen, 'UTC')), error_tracking_fingerprint_issue_state.version), 1)) AS first_seen+ FROM error_tracking_fingerprint_issue_state+ WHERE equals(error_tracking_fingerprint_issue_state.team_id, 99999)+ GROUP BY fp_hash+ HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), events__fingerprint_issue_state.fp_hash)+ LEFT OUTER JOIN+ (SELECT tupleElement(argMax(tuple(error_tracking_issue_fingerprint_overrides.issue_id), error_tracking_issue_fingerprint_overrides.version), 1) AS issue_id,+ error_tracking_issue_fingerprint_overrides.fingerprint AS fingerprint+ FROM error_tracking_issue_fingerprint_overrides+ WHERE equals(error_tracking_issue_fingerprint_overrides.team_id, 99999)+ GROUP BY error_tracking_issue_fingerprint_overrides.fingerprint+ HAVING equals(tupleElement(argMax(tuple(error_tracking_issue_fingerprint_overrides.is_deleted), error_tracking_issue_fingerprint_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__exception_issue_override ON equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', ''), events__exception_issue_override.fingerprint)+ LEFT OUTER JOIN+ (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), equals(events.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), less(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))), notIn(events.event, tuple('paid', 'user signed up')), in(events.event, tuple('positively_related', 'negatively_related')))),+ 2 AS target_step+ SELECT if(ifNull(equals((prop).1, 'Total_Values_In_Query'), 0), 'Total_Values_In_Query', concat(ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), ''), '::', ifNull(toString((prop).3), ''))) AS name,countDistinctIf(actor_id, ifNull(equals(steps, target_step), isNull(steps)and isNull(target_step))) AS success_count,countDistinctIf(actor_id, ifNull(notEquals(steps, target_step), isNotNull(steps)@@ -1373,62 +1275,12 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- event.event AS event_name,- arrayJoin(JSONExtractKeysAndValues(event.properties, 'String')) AS prop- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_1`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), in(event.event, tuple('positively_related', 'negatively_related'))))+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '', '')], if(empty(event_table.event), [], arrayMap(prop -> tuple(event_table.event, prop.1, prop.2), JSONExtractKeysAndValues(event_table.properties, 'String'))))) AS prop+ FROM filtered_events AS event_table+ RIGHT JOIN funnel_actors ON and(equals(funnel_actors.actor_id, event_table.`$group_1`), greater(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))))))GROUP BY name,prop- HAVING greater(plus(success_count, failure_count), 2)- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_1` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals(name, 'Total_Values_In_Query'), greater(plus(success_count, failure_count), 2))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1567,40 +1419,16 @@# ---# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups'''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ WITH funnel_actors AS MATERIALIZED+ (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS stepsFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)+ and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)+ and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)+ and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)+ and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_targetFROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS eWHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_target@@ -1621,47 +1449,7 @@WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))GROUP BY nameLIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step+ UNION ALLSELECT 'Total_Values_In_Query' AS name,countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)and isNull(target_step))) AS success_count,@@ -1692,9 +1480,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1767,9 +1553,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1842,9 +1626,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1917,9 +1699,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -1984,49 +1764,22 @@# ---# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.5'''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ WITH funnel_actors AS MATERIALIZED+ (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS stepsFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)+ and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)+ and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)+ and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)+ and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_targetFROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS eLEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry, groups.group_type_index AS index, groups.group_key AS keyFROM groupsWHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ GROUP BY groups.group_type_index, groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -2036,65 +1789,17 @@assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,2 AS target_step,['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step+ SELECT event.event AS name,+ countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step))) AS success_count,+ countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step))) AS failure_count+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))+ GROUP BY name+ LIMIT 100+ UNION ALLSELECT 'Total_Values_In_Query' AS name,countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)and isNull(target_step))) AS success_count,@@ -2125,9 +1830,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -2200,9 +1903,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -2956,9 +2657,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -2992,7 +2691,7 @@WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -3000,7 +2699,7 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')])) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,@@ -3015,55 +2714,7 @@groups.group_key) AS groupsWHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3088,9 +2739,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -3167,9 +2816,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -3246,9 +2893,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -3325,9 +2970,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -3401,9 +3044,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -3437,7 +3078,7 @@WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -3445,7 +3086,7 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(JSONExtractKeysAndValues(groups_0.properties, 'String')) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,@@ -3460,55 +3101,7 @@groups.group_key) AS groupsWHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4092,9 +3685,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4128,7 +3719,7 @@WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -4136,7 +3727,7 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')])) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,@@ -4151,55 +3742,7 @@groups.group_key) AS groupsWHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4224,9 +3767,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4303,9 +3844,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4382,9 +3921,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4461,9 +3998,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4537,9 +4072,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -4573,7 +4106,7 @@WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -4581,7 +4114,7 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(JSONExtractKeysAndValues(groups_0.properties, 'String')) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,@@ -4596,55 +4129,7 @@groups.group_key) AS groupsWHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambrindex 67ece49b7126..9e09d742b7b5 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr@@ -11,9 +11,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,@@ -126,9 +124,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[3][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[''] AS prop,@@ -242,9 +238,7 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py b/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.pyindex daab3de0e433..e7ff7f5ebe28 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py+++ b/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py@@ -2107,6 +2107,68 @@ class TestClickhouseFunnelCorrelation(ClickhouseTestMixin, APIBaseTest):# 6,# )+ def test_funnel_correlation_with_event_properties_autocapture_no_rows_for_actors_without_events(self):+ query = FunnelsQuery(+ series=[+ EventsNode(event="user signed up"),+ EventsNode(event="paid"),+ ],+ dateRange=DateRange(date_from="2020-01-01", date_to="2020-01-14"),+ )++ for i in range(6):+ _create_person(distinct_ids=[f"user_{i}"], team_id=self.team.pk)+ _create_event(+ team=self.team,+ event="user signed up",+ distinct_id=f"user_{i}",+ timestamp="2020-01-02T14:00:00Z",+ )+ _create_event(+ team=self.team,+ event="$autocapture",+ distinct_id=f"user_{i}",+ elements=[Element(nth_of_type=1, nth_child=0, tag_name="a", href="/movie")],+ timestamp="2020-01-03T14:00:00Z",+ properties={"$event_type": "click"},+ )+ _create_event(+ team=self.team,+ event="paid",+ distinct_id=f"user_{i}",+ timestamp="2020-01-04T14:00:00Z",+ )++ # Enough non-converting users without any $autocapture events to pass the+ # significance filters, so a synthesized correlation row would show up.+ for i in range(3):+ _create_person(distinct_ids=[f"user_fail_{i}"], team_id=self.team.pk)+ _create_event(+ team=self.team,+ event="user signed up",+ distinct_id=f"user_fail_{i}",+ timestamp="2020-01-02T14:00:00Z",+ )++ result, _ = self._get_events_for_query(+ query,+ funnelCorrelationType=FunnelCorrelationResultsType.EVENT_WITH_PROPERTIES,+ funnelCorrelationEventNames=["$autocapture"],+ )++ self.assertEqual(+ result,+ [+ {+ "event": '$autocapture::elements_chain::click__~~__a:href="/movie"nth-child="0"nth-of-type="1"',+ "success_count": 6,+ "failure_count": 0,+ "odds_ratio": 28.0,+ "correlation_type": "success",+ },+ ],+ )+class TestCorrelationFunctions(unittest.TestCase):def test_are_results_insignificant(self):diff --git a/posthog/hogql_queries/insights/trends/test/test_trends.py b/posthog/hogql_queries/insights/trends/test/test_trends.pyindex 98a2b6d99d03..9fd0a4264ee0 100644--- a/posthog/hogql_queries/insights/trends/test/test_trends.py+++ b/posthog/hogql_queries/insights/trends/test/test_trends.py@@ -64,12 +64,16 @@ def breakdown_label(entity: Entity, value: Union[str, int]) -> dict[str, Optionareturn ret_dict-def _create_cohort(**kwargs):- team = kwargs.pop("team")- name = kwargs.pop("name")- groups = kwargs.pop("groups")+def _create_cohort(+ *,+ team: Team,+ name: str,+ groups: list[dict[str, Any]],+ pending_version: int | None = 0,+) -> Cohort:cohort = Cohort.objects.create(team=team, name=name, groups=groups, last_calculation=timezone.now())- cohort.calculate_people_ch(pending_version=0)+ if pending_version is not None:+ cohort.calculate_people_ch(pending_version=pending_version)return cohort@@ -7460,6 +7464,7 @@ class TestTrends(ClickhouseTestMixin, APIBaseTest):team=self.team,name="cohort_2",groups=[{"properties": [{"key": "key_2", "value": "value_2", "type": "person"}]}],+ pending_version=None,)# try different versionsdiff --git a/posthog/temporal/common/clickhouse.py b/posthog/temporal/common/clickhouse.pyindex f543fe740b97..747374843445 100644--- a/posthog/temporal/common/clickhouse.py+++ b/posthog/temporal/common/clickhouse.py@@ -528,6 +528,8 @@ class ClickHouseClient:The response received from the ClickHouse HTTP interface."""params = {**self.params}+ # PyArrow reads response.raw directly in stream_query_as_arrow, so keep the HTTP body uncompressed.+ params["enable_http_compression"] = "0"if query_id is not None:params["query_id"] = query_iddiff --git a/posthog/temporal/tests/test_clickhouse.py b/posthog/temporal/tests/test_clickhouse.pyindex 8d3a346bd348..38b5060c23ac 100644--- a/posthog/temporal/tests/test_clickhouse.py+++ b/posthog/temporal/tests/test_clickhouse.py@@ -197,6 +197,16 @@ def test_clickhouse_error_code_maps_to_exception(clickhouse_client, error_text,pass+def test_post_query_disables_http_compression(clickhouse_client):+ mock_response = MagicMock(status_code=200)+ with _mock_internal_session_post(mock_response) as mock_factory:+ with clickhouse_client.post_query("SELECT 1", query_parameters={}, query_id=None):+ pass++ call_kwargs = mock_factory.return_value.post.call_args.kwargs+ assert call_kwargs["params"]["enable_http_compression"] == "0"++@pytest.mark.parametrize("query,query_parameters,expected",[diff --git a/posthog/test/base.py b/posthog/test/base.pyindex be7d61317287..bbea782004f1 100644--- a/posthog/test/base.py+++ b/posthog/test/base.py@@ -124,7 +124,7 @@ from posthog.models.person.sql import (TRUNCATE_PERSON_DISTINCT_ID_TABLE_SQL,TRUNCATE_PERSON_STATIC_COHORT_TABLE_SQL,)-from posthog.models.person.util import bulk_create_persons, create_person+from posthog.models.person.util import bulk_create_personsfrom posthog.models.personal_api_key import PersonalAPIKeyfrom posthog.models.precalculated_events.sql import (DROP_PRECALCULATED_EVENTS_KAFKA_TABLE_SQL,@@ -1560,14 +1560,7 @@ def _create_person(*args, **kwargs):if kwargs.get("immediate") or (hasattr(dt.datetime.now(), "__module__") and dt.datetime.now().__module__ == "freezegun.api"):- if kwargs.get("immediate"):- del kwargs["immediate"]- create_person(- team_id=kwargs.get("team_id") or kwargs["team"].pk,- properties=kwargs.get("properties"),- uuid=kwargs["uuid"],- version=kwargs.get("version", 0),- )+ kwargs.pop("immediate", None)return Person.objects.create(**kwargs)if len(args) > 0:kwargs["distinct_ids"] = [args[0]] # allow calling _create_person("distinct_id")diff --git a/products/batch_exports/backend/tests/temporal/conftest.py b/products/batch_exports/backend/tests/temporal/conftest.pyindex 4d4b1d5986ab..c43f84fbd176 100644--- a/products/batch_exports/backend/tests/temporal/conftest.py+++ b/products/batch_exports/backend/tests/temporal/conftest.py@@ -27,8 +27,11 @@ from posthog.temporal.tests.utils.events import generate_test_events_in_clickhoufrom products.batch_exports.backend.temporal import ACTIVITIES, WORKFLOWSfrom products.batch_exports.backend.temporal.metrics import BatchExportsMetricsInterceptorfrom products.batch_exports.backend.tests.temporal.utils.persons import (- generate_test_person_distinct_id2_in_clickhouse,+ PersonDistinctId2Values,+ PersonValues,+ generate_test_person_distinct_id2,generate_test_persons_in_clickhouse,+ insert_person_distinct_id2_values_in_clickhouse,)@@ -379,6 +382,43 @@ def events_table(request) -> str | None:return None+async def _insert_person_distinct_ids_for_persons(+ clickhouse_client: ClickHouseClient, team_id: int, persons: list[PersonValues]+) -> list[PersonDistinctId2Values]:+ person_distinct_ids: list[PersonDistinctId2Values] = []+ other_team_person_distinct_ids: list[PersonDistinctId2Values] = []++ for person in persons:+ person_id = uuid.UUID(person["id"])+ timestamp = dt.datetime.fromisoformat(person["_timestamp"])+ distinct_id = f"distinct-id-{person_id}"++ person_distinct_ids.append(+ generate_test_person_distinct_id2(+ count=1,+ team_id=team_id,+ person_id=person_id,+ distinct_id=distinct_id,+ timestamp=timestamp,+ )+ )+ other_team_person_distinct_ids.append(+ generate_test_person_distinct_id2(+ count=1,+ team_id=team_id + random.randint(1, 1000),+ person_id=person_id,+ distinct_id=distinct_id,+ timestamp=timestamp,+ )+ )++ await insert_person_distinct_id2_values_in_clickhouse(+ client=clickhouse_client,+ persons=person_distinct_ids + other_team_person_distinct_ids,+ )+ return person_distinct_ids++@pytest.fixtureasync def generate_test_data(ateam,@@ -455,14 +495,8 @@ async def generate_test_data()persons_to_export_created = []- for person in persons:- person_distinct_id, _ = await generate_test_person_distinct_id2_in_clickhouse(- client=clickhouse_client,- team_id=ateam.pk,- person_id=uuid.UUID(person["id"]),- distinct_id=f"distinct-id-{uuid.UUID(person['id'])}",- timestamp=dt.datetime.fromisoformat(person["_timestamp"]),- )+ person_distinct_ids = await _insert_person_distinct_ids_for_persons(clickhouse_client, ateam.pk, persons)+ for person, person_distinct_id in zip(persons, person_distinct_ids, strict=True):person_to_export = {"team_id": person["team_id"],"person_id": person["id"],@@ -489,14 +523,8 @@ async def generate_test_persons_data(ateam, clickhouse_client, data_interval_sta)persons_to_export_created = []- for person in persons:- person_distinct_id, _ = await generate_test_person_distinct_id2_in_clickhouse(- client=clickhouse_client,- team_id=ateam.pk,- person_id=uuid.UUID(person["id"]),- distinct_id=f"distinct-id-{uuid.UUID(person['id'])}",- timestamp=dt.datetime.fromisoformat(person["_timestamp"]),- )+ person_distinct_ids = await _insert_person_distinct_ids_for_persons(clickhouse_client, ateam.pk, persons)+ for person, person_distinct_id in zip(persons, person_distinct_ids, strict=True):person_to_export = {"team_id": person["team_id"],"person_id": person["id"],diff --git a/products/batch_exports/backend/tests/temporal/utils/persons.py b/products/batch_exports/backend/tests/temporal/utils/persons.pyindex 5f1cbf0e5848..e506a71154f1 100644--- a/products/batch_exports/backend/tests/temporal/utils/persons.py+++ b/products/batch_exports/backend/tests/temporal/utils/persons.py@@ -63,6 +63,9 @@ def generate_test_persons(async def insert_person_values_in_clickhouse(client: ClickHouseClient, persons: list[PersonValues]):"""Execute an insert query to insert provided PersonValues into person."""+ if not persons:+ return+await execute_query(client,f"""@@ -109,8 +112,9 @@ async def generate_test_persons_in_clickhouse(batch_size: int = 10000,) -> tuple[list[PersonValues], list[PersonValues]]:persons: list[PersonValues] = []+ persons_to_insert: list[PersonValues] = []while len(persons) < count:- persons_to_insert = generate_test_persons(+ generated_persons = generate_test_persons(count=min(count - len(persons), batch_size),team_id=team_id,timestamp_start=start_time,@@ -123,9 +127,12 @@ async def generate_test_persons_in_clickhouse(start=len(persons),)- await insert_person_values_in_clickhouse(client=client, persons=persons_to_insert)+ persons_to_insert.extend(generated_persons)+ if len(persons_to_insert) >= batch_size:+ await insert_person_values_in_clickhouse(client=client, persons=persons_to_insert)+ persons_to_insert = []- persons.extend(persons_to_insert)+ persons.extend(generated_persons)persons_from_other_team = generate_test_persons(count=count_other_team,@@ -140,7 +147,8 @@ async def generate_test_persons_in_clickhouse(start=len(persons),)- await insert_person_values_in_clickhouse(client=client, persons=persons_from_other_team)+ persons_to_insert.extend(persons_from_other_team)+ await insert_person_values_in_clickhouse(client=client, persons=persons_to_insert)return (persons, persons_from_other_team)@@ -181,6 +189,9 @@ async def insert_person_distinct_id2_values_in_clickhouse(client: ClickHouseClient, persons: list[PersonDistinctId2Values]):"""Execute an insert query to insert provided PersonDistinctId2Values into person."""+ if not persons:+ return+await execute_query(client,f"""@@ -227,8 +238,6 @@ async def generate_test_person_distinct_id2_in_clickhouse(version=version,)- await insert_person_distinct_id2_values_in_clickhouse(client=client, persons=[person])-person_from_other_team = generate_test_person_distinct_id2(count=1,team_id=team_id + random.randint(1, 1000),@@ -239,5 +248,5 @@ async def generate_test_person_distinct_id2_in_clickhouse(version=version,)- await insert_person_distinct_id2_values_in_clickhouse(client=client, persons=[person_from_other_team])+ await insert_person_distinct_id2_values_in_clickhouse(client=client, persons=[person, person_from_other_team])return (person, person_from_other_team)diff --git a/products/web_analytics/backend/test/test_heatmaps_api.py b/products/web_analytics/backend/test/test_heatmaps_api.pyindex 78c252a9be63..19085e34a616 100644--- a/products/web_analytics/backend/test/test_heatmaps_api.py+++ b/products/web_analytics/backend/test/test_heatmaps_api.py@@ -447,7 +447,7 @@ class TestSessionRecordings(APIBaseTest, ClickhouseTestMixin, QueryMatchingTest)["min_150",{"date_from": "2023-03-08", "viewport_width_min": "150"},- [heatmap_result(0.08, 1), heatmap_result(0.09, 1), heatmap_result(0.1, 1), heatmap_result(0.11, 2)],+ [heatmap_result(0.08, 1), heatmap_result(0.09, 1), heatmap_result(0.1, 2), heatmap_result(0.11, 2)],],["min_161",@@ -455,7 +455,7 @@ class TestSessionRecordings(APIBaseTest, ClickhouseTestMixin, QueryMatchingTest)[heatmap_result(0.08, 1),heatmap_result(0.09, 1),- heatmap_result(0.1, 1),+ heatmap_result(0.1, 2),],],[@@ -470,7 +470,7 @@ class TestSessionRecordings(APIBaseTest, ClickhouseTestMixin, QueryMatchingTest)["min_161_and_max_192",{"date_from": "2023-03-08", "viewport_width_min": 161, "viewport_width_max": 192},- [heatmap_result(0.08, 1), heatmap_result(0.09, 1), heatmap_result(0.1, 1)],+ [heatmap_result(0.08, 1), heatmap_result(0.09, 1), heatmap_result(0.1, 2)],],])@@ -485,7 +485,7 @@ class TestSessionRecordings(APIBaseTest, ClickhouseTestMixin, QueryMatchingTest)# viewport widths that scale to 10self._create_heatmap_event("session_3", "click", "2023-03-08T08:01:00", 152)- self._create_heatmap_event("session_3", "click", "2023-03-08T08:01:00", 161)+ self._create_heatmap_event("session_4", "click", "2023-03-08T08:01:00", 161)# viewport width that scales to 11self._create_heatmap_event("session_3", "click", "2023-03-08T08:01:00", 177)