Skip to content

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

chore(data-warehouse): remove the column statistics rollout flag (#109154)

Tom Owers7e7d4ed95e61
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 78d6d3da337c..e6a9b90d3c4c 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -299,7 +299,6 @@ export const FEATURE_FLAGS = {
DASHBOARD_WIDGETS: 'dashboard-widgets', // owner: @mattp #team-analytics-platform
DATA_MODELING_INCREMENTAL_VIEWS: 'data-modeling-incremental-views', // owner: #team-data-modeling
DATA_QUALITY_CHECKS: 'data-quality-checks', // owner: #team-data-modeling
- DATA_WAREHOUSE_COLUMN_STATISTICS: 'data-warehouse-column-statistics', // owner: #team-warehouse-sources
DATA_WAREHOUSE_CUSTOM_SOURCE_AI_BUILDER: 'dwh-custom-source-ai-builder', // owner: #team-warehouse-sources
DATA_WAREHOUSE_CUSTOM_SOURCE_OAUTH2: 'dwh-custom-source-oauth2', // owner: #team-warehouse-sources
DATA_WAREHOUSE_SCENE: 'data-warehouse-scene', // owner: #team-data-modeling
diff --git a/products/warehouse_sources/backend/temporal/data_imports/post_import_job.py b/products/warehouse_sources/backend/temporal/data_imports/post_import_job.py
index d24e5502bb16..15f2f3db9ba8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/post_import_job.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/post_import_job.py
@@ -53,7 +53,6 @@ from products.warehouse_sources.backend.temporal.data_imports.workflow_activitie
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.compute_table_statistics import (
ComputeTableStatisticsInputs,
ComputeTableStatisticsWorkflow,
- statistics_enabled,
)
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.create_job_model import (
_enrichment_pending,
@@ -155,9 +154,7 @@ def _enrichment_gate(gate: PostImportGateContext) -> bool:
def _statistics_gate(gate: PostImportGateContext) -> bool:
- return bool(
- gate.team is not None and statistics_enabled(gate.team) and _statistics_stale(gate.team_id, gate.schema.table)
- )
+ return bool(gate.team is not None and _statistics_stale(gate.team_id, gate.schema.table))
def _always(gate: PostImportGateContext) -> bool:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
index c7c95e94da6d..a4c10e7d64be 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
@@ -52,7 +52,6 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.d
logger = structlog.get_logger(__name__)
-STATISTICS_FEATURE_FLAG = "data-warehouse-column-statistics"
# Cap profiling to once a day per table — an hourly-syncing table doesn't need re-profiling every hour,
# and Delta-log stats only move materially over longer windows. Env-overridable for ops.
MIN_RECOMPUTE_INTERVAL = timedelta(hours=int(os.getenv("WAREHOUSE_STATS_MIN_RECOMPUTE_INTERVAL_HOURS", "24")))
@@ -80,26 +79,6 @@ class ComputeTableStatisticsInputs:
return {"team_id": self.team_id, "schema_id": str(self.schema_id)}
-def statistics_enabled(team: Team) -> bool:
- try:
- return bool(
- posthoganalytics.feature_enabled(
- STATISTICS_FEATURE_FLAG,
- str(team.uuid),
- groups={"organization": str(team.organization_id), "project": str(team.id)},
- group_properties={
- "organization": {"id": str(team.organization_id)},
- "project": {"id": str(team.id)},
- },
- only_evaluate_locally=False,
- send_feature_flag_events=False,
- )
- )
- except Exception as e:
- capture_exception(e)
- return False
-
-
def capture_statistics_event(team: Team, event: str, properties: dict[str, Any]) -> None:
"""Best-effort product-analytics capture, attributed to the team's org/project groups.
@@ -496,8 +475,8 @@ def _get_team(team_id: int) -> Team:
def compute_table_statistics_sync(team_id: int, schema_id: uuid.UUID) -> dict[str, Any]:
"""Compute and persist per-column statistics for one warehouse table. Safe to re-run."""
- # Lazy: DeltaTableRef drags deltalake/pyarrow/dlt — keep them off the flag-check import path that
- # create_external_data_job_model_activity uses (it only imports statistics_enabled).
+ # Lazy: DeltaTableRef drags deltalake/pyarrow/dlt — keep them off the import path of modules that
+ # only need this module's workflow and input types.
from asgiref.sync import async_to_sync # noqa: PLC0415
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table import ( # noqa: PLC0415
@@ -521,10 +500,6 @@ def compute_table_statistics_sync(team_id: int, schema_id: uuid.UUID) -> dict[st
def emit_completed(status: str, **props: Any) -> None:
capture_statistics_event(team, EVENT_COMPLETED, {"status": status, **event_props, **props})
- if not statistics_enabled(team):
- emit_completed("skipped", reason="flag_disabled")
- return {"status": "skipped", "reason": "flag_disabled"}
-
schema = (
ExternalDataSchema.objects.select_related("source", "table")
.filter(team_id=team_id, deleted=False)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
index e78474afebf7..909cbfa15d11 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
@@ -445,13 +445,8 @@ def create_external_data_job_model_activity(
inputs.team_id, source.source_type, schema.name, ai_data_processing_approved
)
- # Column-statistics profiling is gated on its feature flag only (no consent term) — let the
- # workflow skip the child rather than spawn a no-op. Lazy import keeps deltalake off this path.
- from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.compute_table_statistics import ( # noqa: PLC0415
- statistics_enabled,
- )
-
- statistics_should_run = bool(team is not None and statistics_enabled(team))
+ # Column-statistics profiling needs no consent term, only a team to attribute it to.
+ statistics_should_run = team is not None
# Narrow "permitted" down to "permitted AND has work to do" so steady-state syncs don't spawn
# no-op metadata workflows. The activities re-check this themselves as a safety net.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
index 377f70864377..27109d03cfd2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
@@ -278,7 +278,6 @@ class TestComputeTableStatisticsSync:
}
helper = self._mock_delta(pa.table({"num_records": [999]}), version=9)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", side_effect=lambda _uri, _options, version: commits[version]),
patch(DELTA_HELPER_PATH, return_value=helper),
):
@@ -307,7 +306,6 @@ class TestComputeTableStatisticsSync:
# First fold: version 7 -> 8.
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(10, amount=(1, 60, 1))]),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(pa.table({"num_records": [999]}), version=8)),
):
@@ -327,7 +325,6 @@ class TestComputeTableStatisticsSync:
# Second fold: version 8 -> 9. A fold that reset full_scan_at would make the row look like
# it was freshly full-scanned; it must not.
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(5, amount=(3, 7, 0))]),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(pa.table({"num_records": [999]}), version=9)),
):
@@ -344,7 +341,6 @@ class TestComputeTableStatisticsSync:
)
add_actions = pa.table({"num_records": [999], "null_count.amount": [0], "min.amount": [0], "max.amount": [100]})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(2, amount=(0, 100, 0))]) as mock_read,
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions, version=10)),
):
@@ -371,7 +367,6 @@ class TestComputeTableStatisticsSync:
)
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(1, amount=(1, 1, 0))]) as mock_read,
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions, version=8)),
):
@@ -444,7 +439,6 @@ class TestComputeTableStatisticsSync:
helper = self._mock_delta(pa.table({"num_records": [999]}), version=8, delta_types={"amount": delta_type})
commit = [self._add(1, amount=(log_min, log_max, 0))]
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=commit),
patch(DELTA_HELPER_PATH, return_value=helper),
):
@@ -505,7 +499,6 @@ class TestComputeTableStatisticsSync:
)
helper = self._mock_delta(add_actions, version=table_version, delta_types=columns)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=commit) as mock_read,
patch.object(comp, "capture_exception") as mock_capture,
patch(DELTA_HELPER_PATH, return_value=helper),
@@ -532,7 +525,6 @@ class TestComputeTableStatisticsSync:
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
helper = self._mock_delta(add_actions, version=8, delta_types={"amount": "long"})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(1, amount=(1, 1, 0))]) as mock_read,
patch.object(comp, "capture_exception") as mock_capture,
patch(DELTA_HELPER_PATH, return_value=helper),
@@ -562,7 +554,6 @@ class TestComputeTableStatisticsSync:
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
helper = self._mock_delta(add_actions, version=8, delta_types=delta_types)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=[self._add(1, amount=(1, 1, 0))]) as mock_read,
patch.object(comp, "capture_exception") as mock_capture,
patch(DELTA_HELPER_PATH, return_value=helper),
@@ -589,7 +580,6 @@ class TestComputeTableStatisticsSync:
delta_types={"amount": "long", "payload": {"type": "struct", "fields": []}},
)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch.object(comp, "_read_commit_actions", return_value=commit),
patch(DELTA_HELPER_PATH, return_value=helper),
):
@@ -603,15 +593,6 @@ class TestComputeTableStatisticsSync:
amount = WarehouseColumnStatistics.objects.for_team(team.id).get(table_id=table.id, column_name="amount")
assert amount.max_value == "60"
- def test_skipped_when_flag_disabled(self) -> None:
- team = self._team()
- self._schema_table_job(team)
- schema = ExternalDataSchema.objects.get(team=team)
- with patch.object(comp, "statistics_enabled", return_value=False):
- result = compute_table_statistics_sync(team.id, schema.id)
- assert result == {"status": "skipped", "reason": "flag_disabled"}
- assert WarehouseColumnStatistics.objects.for_team(team.id).count() == 0
-
def test_persists_per_column_statistics(self) -> None:
team = self._team()
schema, table, _ = self._schema_table_job(team)
@@ -619,7 +600,6 @@ class TestComputeTableStatisticsSync:
{"num_records": [10, 30], "null_count.amount": [1, 3], "min.amount": [5, 2], "max.amount": [9, 50]}
)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions, version=12)),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -643,7 +623,6 @@ class TestComputeTableStatisticsSync:
schema, table, _ = self._schema_table_job(team)
add_actions = pa.table({"num_records": [10], "null_count.amount": [1], "min.amount": [5], "max.amount": [9]})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions)),
patch.object(
comp, "_upsert_statistics", side_effect=[OperationalError("server conn crashed?"), None]
@@ -673,7 +652,6 @@ class TestComputeTableStatisticsSync:
with (
patch.object(comp.Team.objects, "select_related", side_effect=select_related_losing_first_deadlock),
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions)),
patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.common.db_retry.time.sleep"),
patch(
@@ -699,7 +677,6 @@ class TestComputeTableStatisticsSync:
return self._mock_delta(add_actions)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, side_effect=_capture_helper),
):
compute_table_statistics_sync(team.id, schema.id)
@@ -715,7 +692,6 @@ class TestComputeTableStatisticsSync:
schema, table, _ = self._schema_table_job(team)
add_actions = pa.table({"num_records": [1], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions)),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -735,7 +711,6 @@ class TestComputeTableStatisticsSync:
)
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(add_actions, version=5)),
):
compute_table_statistics_sync(team.id, schema.id)
@@ -774,7 +749,6 @@ class TestComputeTableStatisticsSync:
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
helper = self._mock_delta(add_actions, version=table_version)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -832,7 +806,6 @@ class TestComputeTableStatisticsSync:
)
helper = self._mock_delta(add_actions, version=7)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -868,7 +841,6 @@ class TestComputeTableStatisticsSync:
add_actions = pa.table({"num_records": [99], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})
helper = self._mock_delta(add_actions, version=7)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -910,7 +882,6 @@ class TestComputeTableStatisticsSync:
)
helper = self._mock_delta(add_actions, version=7)
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -926,7 +897,6 @@ class TestComputeTableStatisticsSync:
schema, _, _ = self._schema_table_job(team, columns={})
helper = self._mock_delta(pa.table({"num_records": [1]}))
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper),
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -942,7 +912,6 @@ class TestComputeTableStatisticsSync:
)
helper = self._mock_delta(pa.table({"num_records": [1]}))
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=helper) as mock_helper,
):
result = compute_table_statistics_sync(team.id, schema.id)
@@ -971,8 +940,7 @@ class TestComputeTableStatisticsSync:
source_id="src", connection_id="conn", team=team, source_type="Stripe"
)
schema = ExternalDataSchema.objects.create(name="Charge", team=team, source=source, table=None)
- with patch.object(comp, "statistics_enabled", return_value=True):
- result = compute_table_statistics_sync(team.id, schema.id)
+ result = compute_table_statistics_sync(team.id, schema.id)
assert result == {"status": "skipped", "reason": "no_table"}
def test_skipped_when_no_files(self) -> None:
@@ -980,7 +948,6 @@ class TestComputeTableStatisticsSync:
schema, table, _ = self._schema_table_job(team)
empty = pa.table({"num_records": pa.array([], type=pa.int64())})
with (
- patch.object(comp, "statistics_enabled", return_value=True),
patch(DELTA_HELPER_PATH, return_value=self._mock_delta(empty)),
):
result = compute_table_statistics_sync(team.id, schema.id)