: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
fix(deletions): shard a sibling over the role its target declares (#91611)
Paweł Szczur52a776817797
diff --git a/posthog/clickhouse/client/connection.py b/posthog/clickhouse/client/connection.pyindex 3b1dcfd12e92..d5c0a414347e 100644--- a/posthog/clickhouse/client/connection.py+++ b/posthog/clickhouse/client/connection.py@@ -29,6 +29,11 @@ class NodeRole(StrEnum):ALL = "all"DATA = "data"INGESTION_EVENTS = "events"+ # Same macro, named for what the role holds rather than what writes to it. The nodes carrying+ # this role run the events ingestion layer and are also the events cluster's shards, so a+ # caller reasoning about stored data (deletion, squash) reads better against EVENTS while the+ # migrations that create ingestion tables keep INGESTION_EVENTS.+ EVENTS = "events"INGESTION_SMALL = "small"INGESTION_MEDIUM = "medium"ENDPOINTS = "endpoints"diff --git a/posthog/clickhouse/cluster.py b/posthog/clickhouse/cluster.pyindex 388cad39a978..991be9d83693 100644--- a/posthog/clickhouse/cluster.py+++ b/posthog/clickhouse/cluster.py@@ -164,6 +164,7 @@ class ClickhouseCluster:satellite_clusters: Sequence[str] | None = None,retry_policy: RetryPolicy | None = None,connection_overrides: Mapping[str, Any] | None = None,+ shard_role: NodeRole = NodeRole.DATA,) -> None:if logger is None:logger = logging.getLogger(__name__)@@ -172,10 +173,15 @@ class ClickhouseCluster:self.__extra_hosts: set[HostInfo] = set()migrations_cluster = cluster or settings.CLICKHOUSE_CLUSTER- # The cluster whose DATA nodes back `shards`, which is what every sharded mutation+ # The cluster whose shard-bearing nodes back `shards`, which is what every sharded mutation# dispatches over. Callers holding a table that lives elsewhere have no way to reach it# through this instance, so they need to be able to ask.self.__data_cluster_name = data_cluster or migrations_cluster+ # Which hostClusterRole owns a shard here. `data` on the main cluster, but a cluster can+ # shard its tables across another role: the events cluster carries sharded_events_json on+ # nodes whose role is `events`, and reading their shard numbers as absent would leave this+ # handle with no shards to dispatch over at all.+ self.__shard_role = shard_rolecluster_hosts = self.__get_cluster_hosts(bootstrap_client, migrations_cluster, retry_policy)for row in cluster_hosts:@@ -186,8 +192,8 @@ class ClickhouseCluster:resolved_host, resolved_port = _resolve_connection_target(host_name, effective_port)host_info = HostInfo(ConnectionInfo(resolved_host, resolved_port),- shard_num if host_cluster_role == NodeRole.DATA else None,- replica_num if host_cluster_role == NodeRole.DATA else None,+ shard_num if host_cluster_role == shard_role else None,+ replica_num if host_cluster_role == shard_role else None,host_cluster_type,host_cluster_role,)@@ -200,7 +206,7 @@ class ClickhouseCluster:data_hosts = self.__get_cluster_hosts(bootstrap_client, data_cluster, retry_policy)for row in data_hosts:(host_name, port, shard_num, replica_num, host_cluster_type, host_cluster_role) = row- if host_cluster_role == NodeRole.DATA:+ if host_cluster_role == shard_role:effective_port = port if (settings.E2E_TESTING or settings.DEBUG) else Noneresolved_host, resolved_port = _resolve_connection_target(host_name, effective_port)host_info = HostInfo(@@ -258,9 +264,13 @@ class ClickhouseCluster:# Kept so `sibling` can build a handle for another cluster from the same connection.self.__bootstrap_client = bootstrap_clientself.__extra_host_infos = list(extra_hosts) if extra_hosts else []- self.__siblings: dict[str, ClickhouseCluster] = {}+ self.__siblings: dict[tuple[str, NodeRole], ClickhouseCluster] = {}- def sibling(self, cluster: str) -> ClickhouseCluster:+ @property+ def shard_role(self) -> NodeRole:+ return self.__shard_role++ def sibling(self, cluster: str, shard_role: NodeRole = NodeRole.DATA) -> ClickhouseCluster:"""A handle addressing ``cluster``, carrying this one's connection settings.``shards`` covers exactly one cluster, so a caller holding a table stored on another one@@ -271,11 +281,11 @@ class ClickhouseCluster:Memoized, because discovery costs a query per cluster and callers resolve the same tableonce per op. Raises whatever the server says when no such cluster is defined here."""- if cluster == self.__data_cluster_name:+ if cluster == self.__data_cluster_name and shard_role == self.__shard_role:return self- sibling = self.__siblings.get(cluster)+ sibling = self.__siblings.get((cluster, shard_role))if sibling is None:- sibling = self.__siblings[cluster] = ClickhouseCluster(+ sibling = self.__siblings[(cluster, shard_role)] = ClickhouseCluster(self.__bootstrap_client,extra_hosts=self.__extra_host_infos,logger=self.__logger,@@ -283,6 +293,7 @@ class ClickhouseCluster:cluster=cluster,retry_policy=self.__retry_policy,connection_overrides=self.__connection_overrides,+ shard_role=shard_role,)return siblingdiff --git a/posthog/dags/deletes.py b/posthog/dags/deletes.pyindex 7c413782a8c7..41580c3d5776 100644--- a/posthog/dags/deletes.py+++ b/posthog/dags/deletes.py@@ -130,9 +130,11 @@ _DELETE_PREDICATE = """or(ShardMutations = dict[int, MutationWaiters]# Shard numbers are per cluster, so a sweep spanning two of them cannot key its waiters by shard-# alone. Keyed by cluster name rather than by handle: the handle is recovered with-# ClickhouseCluster.sibling, which is memoized, and a name survives the op boundary.-ClusterShardMutations = dict[str, ShardMutations]+# alone. Keyed by cluster name and the role that owns its shards rather than by handle: the handle+# is recovered with ClickhouseCluster.sibling, which is memoized, and both survive the op boundary.+# The role has to travel with the name, or sibling hands back a default-role handle with no shards+# and the waits find nothing to wait on.+ClusterShardMutations = dict[tuple[str, NodeRole], ShardMutations]@dataclass@@ -707,18 +709,19 @@ def delete_events(for placement in placements]- waiters: dict[str, dict[int, list[MutationWaiter]]] = {}+ waiters: dict[tuple[str, NodeRole], dict[int, list[MutationWaiter]]] = {}for placement, delete_mutation_runner in delete_mutation_runners:# placement.cluster, not the job's handle: the dictionary the predicate joins was created# on every cluster here, but the storage table only exists on this one.for host, mutation in placement.cluster.map_one_host_per_shard(delete_mutation_runner).result().items():if host.shard_num is not None:- by_shard = waiters.setdefault(placement.cluster.data_cluster_name, {})+ key = (placement.cluster.data_cluster_name, placement.cluster.shard_role)+ by_shard = waiters.setdefault(key, {})by_shard.setdefault(host.shard_num, []).append(mutation)cluster_mutations: ClusterShardMutations = {- name: {shard_num: MutationWaiters(waiters=shard_waiters) for shard_num, shard_waiters in by_shard.items()}- for name, by_shard in waiters.items()+ key: {shard_num: MutationWaiters(waiters=shard_waiters) for shard_num, shard_waiters in by_shard.items()}+ for key, by_shard in waiters.items()}return (load_and_verify_deletes_dictionary, cluster_mutations)@@ -805,8 +808,8 @@ def wait_for_delete_mutations_in_shards() -> PendingDeletesDictionary:pending_deletes_dict, cluster_mutations = delete_mutations- for cluster_name, shard_mutations in cluster_mutations.items():- handle = cluster.sibling(cluster_name)+ for (cluster_name, shard_role), shard_mutations in cluster_mutations.items():+ handle = cluster.sibling(cluster_name, shard_role)handle.map_all_hosts_in_shards({shard: mutation.wait for shard, mutation in shard_mutations.items()}).result()return pending_deletes_dictdiff --git a/posthog/models/deletion_targets.py b/posthog/models/deletion_targets.pyindex f2178718d52e..477db7a7d656 100644--- a/posthog/models/deletion_targets.py+++ b/posthog/models/deletion_targets.py@@ -85,6 +85,12 @@ class DeletionTarget:# Anything that may live elsewhere must also be ``optional``, since that is what makes the# storage table's presence a question rather than an assumption.cluster_setting: str = "CLICKHOUSE_CLUSTER"+ # The hostClusterRole owning this table's shards on the cluster named above. `data` on the main+ # cluster, but a cluster can shard across another role: the events cluster carries+ # sharded_events_json on nodes whose role is `events`, and a handle built for `data` there reads+ # no shard numbers at all, so it has nothing to dispatch over and matches no probe. Only used+ # when building that cluster's handle; the handle in hand is always probed on its own role.+ node_role: NodeRole = NodeRole.DATA# Guarded on system.tables: the table sits behind a migration that may not have run everywhere.optional: bool = False# The schema a HogQL predicate compiles against here, None where no HogQL table definition@@ -153,6 +159,7 @@ EVENTS_JSON = DeletionTarget(read_table=DISTRIBUTED_EVENTS_JSON_TABLE,optional=True,cluster_setting="CLICKHOUSE_EVENTS_CLUSTER",+ node_role=NodeRole.EVENTS,hogql_schema=HogQLSchema.NATIVE_JSON,accepts_property_rewrite=True,# Dual-written from the same events, so its uuids are the legacy table's.@@ -236,13 +243,18 @@ def _assert_no_rows_behind_the_proxy(cluster: ClickhouseCluster, target: Deletio)-def _any_data_node_has(cluster: ClickhouseCluster, table: str) -> bool:- """Whether any data node of ``cluster`` carries ``table``.+def _any_node_has(cluster: ClickhouseCluster, table: str) -> bool:+ """Whether any shard-bearing node of ``cluster`` carries ``table``.++ Probed with the handle's own shard role rather than the target's. The handle in hand shards+ over ``data`` even for a table that lives on ``events`` nodes elsewhere, which is the dev, CI+ and self-hosted case where events_json sits on the main cluster; the sibling is built for the+ target's role, so probing it picks that role up on its own.``any`` rather than ``all``: on a partially-migrated cluster the mutation fails loudly on thehosts missing the table, which is preferable to silently skipping a deletion."""- results = cluster.map_hosts_by_role(partial(_table_exists, table=table), NodeRole.DATA).result()+ results = cluster.map_hosts_by_role(partial(_table_exists, table=table), cluster.shard_role).result()return any(results.values())@@ -251,14 +263,14 @@ def _sibling_holding(cluster: ClickhouseCluster, target: DeletionTarget) -> Clicif target.cluster_name == cluster.data_cluster_name:return Nonetry:- sibling = cluster.sibling(target.cluster_name)+ sibling = cluster.sibling(target.cluster_name, target.node_role)except ServerException as exc:if exc.code != _CLUSTER_DOESNT_EXIST:raise# No such cluster here, which is every deployment the split that moves this table has not# reached: local, CI, self-hosted. Leave the verdict to the proxy check.return None- return sibling if _any_data_node_has(sibling, target.data_table) else None+ return sibling if _any_node_has(sibling, target.data_table) else Nonedef placement_for(cluster: ClickhouseCluster, target: DeletionTarget) -> TargetPlacement | None:@@ -268,7 +280,7 @@ def placement_for(cluster: ClickhouseCluster, target: DeletionTarget) -> TargetPcover the same nodes, which is what the dev stack and CI do. So the handle in hand is triedfirst, and a sibling is built only for a table it does not carry."""- if not target.optional or _any_data_node_has(cluster, target.data_table):+ if not target.optional or _any_node_has(cluster, target.data_table):return TargetPlacement(target=target, cluster=cluster)sibling = _sibling_holding(cluster, target)diff --git a/posthog/models/test/test_deletion_targets.py b/posthog/models/test/test_deletion_targets.pyindex 0c277258526b..675873aa2b28 100644--- a/posthog/models/test/test_deletion_targets.py+++ b/posthog/models/test/test_deletion_targets.py@@ -6,6 +6,7 @@ from unittest.mock import Mock, patchfrom django.test import override_settings+from posthog.clickhouse.client.connection import NodeRolefrom posthog.clickhouse.cluster import ClickhouseCluster, HostInfofrom posthog.models.deletion_targets import (DeletionTarget,@@ -15,12 +16,17 @@ from posthog.models.deletion_targets import (sweep_clusters,)-# One data node each, so a table present on one cluster and absent from the other is the only-# difference between them. That is the topology the placement resolution exists for and the one no-# single-node test environment can reproduce.+# Mirrors production. The main cluster shards across `data` nodes; the events cluster shards across+# nodes whose hostClusterRole is `events` and whose type is `offline`. Calling those nodes `data`+# here is what let the placement resolution pass its tests while finding nothing in production: a+# handle built for them assigns no shard numbers, so it has no shards to dispatch over and no host+# matching a `data` probe._HOSTS_BY_CLUSTER: dict[str, list[tuple]] = {"posthog": [("data1", 9000, 1, 1, "online", "data")],- "events": [("events1", 9000, 1, 1, "online", "data")],+ "events": [+ ("events1", 9000, 1, 1, "offline", "events"),+ ("events2", 9000, 2, 1, "offline", "events"),+ ],}_OFF_CLUSTER_TARGET = DeletionTarget(@@ -28,6 +34,7 @@ _OFF_CLUSTER_TARGET = DeletionTarget(read_table="events_json",optional=True,cluster_setting="CLICKHOUSE_EVENTS_CLUSTER",+ node_role=NodeRole.EVENTS,)@@ -57,7 +64,9 @@ def _cluster_with(tables_by_host: dict[str, set[str]]) -> Iterator[ClickhouseClu@override_settings(CLICKHOUSE_EVENTS_CLUSTER="events")def test_placement_routes_a_target_to_the_cluster_that_carries_it() -> None:- with _cluster_with({"data1": set(), "events1": {"sharded_events_json"}}) as cluster:+ with _cluster_with(+ {"data1": set(), "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ ) as cluster:placement = placement_for(cluster, _OFF_CLUSTER_TARGET)assert placement is not None@@ -69,7 +78,9 @@ def test_placement_routes_a_target_to_the_cluster_that_carries_it() -> None:def test_placement_prefers_the_handle_in_hand_over_a_sibling() -> None:# Two cluster names covering the same nodes is what the dev stack and CI do. Building a sibling# there would sweep the same rows twice, so the handle in hand has to win.- with _cluster_with({"data1": {"sharded_events_json"}, "events1": {"sharded_events_json"}}) as cluster:+ with _cluster_with(+ {"data1": {"sharded_events_json"}, "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ ) as cluster:placement = placement_for(cluster, _OFF_CLUSTER_TARGET)assert placement is not None@@ -81,7 +92,9 @@ def test_dispatchable_here_refuses_a_target_another_cluster_carries() -> None:# Sweeps that fan out over a single handle (property removal, the queued-uuid drain) have no way# to reach another cluster's shards. Answering False would put back the silent skip that# completes a request while the rows survive.- with _cluster_with({"data1": set(), "events1": {"sharded_events_json"}}) as cluster:+ with _cluster_with(+ {"data1": set(), "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ ) as cluster:with pytest.raises(UnreachableTargetError):dispatchable_here(cluster, _OFF_CLUSTER_TARGET)@@ -90,7 +103,9 @@ def test_dispatchable_here_refuses_a_target_another_cluster_carries() -> None:def test_sweep_clusters_lists_every_cluster_a_mutation_runs_on() -> None:# The delete predicate joins a dictionary, so the dictionary has to exist on each cluster this# returns. Missing one there means the mutation runs against nothing and reports success.- with _cluster_with({"data1": set(), "events1": {"sharded_events_json"}}) as cluster:+ with _cluster_with(+ {"data1": set(), "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ ) as cluster:clusters = sweep_clusters(cluster, [_OFF_CLUSTER_TARGET])assert [handle.data_cluster_name for handle in clusters] == ["posthog", "events"]@@ -101,5 +116,21 @@ def test_sweep_clusters_lists_every_cluster_a_mutation_runs_on() -> None:def test_sweep_clusters_does_not_repeat_the_handle_in_hand() -> None:# Building the dictionary twice on one cluster is wasted work, and every sweep keyed off this# list would run its mutations twice.- with _cluster_with({"data1": {"sharded_events_json"}, "events1": {"sharded_events_json"}}) as cluster:+ with _cluster_with(+ {"data1": {"sharded_events_json"}, "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ ) as cluster:assert sweep_clusters(cluster, [_OFF_CLUSTER_TARGET]) == [cluster]+++@override_settings(CLICKHOUSE_EVENTS_CLUSTER="events")+def test_a_sibling_shards_over_the_role_its_target_declares() -> None:+ # The mutation dispatches over placement.cluster.shards. A handle that only reads shard numbers+ # off `data` nodes leaves that empty for the events cluster, so the sweep reaches nothing and+ # the target looks absent rather than unreachable, which is how it went silent in production.+ tables = {"data1": set(), "events1": {"sharded_events_json"}, "events2": {"sharded_events_json"}}+ with _cluster_with(tables) as cluster:+ placement = placement_for(cluster, _OFF_CLUSTER_TARGET)++ assert placement is not None+ assert sorted(placement.cluster.shards) == [1, 2]+ assert placement.cluster.shard_role == NodeRole.EVENTSdiff --git a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambrindex 17d46f5c097e..017f23c3892b 100644--- a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr+++ b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr@@ -34,7 +34,7 @@e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'user did things'), 1, 0) AS step_1,- ([replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', '')] AS value) AS prop_basic,+ ([e__person.properties___fish] AS value) AS prop_basic,prop_basic AS propFROM events AS eLEFT OUTER JOIN@@ -44,6 +44,16 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.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('user did things', 'user signed up')), ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -111,7 +121,17 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.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('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -168,8 +188,8 @@e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 1, 0) AS step_0,- if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 1, 0) AS step_1+ if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_0,+ if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_1FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -178,6 +198,16 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.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('user did things', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -294,7 +324,24 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,+ person_distinct_id_overrides.distinct_id AS distinct_id+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -326,7 +373,24 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,+ person_distinct_id_overrides.distinct_id AS distinct_id+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)