: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(clickhouse): skip teams without overrides in the events_json squash (#114596)
Rory Shanksbaabf3fd3ab4
diff --git a/posthog/dags/common/overrides_manager.py b/posthog/dags/common/overrides_manager.pyindex 1bf151ab6315..a24127c9a7e9 100644--- a/posthog/dags/common/overrides_manager.py+++ b/posthog/dags/common/overrides_manager.py@@ -152,7 +152,7 @@ class OverridesSnapshotDictionary(ABC, Generic[TOverridesSnapshotTable]):return self.get_checksum(client)@abstractmethod- def update_commands(self, partition_clause: str = "") -> set[str]:+ def update_commands(self, partition_clause: str = "", filter_teams: bool = False) -> set[str]:raise NotImplementedError()def update_mutation_runner_for(self, table: str, partition_id: str | None = None) -> AlterTableMutationRunner:@@ -160,7 +160,7 @@ class OverridesSnapshotDictionary(ABC, Generic[TOverridesSnapshotTable]):A squash rewrites every table that stamps the overridden column, so the table is anargument rather than a property of the snapshot. A partition_id limits the rewrite to that- one partition.+ one partition and to the teams in the snapshot."""if partition_id is None:return AlterTableMutationRunner(@@ -170,7 +170,7 @@ class OverridesSnapshotDictionary(ABC, Generic[TOverridesSnapshotTable]):)return AlterTableMutationRunner(table=table,- commands=self.update_commands(" IN PARTITION ID %(partition_id)s"),+ commands=self.update_commands(" IN PARTITION ID %(partition_id)s", filter_teams=True),parameters={"name": self.qualified_name, "partition_id": partition_id},)diff --git a/posthog/dags/person_overrides.py b/posthog/dags/person_overrides.pyindex 71389a67701f..4d820c359791 100644--- a/posthog/dags/person_overrides.py+++ b/posthog/dags/person_overrides.py@@ -132,9 +132,12 @@ class PersonOverridesSnapshotDictionary(OverridesSnapshotDictionary):[[checksum]] = resultsreturn checksum- def update_commands(self, partition_clause: str = "") -> set[str]:+ def update_commands(self, partition_clause: str = "", filter_teams: bool = False) -> set[str]:+ # team_id leads the sorting key, so this set lets the read skip the granules of every team+ # with no override instead of looking up each of their rows in the dictionary.+ team_filter = " AND team_id IN (SELECT DISTINCT team_id FROM dictionary(%(name)s))" if filter_teams else ""return {- f"UPDATE person_id = dictGet(%(name)s, 'person_id', (team_id, distinct_id)){partition_clause} WHERE dictHas(%(name)s, (team_id, distinct_id)) AND person_id != dictGet(%(name)s, 'person_id', (team_id, distinct_id))"+ f"UPDATE person_id = dictGet(%(name)s, 'person_id', (team_id, distinct_id)){partition_clause} WHERE dictHas(%(name)s, (team_id, distinct_id)) AND person_id != dictGet(%(name)s, 'person_id', (team_id, distinct_id)){team_filter}"}@property