: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
chore(product-analytics): move funnels query runners into the product (#90749)
Thomas Obermüllerba25acd45498
diff --git a/.semgrep/rules/devex/no-init-reexports.yaml b/.semgrep/rules/devex/no-init-reexports.yamlindex 0b4b82c3402f..7c6310a45454 100644--- a/.semgrep/rules/devex/no-init-reexports.yaml+++ b/.semgrep/rules/devex/no-init-reexports.yaml@@ -66,7 +66,7 @@ rules:- 'posthog/dags/common/__init__.py'- 'products/managed_warehouse/backend/logic/verification/__init__.py'- 'posthog/helpers/__init__.py'- - 'posthog/hogql_queries/insights/funnels/__init__.py'+ - 'products/product_analytics/backend/hogql_queries/funnels/__init__.py'- 'posthog/plugins/__init__.py'- 'posthog/queries/properties_timeline/__init__.py'- 'products/ai_observability/backend/api/__init__.py'diff --git a/frontend/src/scenes/funnels/funnelUtils.tsx b/frontend/src/scenes/funnels/funnelUtils.tsxindex d1343e88e436..f415915d8858 100644--- a/frontend/src/scenes/funnels/funnelUtils.tsx+++ b/frontend/src/scenes/funnels/funnelUtils.tsx@@ -39,7 +39,7 @@ import {PropertyOperator,} from '~/types'-// Keep in sync with CONVERSION_WINDOW_INTERVAL_BOUNDS in posthog/hogql_queries/insights/funnels/utils.py,+// Keep in sync with CONVERSION_WINDOW_INTERVAL_BOUNDS in products/product_analytics/backend/hogql_queries/funnels/utils.py,// which enforces the same bounds server-side for the paths v2 gap.export const TIME_INTERVAL_BOUNDS: Record<FunnelConversionWindowTimeUnit, number[]> = {[FunnelConversionWindowTimeUnit.Second]: [1, 3600],diff --git a/posthog/api/test/test_query.py b/posthog/api/test/test_query.pyindex b0ec08bed153..37031879cad6 100644--- a/posthog/api/test/test_query.py+++ b/posthog/api/test/test_query.py@@ -1527,59 +1527,39 @@ class TestQueryLLMFormatting(ClickhouseTestMixin, APIBaseTest):@parameterized.expand([- # An explicit ISO timestamp (including midnight Z) is an exact boundary, not a calendar day.- ("explicit_midnight", "2026-07-09T00:00:00Z", "to 2026-07-09 00:00:00"),- ("explicit_time_of_day", "2026-07-09T14:30:00Z", "to 2026-07-09 14:30:00"),- # A bare calendar day keeps the default end-of-day rounding so the last day stays included.- ("bare_date", "2026-07-09", "to 2026-07-09 23:59:59"),+ # An MCP caller passing a full timestamp means an exact boundary, so the range is marked+ # explicit and keeps the time of day instead of snapping to end of day.+ ("mcp_explicit_midnight", True, "2026-07-09T00:00:00Z", True),+ ("mcp_explicit_time_of_day", True, "2026-07-09T14:30:00Z", True),+ # A bare calendar day carries no time of day, so it keeps the default end-of-day rounding+ # and the last day stays in range.+ ("mcp_bare_date", True, "2026-07-09", False),+ # The web UI serialises fixed calendar ranges as naive timestamps and relies on that same+ # rounding, so a non-MCP request must never have its boundary marked explicit.+ ("non_mcp_explicit_timestamp", False, "2026-07-09T00:00:00Z", False),])@patch("posthog.api.query.process_query_model")- def test_mcp_funnel_respects_explicit_timestamp_date_to(- self, _name, date_to, expected_range_suffix, mock_process_query_model+ def test_explicit_date_boundary_marking(+ self, _name, is_mcp_client, date_to, expected_explicit, mock_process_query_model):- mock_process_query_model.return_value = {- "results": [- {"name": "$pageview", "count": 10, "average_conversion_time": None, "median_conversion_time": None}- ],- "is_cached": False,- }-- response = self.client.post(- f"/api/environments/{self.team.id}/query/",- {- "query": {- "kind": "FunnelsQuery",- "series": [{"kind": "EventsNode", "event": "$pageview"}],- "dateRange": {"date_from": "2026-07-02T00:00:00Z", "date_to": date_to},- }- },- HTTP_X_POSTHOG_CLIENT="mcp",- )-- self.assertEqual(response.status_code, 200)- formatted = response.json()["formatted_results"]- self.assertIn(expected_range_suffix, formatted)-- @patch("posthog.api.query.process_query_model")- def test_non_mcp_request_does_not_mark_explicit_date(self, mock_process_query_model):- # The web UI serialises fixed calendar ranges as naive timestamps and relies on end-of-day- # rounding, so a non-MCP request must never have its date boundary marked explicit.mock_process_query_model.return_value = {"results": [], "is_cached": False}- self.client.post(- f"/api/environments/{self.team.id}/query/",- {- "query": {- "kind": "FunnelsQuery",- "series": [{"kind": "EventsNode", "event": "$pageview"}],- "dateRange": {"date_from": "2026-07-02T00:00:00Z", "date_to": "2026-07-09T00:00:00Z"},- }- },- )+ url = f"/api/environments/{self.team.id}/query/"+ payload = {+ "query": {+ "kind": "LifecycleQuery",+ "series": [{"kind": "EventsNode", "event": "$pageview"}],+ "dateRange": {"date_from": "2026-07-02T00:00:00Z", "date_to": date_to},+ }+ }+ if is_mcp_client:+ self.client.post(url, payload, HTTP_X_POSTHOG_CLIENT="mcp")+ else:+ self.client.post(url, payload)executed_query = mock_process_query_model.call_args.args[1]- self.assertFalse(executed_query.dateRange.explicitDate)+ self.assertEqual(bool(executed_query.dateRange.explicitDate), expected_explicit)class TestMcpProductTaggingEndToEnd(ClickhouseTestMixin, APIBaseTest):diff --git a/posthog/hogql_queries/actors_query_runner.py b/posthog/hogql_queries/actors_query_runner.pyindex cb3c6032d5a0..a68de5a6d772 100644--- a/posthog/hogql_queries/actors_query_runner.py+++ b/posthog/hogql_queries/actors_query_runner.py@@ -27,7 +27,6 @@ from posthog.hogql.resolver_utils import extract_select_queriesfrom posthog.api.person import PERSON_DEFAULT_DISPLAY_NAME_PROPERTIESfrom posthog.clickhouse.query_tagging import tag_contains_user_hogqlfrom posthog.hogql_queries.actor_strategies import ActorStrategy, GroupStrategy, PersonStrategy, SessionStrategy-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.insight_actors_query_runner import InsightActorsQueryRunnerfrom posthog.hogql_queries.insights.paginators import HogQLHasMorePaginatorfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunner, ExecutionMode, QueryRunner, get_query_runner@@ -35,6 +34,8 @@ from posthog.hogql_queries.utils.person_display_name import person_display_name_from posthog.models import Userfrom posthog.slo.context import tag_current_slo+from products.product_analytics.backend.facade.queries import FunnelsQueryRunner+class ActorsQueryRunner(AnalyticsQueryRunner[ActorsQueryResponse]):query: ActorsQuerydiff --git a/posthog/hogql_queries/insights/insight_actors_query_options_runner.py b/posthog/hogql_queries/insights/insight_actors_query_options_runner.pyindex 8aae7cebb1bd..66bc4afe7485 100644--- a/posthog/hogql_queries/insights/insight_actors_query_options_runner.py+++ b/posthog/hogql_queries/insights/insight_actors_query_options_runner.py@@ -8,12 +8,13 @@ from posthog.schema import (from posthog.hogql import ast-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.lifecycle.lifecycle_query_runner import LifecycleQueryRunnerfrom posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunnerfrom posthog.hogql_queries.query_runner import QueryRunner, get_query_runnerfrom posthog.models.filters.mixins.utils import cached_property+from products.product_analytics.backend.facade.queries import FunnelsQueryRunner+class InsightActorsQueryOptionsRunner(QueryRunner):query: InsightActorsQueryOptionsdiff --git a/posthog/hogql_queries/insights/insight_actors_query_runner.py b/posthog/hogql_queries/insights/insight_actors_query_runner.pyindex 027806d3bebd..c1ca4a34d2d6 100644--- a/posthog/hogql_queries/insights/insight_actors_query_runner.py+++ b/posthog/hogql_queries/insights/insight_actors_query_runner.py@@ -24,8 +24,6 @@ from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.hogql.query import execute_hogql_queryfrom posthog.hogql.timings import HogQLTimings-from posthog.hogql_queries.insights.funnels.funnel_correlation_query_runner import FunnelCorrelationQueryRunner-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.lifecycle.lifecycle_query_runner import LifecycleQueryRunnerfrom posthog.hogql_queries.insights.retention.retention_query_runner import RetentionQueryRunnerfrom posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner@@ -37,6 +35,8 @@ from posthog.types import InsightActorsQueryNodefrom products.experiments.backend.hogql_queries.experiment_query_runner import ExperimentQueryRunnerfrom products.product_analytics.backend.facade.queries import (+ FunnelCorrelationQueryRunner,+ FunnelsQueryRunner,PathsQueryRunner,PathsV2QueryRunner,StickinessQueryRunner,diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambrindex 2df43d3dd977..2c42a8c0a7a1 100644--- a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr+++ b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr@@ -21,70 +21,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_funnels_query- '''- SELECT name AS name- FROM- (SELECT persons.properties___name AS name- FROM- (SELECT aggregation_target AS actor_id- 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), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, 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.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'US/Pacific') 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, '$pageview'), 1, 0) AS step_0,- if(equals(e.event, '$pageview'), 1, 0) AS step_1- FROM events AS e- 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)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('$pageview'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 1)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- INNER JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- 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, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_lifecycle_query'''SELECT n AS ndiff --git a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.pyindex fbd9cfc9a2d4..77024d6c4b9c 100644--- a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py+++ b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py@@ -336,58 +336,6 @@ class TestInsightActorsQueryRunner(ClickhouseTestMixin, APIBaseTest):self.assertEqual([("org1",)], response.results)- @snapshot_clickhouse_queries- def test_insight_persons_funnels_query(self):- self._create_test_events()- self.team.timezone = "US/Pacific"- self.team.save()-- response = self.select(- """- select * from (- <ActorsQuery select={['properties.name']}>- <FunnelsActorsQuery funnelStep={2}>- <FunnelsQuery- dateRange={<DateRange date_from='2020-01-01' date_to='2020-01-19' />}- series={[<EventsNode event='$pageview' />, <EventsNode event='$pageview' />]}- />- </FunnelsActorsQuery>- </ActorsQuery>- )- """- )-- self.assertEqual([("p1",), ("p2",)], response.results)-- def test_insight_groups_funnels_query(self):- self._create_test_groups()- self._create_test_events()- self.team.timezone = "US/Pacific"- self.team.save()-- response = self.select(- """- select * from (- <ActorsQuery select={['properties.name']}>- <FunnelsActorsQuery funnelStep={2}>- <FunnelsQuery- aggregation_group_type_index={0}- dateRange={<DateRange date_from='2020-01-01' date_to='2020-01-19' />}- series={[<EventsNode event='$pageview' />, <EventsNode event='$pageview' />]}- />- </FunnelsActorsQuery>- </ActorsQuery>- )- """- )-- self.assertEqual(- [- ("org1",),- ],- response.results,- )-def test_insight_actors_trends_weekly_active_groups(self):self._create_test_groups()self._create_test_events()diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.pyindex 5b7048e49db9..11f44c0ecc76 100644--- a/posthog/hogql_queries/query_runner.py+++ b/posthog/hogql_queries/query_runner.py@@ -600,7 +600,7 @@ def get_query_runner(user=user,)if kind == "FunnelsQuery":- from .insights.funnels.funnels_query_runner import FunnelsQueryRunner+ from products.product_analytics.backend.facade.queries import FunnelsQueryRunnerreturn FunnelsQueryRunner(query=cast(FunnelsQuery | dict[str, Any], query),@@ -775,7 +775,7 @@ def get_query_runner(user=user,)if kind == "FunnelCorrelationQuery":- from .insights.funnels.funnel_correlation_query_runner import FunnelCorrelationQueryRunner+ from products.product_analytics.backend.facade.queries import FunnelCorrelationQueryRunnerreturn FunnelCorrelationQueryRunner(query=cast(FunnelCorrelationQuery | dict[str, Any], query),diff --git a/posthog/hogql_queries/test/test_dashboard_filters_overrides.py b/posthog/hogql_queries/test/test_dashboard_filters_overrides.pyindex 10a5d345c3fd..ac1b9d9be15d 100644--- a/posthog/hogql_queries/test/test_dashboard_filters_overrides.py+++ b/posthog/hogql_queries/test/test_dashboard_filters_overrides.py@@ -8,7 +8,6 @@ from posthog.schema import (DashboardFilter,DataWarehouseNode,EventsNode,- FunnelsQuery,IntervalType,LifecycleQuery,RetentionFilter,@@ -20,7 +19,6 @@ from posthog.hogql_queries.apply_dashboard_filters import (apply_dashboard_filters_to_dict,resolve_effective_dashboard_filters,)-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.lifecycle.lifecycle_query_runner import LifecycleQueryRunnerfrom posthog.hogql_queries.insights.retention.retention_query_runner import RetentionQueryRunnerfrom posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner@@ -29,18 +27,14 @@ from posthog.models import Team_TIME_SERIES = [EventsNode(event="$pageview")]-# Only core-owned runners belong here. Product-owned runners (paths, stickiness) cover the-# same dashboard-filter behavior in their own product tests.+# Only core-owned runners belong here. Product-owned runners (funnels, paths, stickiness) cover+# the same dashboard-filter behavior in their own product tests.# Runners whose query model carries an `interval` field.INTERVAL_QUERY_RUNNERS: list[tuple[str, Callable[[Team], QueryRunner]]] = [("trends",lambda team: TrendsQueryRunner(query=TrendsQuery(series=_TIME_SERIES, interval=IntervalType.DAY), team=team),),- (- "funnels",- lambda team: FunnelsQueryRunner(query=FunnelsQuery(series=_TIME_SERIES), team=team),- ),("lifecycle",lambda team: LifecycleQueryRunner(diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.pyindex 75dd99ffdfc3..4751baf125bc 100644--- a/posthog/hogql_queries/test/test_query_runner.py+++ b/posthog/hogql_queries/test/test_query_runner.py@@ -1134,92 +1134,6 @@ class TestApplySeriesCustomNames(BaseTest):self.assertEqual(patched_response.results, expected_results)- @parameterized.expand(- [- (- "patches_funnel_steps_without_breakdown",- [- {"order": 0, "custom_name": "Old Step 1", "count": 100},- {"order": 1, "custom_name": "Old Step 2", "count": 50},- ],- [- {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},- {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},- ],- True,- ),- (- "patches_funnel_steps_with_breakdown",- [- [- {"order": 0, "custom_name": None, "count": 100, "breakdown": "Chrome"},- {"order": 1, "custom_name": None, "count": 50, "breakdown": "Chrome"},- ],- [- {"order": 0, "custom_name": None, "count": 80, "breakdown": "Firefox"},- {"order": 1, "custom_name": None, "count": 40, "breakdown": "Firefox"},- ],- ],- [- [- {"order": 0, "custom_name": "Step 1 Renamed", "count": 100, "breakdown": "Chrome"},- {"order": 1, "custom_name": "Step 2 Renamed", "count": 50, "breakdown": "Chrome"},- ],- [- {"order": 0, "custom_name": "Step 1 Renamed", "count": 80, "breakdown": "Firefox"},- {"order": 1, "custom_name": "Step 2 Renamed", "count": 40, "breakdown": "Firefox"},- ],- ],- True,- ),- (- "not_modified_when_names_match",- [- {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},- {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},- ],- [- {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},- {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},- ],- False,- ),- ]- )- def test_apply_funnels_custom_names(- self,- _name: str,- cached_results: list,- expected_results: list,- expect_modified: bool,- ):- from posthog.schema import CachedFunnelsQueryResponse, FunnelsQuery-- from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-- query = FunnelsQuery(- series=[- EventsNode(event="step1", custom_name="Step 1 Renamed"),- EventsNode(event="step2", custom_name="Step 2 Renamed"),- ]- )-- runner = FunnelsQueryRunner(query=query, team=self.team)-- cached_response = CachedFunnelsQueryResponse(- results=cached_results,- is_cached=True,- last_refresh=datetime.now(UTC),- next_allowed_client_refresh=datetime.now(UTC),- cache_key="test_key",- timezone="UTC",- )-- patched_response, was_modified = runner.apply_series_custom_names(cached_response)-- self.assertEqual(patched_response.results, expected_results)- self.assertEqual(was_modified, expect_modified)-@parameterized.expand([(diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 0b5fb537fe40..03f8eb44ae50 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -34,7 +34,6 @@1 posthog/hogql/transforms/lazy_tables.py1 posthog/hogql/transforms/test/test_property_types.py1 posthog/hogql/transforms/test/test_property_types_dmat.py-1 posthog/hogql_queries/insights/funnels/funnel_event_query.py1 posthog/hogql_queries/insights/utils/aggregations.py1 posthog/kafka_client/client.py1 posthog/management/commands/audit_encrypted_field_keys.py@@ -162,6 +161,7 @@1 products/posthog_ai/eval_harness/harness/reporting.py1 products/posthog_ai/eval_harness/runner.py1 products/posthog_ai/eval_harness/scorers/tracing.py+1 products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.py1 products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.py1 products/product_tours/backend/generate_tour_content/generate.py1 products/pulse/backend/temporal/activities.py@@ -1389,7 +1389,6 @@2 posthog/helpers/email_utils.py2 posthog/hogql/context.py2 posthog/hogql/database/models.py-2 posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py2 posthog/management/commands/generate_test_events.py2 posthog/management/migration_analysis/models.py2 posthog/models/data_deletion_request.py@@ -1445,6 +1444,7 @@2 products/marketing_analytics/backend/services/campaign_field_suggester.py2 products/marketing_analytics/backend/services/event_suggestions.py2 products/notebooks/backend/collab.py+2 products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.py2 products/product_analytics/backend/hogql_queries/stickiness/test/test_stickiness_query_runner.py2 products/review_hog/backend/reviewer/progress.py2 products/review_hog/backend/reviewer/tools/select_perspectives.py@@ -1573,6 +1573,7 @@4 products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py4 products/marketing_analytics/backend/services/campaign_mapping_suggester.py4 products/marketing_analytics/backend/services/conversion_goals_inspector.py+4 products/signals/backend/temporal/buffer.py4 products/tasks/backend/temporal/process_task/activities/slack_agent_design.py4 products/tasks/backend/temporal/process_task/activities/start_agent_server.py4 products/tasks/backend/temporal/process_task/workflow.py@@ -1593,7 +1594,6 @@5 products/customer_analytics/backend/temporal/calendar_sync.py5 products/managed_warehouse/backend/temporal/ducklake_copy_data_modeling_workflow.py5 products/notebooks/backend/kernel_runtime.py-4 products/signals/backend/temporal/buffer.py5 products/tasks/backend/temporal/execute_sandbox/workflow.py6 posthog/dags/deletes.py6 posthog/hogql/base.pydiff --git a/products/alerts/backend/tests/api/test_alert.py b/products/alerts/backend/tests/api/test_alert.pyindex 1c71908f42b9..d92c92726ca2 100644--- a/products/alerts/backend/tests/api/test_alert.py+++ b/products/alerts/backend/tests/api/test_alert.py@@ -170,32 +170,6 @@ class TestAlert(APIBaseTest, QueryMatchingTest):assert delete.status_code == status.HTTP_404_NOT_FOUND, delete.contentassert [a["id"] for a in listed.json()["results"]] == []- def test_create_alert_on_funnel_insight(self) -> None:- funnel_insight = self.client.post(- f"/api/projects/{self.team.id}/insights",- data={- "query": {- "kind": "FunnelsQuery",- "series": [- {"kind": "EventsNode", "event": "$pageview"},- {"kind": "EventsNode", "event": "$autocapture"},- ],- }- },- ).json()- creation_request = {- "insight": funnel_insight["id"],- "subscribed_users": [self.user.id],- "condition": {"type": AlertConditionType.ABSOLUTE_VALUE},- "config": {"type": "FunnelsAlertConfig", "metric": "conversion_from_start", "funnel_step": None},- "name": "funnel alert",- "threshold": {"configuration": {"type": InsightThresholdType.ABSOLUTE, "bounds": {"upper": 50}}},- "calculation_interval": "daily",- }-- response = self.client.post(f"/api/projects/{self.team.id}/alerts", creation_request)- assert response.status_code == status.HTTP_201_CREATED, response.content-def test_create_threshold_alert_rejects_empty_bounds(self) -> None:creation_request = {"insight": self.insight["id"],@@ -836,49 +810,6 @@ class TestAlert(APIBaseTest, QueryMatchingTest):response = self.client.get(f"/api/projects/{self.team.id}/alerts/{alert['id']}")assert response.status_code == status.HTTP_404_NOT_FOUND- def test_funnel_alert_survives_insight_update_and_is_listed_on_insight(self) -> None:- funnel_insight_data: dict[str, Any] = {- "query": {- "kind": "FunnelsQuery",- "series": [- {"kind": "EventsNode", "event": "$pageview"},- {"kind": "EventsNode", "event": "$autocapture"},- ],- },- }- funnel_insight = self.client.post(f"/api/projects/{self.team.id}/insights", data=funnel_insight_data).json()-- alert = self.client.post(- f"/api/projects/{self.team.id}/alerts",- {- "insight": funnel_insight["id"],- "subscribed_users": [self.user.id],- "condition": {"type": AlertConditionType.ABSOLUTE_VALUE},- "config": {"type": "FunnelsAlertConfig", "metric": "conversion_from_start", "funnel_step": None},- "threshold": {"configuration": {"type": InsightThresholdType.ABSOLUTE, "bounds": {"upper": 50}}},- "name": "funnel alert",- },- ).json()-- # The insight response must list the alert inline — the UI trusts this list on reload.- insight_response = self.client.get(f"/api/projects/{self.team.id}/insights/{funnel_insight['id']}").json()- assert [a["id"] for a in insight_response["alerts"]] == [alert["id"]]-- # Updating the insight while it stays funnel-backed must not cascade-delete the alert.- updated = deepcopy(funnel_insight_data)- updated["query"]["series"][1]["event"] = "$pageleave"- self.client.patch(f"/api/projects/{self.team.id}/insights/{funnel_insight['id']}", data=updated)- response = self.client.get(f"/api/projects/{self.team.id}/alerts/{alert['id']}")- assert response.status_code == status.HTTP_200_OK-- # Changing to a kind that cannot carry alerts still cascades.- self.client.patch(- f"/api/projects/{self.team.id}/insights/{funnel_insight['id']}",- data={"query": {"kind": "RetentionQuery", "retentionFilter": {}}},- )- response = self.client.get(f"/api/projects/{self.team.id}/alerts/{alert['id']}")- assert response.status_code == status.HTTP_404_NOT_FOUND-def test_alert_survives_switch_between_alertable_kinds(self) -> None:# Switching the insight to a different alertable kind (trends -> SQL) leaves the alert's config# mismatched, but the alert is NOT deleted: the check cycle re-validates against the currentdiff --git a/products/experiments/backend/hogql_queries/experiment_funnels_query_runner.py b/products/experiments/backend/hogql_queries/experiment_funnels_query_runner.pyindex 073075bd5112..8ecfddf7a890 100644--- a/products/experiments/backend/hogql_queries/experiment_funnels_query_runner.py+++ b/products/experiments/backend/hogql_queries/experiment_funnels_query_runner.py@@ -23,7 +23,6 @@ from posthog.hogql import astfrom posthog.clickhouse.query_tagging import tag_queriesfrom posthog.constants import ExperimentNoResultsErrorKeys-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.query_runner import QueryRunnerfrom products.experiments.backend.hogql_queries import CONTROL_VARIANT_KEY@@ -33,6 +32,7 @@ from products.experiments.backend.hogql_queries.funnels_statistics_v2 import (calculate_probabilities_v2,)from products.experiments.backend.models.experiment import Experiment+from products.product_analytics.backend.facade.queries import FunnelsQueryRunnerclass ExperimentFunnelsQueryRunner(QueryRunner):diff --git a/products/experiments/backend/metric_utils.py b/products/experiments/backend/metric_utils.pyindex 5a763989057d..cd5d78615e0d 100644--- a/products/experiments/backend/metric_utils.py+++ b/products/experiments/backend/metric_utils.py@@ -45,6 +45,20 @@ def get_default_metric_title(metric_dict: dict) -> str:logger = logging.getLogger(__name__)+# A legacy metric nests its query under a kind-specific key: ExperimentTrendsQuery under+# `count_query`, ExperimentFunnelsQuery under `funnels_query`.+LEGACY_METRIC_QUERY_KEYS = ("count_query", "funnels_query")+++def apply_metric_date_range(metric: dict[str, Any], date_range: dict[str, Any]) -> None:+ """Overwrite a legacy metric's nested query date range in place.++ Only a query that already carries a date range is rewritten, so the stored shape of a metric+ without one is preserved."""+ for key in LEGACY_METRIC_QUERY_KEYS:+ if metric.get(key, {}).get("dateRange"):+ metric[key]["dateRange"] = date_range+def refresh_action_names_in_metric(query: dict[str, Any] | None,diff --git a/products/experiments/backend/presentation/serializers.py b/products/experiments/backend/presentation/serializers.pyindex 634b856305de..097804a8845f 100644--- a/products/experiments/backend/presentation/serializers.py+++ b/products/experiments/backend/presentation/serializers.py@@ -39,7 +39,7 @@ from products.experiments.backend.hogql_queries.exposure_query_logic import resofrom products.experiments.backend.hogql_queries.utils import get_experiment_stats_methodfrom products.experiments.backend.llm_metric_templates import TEMPLATE_NAMESfrom products.experiments.backend.metric_events import MetricSourceRole-from products.experiments.backend.metric_utils import refresh_action_names_in_metric+from products.experiments.backend.metric_utils import apply_metric_date_range, refresh_action_names_in_metricfrom products.experiments.backend.models.experiment import (Experiment,ExperimentHoldout,@@ -551,10 +551,7 @@ class ExperimentSerializer(ExperimentBaseSerializer):metrics_list[i] = refreshed_metricmetric = refreshed_metric- if metric.get("count_query", {}).get("dateRange"):- metric["count_query"]["dateRange"] = new_date_range- if metric.get("funnels_query", {}).get("dateRange"):- metric["funnels_query"]["dateRange"] = new_date_range+ apply_metric_date_range(metric, new_date_range)# Update date ranges in saved metrics# Note: Action name refresh is handled by ExperimentToSavedMetricSerializer.to_representation@@ -563,10 +560,7 @@ class ExperimentSerializer(ExperimentBaseSerializer):span.set_attribute("saved_metric_count", len(saved_metrics))for saved_metric in saved_metrics:if saved_metric.get("query"):- if saved_metric["query"].get("count_query", {}).get("dateRange"):- saved_metric["query"]["count_query"]["dateRange"] = new_date_range- if saved_metric["query"].get("funnels_query", {}).get("dateRange"):- saved_metric["query"]["funnels_query"]["dateRange"] = new_date_range+ apply_metric_date_range(saved_metric["query"], new_date_range)# Add fingerprint to saved metric returned from API# so that frontend knows what timeseries records to querydiff --git a/products/experiments/backend/test/test_metric_utils.py b/products/experiments/backend/test/test_metric_utils.pyindex 7e599762ab92..c3abc980fc29 100644--- a/products/experiments/backend/test/test_metric_utils.py+++ b/products/experiments/backend/test/test_metric_utils.py@@ -8,6 +8,7 @@ from parameterized import parameterizedfrom products.actions.backend.models.action import Actionfrom products.experiments.backend.metric_utils import (+ apply_metric_date_range,collect_metric_events_and_action_ids,collect_metric_warehouse_tables,refresh_action_names_in_metric,@@ -500,3 +501,23 @@ class TestResolveActionEvents(BaseTest):def test_empty_makes_no_query(self):with self.assertNumQueries(0):assert resolve_action_events(set(), self.team) == {}+++class TestApplyMetricDateRange(SimpleTestCase):+ NEW_RANGE = {"date_from": "2025-02-01T00:00:00Z", "date_to": "", "explicitDate": True}++ @parameterized.expand([("trends", "count_query"), ("funnels", "funnels_query")])+ def test_overwrites_a_stale_nested_date_range(self, _name: str, query_key: str) -> None:+ metric = {query_key: {"dateRange": {"date_from": "2025-01-30T12:16", "date_to": "2025-02-13T23:59"}}}++ apply_metric_date_range(metric, self.NEW_RANGE)++ assert metric[query_key]["dateRange"] == self.NEW_RANGE++ @parameterized.expand([("trends", "count_query"), ("funnels", "funnels_query")])+ def test_leaves_a_metric_without_a_date_range_alone(self, _name: str, query_key: str) -> None:+ metric: dict = {query_key: {"series": []}}++ apply_metric_date_range(metric, self.NEW_RANGE)++ assert metric == {query_key: {"series": []}}diff --git a/products/experiments/backend/test/test_presentation_api.py b/products/experiments/backend/test/test_presentation_api.pyindex 7221f1e92529..469b079d5dce 100644--- a/products/experiments/backend/test/test_presentation_api.py+++ b/products/experiments/backend/test/test_presentation_api.py@@ -1527,24 +1527,6 @@ class TestExperimentCRUD(_HoistFlagConfigClientMixin, APILicensedTest):},created_by=self.user,)- funnel_query = {- "kind": "ExperimentFunnelsQuery",- "funnels_query": {- "kind": "FunnelsQuery",- "series": [- {"kind": "EventsNode", "name": "[jan-16-running] seen", "event": "[jan-16-running] seen"},- {"kind": "EventsNode", "name": "[jan-16-running] payment", "event": "[jan-16-running] payment"},- ],- "dateRange": {"date_to": "2025-02-13T23:59", "date_from": "2025-01-30T12:16", "explicitDate": True},- "funnelsFilter": {- "layout": "horizontal",- "funnelVizType": "steps",- "funnelWindowInterval": 14,- "funnelWindowIntervalUnit": "day",- },- "filterTestAccounts": True,- },- }trends_query = {"kind": "ExperimentTrendsQuery","count_query": {@@ -1570,54 +1552,39 @@ class TestExperimentCRUD(_HoistFlagConfigClientMixin, APILicensedTest):team=self.team,created_by=self.user,)- saved_funnel_metric = ExperimentSavedMetric.objects.create(- name="Test saved metric",- description="Test description",- query=funnel_query,- team=self.team,- created_by=self.user,- )experiment = Experiment.objects.create(name="Test Experiment with stale dates",team=self.team,feature_flag=test_feature_flag,start_date=datetime(2025, 2, 1),end_date=None,- metrics=[funnel_query],+ metrics=[trends_query],metrics_secondary=[trends_query],)- for saved_metric_data in [saved_funnel_metric, saved_trends_metric]:- saved_metric_serializer = ExperimentToSavedMetricSerializer(- data={- "experiment": experiment.id,- "saved_metric": saved_metric_data.id,- "metadata": {"type": "secondary"},- },- )- saved_metric_serializer.is_valid(raise_exception=True)- saved_metric_serializer.save()+ saved_metric_serializer = ExperimentToSavedMetricSerializer(+ data={+ "experiment": experiment.id,+ "saved_metric": saved_trends_metric.id,+ "metadata": {"type": "secondary"},+ },+ )+ saved_metric_serializer.is_valid(raise_exception=True)+ saved_metric_serializer.save()response = self.client.get(f"/api/projects/{self.team.id}/experiments/{experiment.id}")self.assertEqual(response.status_code, status.HTTP_200_OK)- self.assertEqual(- response.json()["metrics"][0]["funnels_query"]["dateRange"]["date_from"], "2025-02-01T00:00:00Z"- )- self.assertEqual(response.json()["metrics"][0]["funnels_query"]["dateRange"]["date_to"], "")+ self.assertEqual(response.json()["metrics"][0]["count_query"]["dateRange"]["date_from"], "2025-02-01T00:00:00Z")+ self.assertEqual(response.json()["metrics"][0]["count_query"]["dateRange"]["date_to"], "")self.assertEqual(response.json()["metrics_secondary"][0]["count_query"]["dateRange"]["date_from"], "2025-02-01T00:00:00Z")self.assertEqual(response.json()["metrics_secondary"][0]["count_query"]["dateRange"]["date_to"], "")self.assertEqual(- response.json()["saved_metrics"][0]["query"]["funnels_query"]["dateRange"]["date_from"],- "2025-02-01T00:00:00Z",- )- self.assertEqual(response.json()["saved_metrics"][0]["query"]["funnels_query"]["dateRange"]["date_to"], "")- self.assertEqual(- response.json()["saved_metrics"][1]["query"]["count_query"]["dateRange"]["date_from"],+ response.json()["saved_metrics"][0]["query"]["count_query"]["dateRange"]["date_from"],"2025-02-01T00:00:00Z",)- self.assertEqual(response.json()["saved_metrics"][1]["query"]["count_query"]["dateRange"]["date_to"], "")+ self.assertEqual(response.json()["saved_metrics"][0]["query"]["count_query"]["dateRange"]["date_to"], "")def test_adding_behavioral_cohort_filter_to_experiment_fails(self):cohort = Cohort.objects.create(diff --git a/products/product_analytics/backend/facade/queries.py b/products/product_analytics/backend/facade/queries.pyindex 37c847835aa2..e06a1a020449 100644--- a/products/product_analytics/backend/facade/queries.py+++ b/products/product_analytics/backend/facade/queries.py@@ -4,16 +4,19 @@ Facade re-exports for product analytics HogQL query runners.Core's query-runner registry (``posthog/hogql_queries/query_runner.py``) dispatcheson query ``kind`` and constructs these runners by class identity; the paths_v2presentation imports the segment-to-funnels helpers. The implementations stay in-``backend/hogql_queries/`` (the wiring location, covered by the contract-check-inputs). Runner modules pull the heavy HogQL import chain, so — like-warehouse_sources' pipeline facade — names resolve lazily (PEP 562), keeping the-runners off the ``django.setup()`` path that presentation loads at startup.+``backend/hogql_queries/`` (the wiring location, which stays out of the+contract-check inputs while no test outside the product drives it). Runner modules+pull the heavy HogQL import chain, so — like warehouse_sources' pipeline facade —+names resolve lazily (PEP 562), keeping the runners off the ``django.setup()`` path+that presentation loads at startup."""_B = "products.product_analytics.backend.hogql_queries."_LAZY = {"PATHS_V2_OTHER": "paths_v2.path_item",+ "FunnelCorrelationQueryRunner": "funnels.funnel_correlation_query_runner",+ "FunnelsQueryRunner": "funnels.funnels_query_runner","PathsQueryRunner": "paths.paths_query_runner","PathsV2QueryRunner": "paths_v2.paths_v2_query_runner","StickinessQueryRunner": "stickiness.stickiness_query_runner",diff --git a/posthog/hogql_queries/insights/funnels/__init__.py b/products/product_analytics/backend/hogql_queries/funnels/__init__.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/__init__.pyrename to products/product_analytics/backend/hogql_queries/funnels/__init__.pydiff --git a/posthog/hogql_queries/insights/funnels/base.py b/products/product_analytics/backend/hogql_queries/funnels/base.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/base.pyrename to products/product_analytics/backend/hogql_queries/funnels/base.pyindex 3bdb31995efe..bae3058fc3dd 100644--- a/posthog/hogql_queries/insights/funnels/base.py+++ b/products/product_analytics/backend/hogql_queries/funnels/base.py@@ -20,9 +20,6 @@ from posthog.hogql.constants import get_breakdown_limit_for_contextfrom posthog.hogql.parser import parse_expr, parse_selectfrom posthog.clickhouse.materialized_columns import ColumnName-from posthog.hogql_queries.insights.funnels.funnel_event_query import FunnelEventQuery-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.utils import funnel_window_interval_unit_to_sql, get_breakdown_cohort_namefrom posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_IDfrom posthog.hogql_queries.insights.utils.entities import is_equal, is_supersetfrom posthog.models.property.property import PropertyName@@ -31,6 +28,12 @@ from posthog.types import FunnelEntityNodefrom products.actions.backend.models.action import Actionfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels.funnel_event_query import FunnelEventQuery+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.utils import (+ funnel_window_interval_unit_to_sql,+ get_breakdown_cohort_name,+)JOIN_ALGOS = "auto"diff --git a/posthog/hogql_queries/insights/funnels/funnel.py b/products/product_analytics/backend/hogql_queries/funnels/funnel.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/funnel.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel.pyindex f102fda019ea..77269ebcda9f 100644--- a/posthog/hogql_queries/insights/funnels/funnel.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel.py@@ -8,13 +8,14 @@ from posthog.hogql import astfrom posthog.hogql.constants import DEFAULT_RETURNED_ROWS, HogQLQuerySettingsfrom posthog.hogql.parser import parse_expr, parse_select-from posthog.hogql_queries.insights.funnels.base import JOIN_ALGOS, FunnelBase-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.funnel_validation_rules import validate_max_funnel_steps-from posthog.hogql_queries.insights.funnels.utils import get_breakdown_cohort_namefrom posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_IDfrom posthog.utils import DATERANGE_MAP+from products.product_analytics.backend.hogql_queries.funnels.base import JOIN_ALGOS, FunnelBase+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.funnel_validation_rules import validate_max_funnel_steps+from products.product_analytics.backend.hogql_queries.funnels.utils import get_breakdown_cohort_name+@runtime_checkableclass FunnelProtocol(Protocol):diff --git a/posthog/hogql_queries/insights/funnels/funnel_aggregation_operations.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_aggregation_operations.pysimilarity index 96%rename from posthog/hogql_queries/insights/funnels/funnel_aggregation_operations.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_aggregation_operations.pyindex f78a3e927b0d..9bd44e4b9af6 100644--- a/posthog/hogql_queries/insights/funnels/funnel_aggregation_operations.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_aggregation_operations.py@@ -2,13 +2,14 @@ from typing import castfrom posthog.hogql import ast-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContextfrom posthog.hogql_queries.insights.utils.aggregations import (FirstTimeForUserDataWarehouseConfig,FirstTimeForUserEventsQueryAlternator,)from posthog.hogql_queries.utils.query_date_range import QueryDateRange+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+class FirstTimeForUserAggregationQuery:_context: FunnelQueryContextdiff --git a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.pyindex 7f556908a52a..d4bf15a32103 100644--- a/posthog/hogql_queries/insights/funnels/funnel_correlation_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.py@@ -31,9 +31,6 @@ from posthog.hogql.timings import HogQLTimingsfrom posthog.constants import AUTOCAPTURE_EVENTfrom posthog.dataclasses import frozen-from posthog.hogql_queries.insights.funnels import FunnelUDF-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.utils import funnel_window_interval_unit_to_sqlfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.models import Team@@ -45,6 +42,9 @@ from posthog.models.user import Userfrom posthog.queries.util import correct_result_for_samplingfrom products.actions.backend.models.action import Action+from products.product_analytics.backend.hogql_queries.funnels import FunnelUDF+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.utils import funnel_window_interval_unit_to_sqlclass EventOddsRatio(TypedDict):diff --git a/posthog/hogql_queries/insights/funnels/funnel_event_query.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/funnel_event_query.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.pyindex a69d80e9685e..840e7aab2191 100644--- a/posthog/hogql_queries/insights/funnels/funnel_event_query.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.py@@ -29,14 +29,6 @@ from posthog.hogql.property import action_to_expr, property_to_exprfrom posthog.clickhouse.materialized_columns import ColumnNamefrom posthog.clickhouse.query_tagging import tag_contains_user_hogql-from posthog.hogql_queries.insights.funnels.funnel_aggregation_operations import FirstTimeForUserAggregationQuery-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.utils import (- alias_columns_in_select,- data_warehouse_config_key,- entity_config_mismatch,- get_breakdown_expr,-)from posthog.hogql_queries.insights.utils.aggregations import FirstTimeForUserDataWarehouseConfigfrom posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_ID, strip_user_aliasesfrom posthog.hogql_queries.insights.utils.data_warehouse_schema_mixin import DataWarehouseSchemaMixin@@ -46,6 +38,16 @@ from posthog.models.property.property import PropertyNamefrom posthog.types import FunnelEntityNode, FunnelExclusionEntityNodefrom products.actions.backend.models.action import Action+from products.product_analytics.backend.hogql_queries.funnels.funnel_aggregation_operations import (+ FirstTimeForUserAggregationQuery,+)+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.utils import (+ alias_columns_in_select,+ data_warehouse_config_key,+ entity_config_mismatch,+ get_breakdown_expr,+)@dataclassdiff --git a/posthog/hogql_queries/insights/funnels/funnel_query_context.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_query_context.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/funnel_query_context.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_query_context.pydiff --git a/posthog/hogql_queries/insights/funnels/funnel_time_to_convert.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_time_to_convert.pysimilarity index 95%rename from posthog/hogql_queries/insights/funnels/funnel_time_to_convert.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_time_to_convert.pyindex 81d95e4f9e89..b4b8e3fd834d 100644--- a/posthog/hogql_queries/insights/funnels/funnel_time_to_convert.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_time_to_convert.py@@ -8,9 +8,10 @@ from posthog.hogql import astfrom posthog.hogql.parser import parse_selectfrom posthog.constants import FUNNEL_TO_STEP-from posthog.hogql_queries.insights.funnels import FunnelUDF-from posthog.hogql_queries.insights.funnels.base import FunnelBase-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext++from products.product_analytics.backend.hogql_queries.funnels import FunnelUDF+from products.product_analytics.backend.hogql_queries.funnels.base import FunnelBase+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContextclass FunnelTimeToConvertUDF(FunnelBase):diff --git a/posthog/hogql_queries/insights/funnels/funnel_time_to_convert_bins.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_time_to_convert_bins.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/funnel_time_to_convert_bins.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_time_to_convert_bins.pydiff --git a/posthog/hogql_queries/insights/funnels/funnel_trends.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_trends.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/funnel_trends.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_trends.pyindex 27e6c34cd535..2f0079b2a7ba 100644--- a/posthog/hogql_queries/insights/funnels/funnel_trends.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_trends.py@@ -10,10 +10,6 @@ from posthog.hogql import astfrom posthog.hogql.constants import HogQLQuerySettingsfrom posthog.hogql.parser import parse_expr, parse_select-from posthog.hogql_queries.insights.funnels.base import JOIN_ALGOS, FunnelBase-from posthog.hogql_queries.insights.funnels.funnel import FunnelUDF, FunnelUDFMixin-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.utils import get_breakdown_cohort_namefrom posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_IDfrom posthog.hogql_queries.insights.utils.utils import get_start_of_interval_hogql, get_start_of_interval_hogql_strfrom posthog.hogql_queries.utils.query_date_range import QueryDateRange@@ -22,6 +18,11 @@ from posthog.interval_specs import get_interval_funcfrom posthog.queries.util import correct_result_for_samplingfrom posthog.utils import DATERANGE_MAP, relative_date_parse+from products.product_analytics.backend.hogql_queries.funnels.base import JOIN_ALGOS, FunnelBase+from products.product_analytics.backend.hogql_queries.funnels.funnel import FunnelUDF, FunnelUDFMixin+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.utils import get_breakdown_cohort_name+class FunnelTrendsUDF(FunnelUDFMixin, FunnelBase):"""diff --git a/posthog/hogql_queries/insights/funnels/funnel_validation_rules.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/funnel_validation_rules.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnel_validation_rules.pydiff --git a/posthog/hogql_queries/insights/funnels/funnels_query_runner.py b/products/product_analytics/backend/hogql_queries/funnels/funnels_query_runner.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/funnels_query_runner.pyrename to products/product_analytics/backend/hogql_queries/funnels/funnels_query_runner.pyindex 80c1271910ee..b5f8c61c157e 100644--- a/posthog/hogql_queries/insights/funnels/funnels_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnels_query_runner.py@@ -33,21 +33,6 @@ from posthog.hogql.timings import HogQLTimingsfrom posthog.caching.insights_api import BASE_MINIMUM_INSIGHT_REFRESH_INTERVAL, REDUCED_MINIMUM_INSIGHT_REFRESH_INTERVALfrom posthog.clickhouse import query_taggingfrom posthog.clickhouse.query_tagging import QueryTags-from posthog.hogql_queries.insights.funnels import FunnelTrendsUDF, FunnelUDF-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.hogql_queries.insights.funnels.funnel_time_to_convert import FunnelTimeToConvertUDF-from posthog.hogql_queries.insights.funnels.funnel_time_to_convert_bins import (- ConversionTimeRange,- compute_shared_bin_boundaries,-)-from posthog.hogql_queries.insights.funnels.funnel_validation_rules import (- RequireAtLeastTwoFunnelSteps,- ValidateFunnelExclusions,- ValidateFunnelStepRange,- ValidateMaxFunnelSteps,- ValidateOptionalFunnelSteps,-)-from posthog.hogql_queries.insights.funnels.utils import get_breakdown_cohort_namefrom posthog.hogql_queries.insights.utils.breakdowns import (ALL_USERS_COHORT_ID,BREAKDOWN_BASELINE_DISPLAY,@@ -67,6 +52,21 @@ from posthog.models.filters.mixins.utils import cached_propertyfrom posthog.models.user import Userfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels import FunnelTrendsUDF, FunnelUDF+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+from products.product_analytics.backend.hogql_queries.funnels.funnel_time_to_convert import FunnelTimeToConvertUDF+from products.product_analytics.backend.hogql_queries.funnels.funnel_time_to_convert_bins import (+ ConversionTimeRange,+ compute_shared_bin_boundaries,+)+from products.product_analytics.backend.hogql_queries.funnels.funnel_validation_rules import (+ RequireAtLeastTwoFunnelSteps,+ ValidateFunnelExclusions,+ ValidateFunnelStepRange,+ ValidateMaxFunnelSteps,+ ValidateOptionalFunnelSteps,+)+from products.product_analytics.backend.hogql_queries.funnels.utils import get_breakdown_cohort_namelogger = structlog.get_logger(__name__)diff --git a/posthog/hogql_queries/insights/funnels/test/__init__.py b/products/product_analytics/backend/hogql_queries/funnels/test/__init__.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__init__.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/__init__.pydiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel.ambrsimilarity index 94%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel.ambrindex 097ca9194e8d..a746b2ae080c 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel.ambr@@ -467,7 +467,18 @@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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), or(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ 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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -528,7 +539,18 @@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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), or(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ 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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -586,7 +608,18 @@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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), or(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ 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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 1)@@ -644,7 +677,18 @@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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), or(ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'email'), ''), 'null'), '^"|"$', '')), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ 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('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 2)diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation.ambrsimilarity index 96%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation.ambrindex 84ce45af67f7..3d209c6f99b0 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation.ambr@@ -187,7 +187,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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ 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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -285,7 +295,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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ 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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -383,7 +403,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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ 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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -481,7 +511,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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ 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('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation_actors.ambrsimilarity index 95%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation_actors.ambrindex db86cc71386c..e54171078622 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr@@ -261,7 +261,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('$pageview', 'insight analyzed')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo+ 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('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation_actors.new_events_schema.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_correlation_actors.new_events_schema.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.ambrsimilarity index 91%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.ambrindex 0408196f04ac..5ae1790b7493 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr@@ -33,7 +33,7 @@NULL AS `$window_id`,if(1, 1, 0) AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2025-11-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2025-11-07 23:59:59.999999', 6, 'UTC'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -117,7 +117,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -201,7 +201,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -276,7 +276,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -335,7 +335,7 @@NULL AS `$window_id`,if(1, 1, 0) AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2025-11-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2025-11-07 23:59:59.999999', 6, 'UTC'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -395,7 +395,7 @@NULL AS `$window_id`,if(1, 1, 0) AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2025-11-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2025-11-07 23:59:59.999999', 6, 'UTC'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -455,7 +455,7 @@NULL AS `$window_id`,if(isNotNull(e.id_with_nulls), 1, 0) AS step_0,if(isNotNull(e.id_with_nulls), 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2025-11-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2025-11-07 23:59:59.999999', 6, 'UTC'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -530,7 +530,7 @@if(1, 1, 0) AS step_0,0 AS step_1,0 AS step_2- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_salesforce_lead/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `created_date` DateTime64(3, \'UTC\'), `converted_opportunity_id` Nullable(String)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_salesforce_lead/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `created_date` DateTime64(3, \'UTC\'), `converted_opportunity_id` Nullable(String)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2024-05-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2024-06-30 23:59:59.999999', 6, 'UTC'))), equals(step_0, 1))UNION ALL SELECT toTimeZone(e.created_date, 'UTC') AS timestamp,toString(e.id) AS aggregation_target,@@ -540,7 +540,7 @@0 AS step_0,if(1, 1, 0) AS step_1,0 AS step_2- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_salesforce_opportunity/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `close_date` Nullable(Date), `created_date` DateTime64(3, \'UTC\')') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_salesforce_opportunity/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `close_date` Nullable(Date), `created_date` DateTime64(3, \'UTC\')') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('2024-05-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('2024-06-30 23:59:59.999999', 6, 'UTC'))), equals(step_1, 1))UNION ALL SELECT e.close_date AS timestamp,toString(e.id) AS aggregation_target,@@ -550,7 +550,7 @@0 AS step_0,0 AS step_1,if(1, 1, 0) AS step_2- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_salesforce_opportunity/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `close_date` Nullable(Date), `created_date` DateTime64(3, \'UTC\')') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_salesforce_opportunity/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `close_date` Nullable(Date), `created_date` DateTime64(3, \'UTC\')') AS eWHERE and(and(ifNull(greaterOrEquals(timestamp, toDateTime64('2024-05-01 00:00:00.000000', 6, 'UTC')), 0), ifNull(lessOrEquals(timestamp, toDateTime64('2024-06-30 23:59:59.999999', 6, 'UTC')), 0)), equals(step_2, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambrsimilarity index 93%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambrindex c815aeae725e..4070343d6fd6 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambr+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_data_warehouse.new_events_schema.ambr@@ -57,7 +57,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -141,7 +141,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -216,7 +216,7 @@NULL AS `$window_id`,0 AS step_0,if(1, 1, 0) AS step_1- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e+ FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS eWHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))diff --git a/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_insight_actors.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_insight_actors.ambrnew file mode 100644index 000000000000..8f08c51e6dbb--- /dev/null+++ b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_insight_actors.ambr@@ -0,0 +1,65 @@+# serializer version: 1+# name: TestFunnelInsightActors.test_insight_persons_funnels_query+ '''+ SELECT name AS name+ FROM+ (SELECT persons.properties___name AS name+ FROM+ (SELECT aggregation_target AS actor_id+ 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), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, 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.5 AS steps_bitfield,+ aggregation_target AS aggregation_target+ FROM+ (SELECT toTimeZone(e.timestamp, 'US/Pacific') 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, '$pageview'), 1, 0) AS step_0,+ if(equals(e.event, '$pageview'), 1, 0) AS step_1+ FROM events AS e+ 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)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('$pageview'))), or(equals(step_0, 1), equals(step_1, 1))))+ GROUP BY aggregation_target+ HAVING ifNull(greaterOrEquals(step_reached, 0), 0))+ WHERE bitTest(steps_bitfield, 1)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source+ INNER JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name+ 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, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto')+ LIMIT 100 SETTINGS readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_persons.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_persons.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_persons.new_events_schema.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_persons.new_events_schema.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict.new_events_schema.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict.new_events_schema.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict_persons.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict_persons.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict_persons.new_events_schema.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_strict_persons.new_events_schema.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_time_to_convert.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_time_to_convert.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.new_events_schema.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_time_to_convert.new_events_schema.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.new_events_schema.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_time_to_convert.new_events_schema.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_trends.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_trends.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_trends_actors.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_trends_actors.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambr b/products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_unordered.ambrsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambrrename to products/product_analytics/backend/hogql_queries/funnels/test/__snapshots__/test_funnel_unordered.ambrdiff --git a/posthog/hogql_queries/insights/funnels/test/breakdown_cases.py b/products/product_analytics/backend/hogql_queries/funnels/test/breakdown_cases.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/breakdown_cases.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/breakdown_cases.pyindex 5f7cc9948407..8ed7dea2408a 100644--- a/posthog/hogql_queries/insights/funnels/test/breakdown_cases.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/breakdown_cases.py@@ -32,8 +32,6 @@ from posthog.schema import ()from posthog.constants import FunnelOrderType-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_ID, NOT_IN_COHORT_IDfrom posthog.models.group.util import create_groupfrom posthog.models.instance_setting import override_instance_config@@ -41,9 +39,11 @@ from posthog.test.test_journeys import journeys_forfrom posthog.test.test_utils import create_group_type_mapping_without_created_atfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actorsfrom products.warehouse_sources.backend.facade.testing import create_data_warehouse_table_from_csv-TEST_BUCKET = "test_storage_bucket-posthog.hogql_queries.insights.funnels.breakdown_cases"+TEST_BUCKET = "test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.breakdown_cases"@dataclass(frozen=True)diff --git a/posthog/hogql_queries/insights/funnels/test/conversion_time_cases.py b/products/product_analytics/backend/hogql_queries/funnels/test/conversion_time_cases.pysimilarity index 97%rename from posthog/hogql_queries/insights/funnels/test/conversion_time_cases.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/conversion_time_cases.pyindex 691b3323f3b2..58151dc8988c 100644--- a/posthog/hogql_queries/insights/funnels/test/conversion_time_cases.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/conversion_time_cases.py@@ -6,10 +6,11 @@ from posthog.test.base import APIBaseTestfrom posthog.schema import DateRange, EventsNode, FunnelConversionWindowTimeUnit, FunnelsFilter, FunnelsQueryfrom posthog.constants import FunnelOrderType-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actors+def funnel_conversion_time_test_factory(funnel_order_type: FunnelOrderType):class TestFunnelConversionTime(APIBaseTest):diff --git a/posthog/hogql_queries/insights/funnels/test/cross_match_table_one_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/cross_match_table_one_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/cross_match_table_one_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/cross_match_table_one_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/cross_match_table_two_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/cross_match_table_two_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/cross_match_table_two_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/cross_match_table_two_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/funnels_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/funnels_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/funnels_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/funnels_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/salesforce_lead_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/salesforce_lead_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/salesforce_lead_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/salesforce_lead_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/salesforce_opportunity_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/salesforce_opportunity_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/salesforce_opportunity_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/salesforce_opportunity_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/salesforce_opportunity_repeated_created_date_data.csv b/products/product_analytics/backend/hogql_queries/funnels/test/salesforce_opportunity_repeated_created_date_data.csvsimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/salesforce_opportunity_repeated_created_date_data.csvrename to products/product_analytics/backend/hogql_queries/funnels/test/salesforce_opportunity_repeated_created_date_data.csvdiff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel.pyindex 10ab3515a90a..f5d63cd6f0ea 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel.py@@ -55,13 +55,6 @@ from posthog.api.instance_settings import get_instance_settingfrom posthog.clickhouse.client.execute import sync_executefrom posthog.constants import FunnelOrderType, FunnelVizTypefrom posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.breakdown_cases import (- assert_funnel_results_equal,- funnel_breakdown_group_test_factory,- funnel_breakdown_test_factory,-)-from posthog.hogql_queries.insights.funnels.test.conversion_time_cases import funnel_conversion_time_test_factoryfrom posthog.models import Elementfrom posthog.models.event.sql import EVENTS_DATA_TABLE, EVENTS_JSON_DATA_TABLEfrom posthog.models.group.util import create_group@@ -72,6 +65,15 @@ from posthog.test.test_utils import create_group_type_mapping_without_created_atfrom products.actions.backend.models.action import Actionfrom products.cohorts.backend.models.cohort import Cohortfrom products.event_definitions.backend.models.property_definition import PropertyDefinition+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.breakdown_cases import (+ assert_funnel_results_equal,+ funnel_breakdown_group_test_factory,+ funnel_breakdown_test_factory,+)+from products.product_analytics.backend.hogql_queries.funnels.test.conversion_time_cases import (+ funnel_conversion_time_test_factory,+)class TestFunnelBreakdownUDF(diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_actors_query_options.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_actors_query_options.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_actors_query_options.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_actors_query_options.pyindex f98ecc9bb94d..61b81d5ed24a 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_actors_query_options.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_actors_query_options.py@@ -18,7 +18,6 @@ from posthog.schema import (InsightActorsQueryOptions,)-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.insight_actors_query_options_runner import InsightActorsQueryOptionsRunnerfrom posthog.hogql_queries.insights.utils.breakdowns import (ALL_USERS_COHORT_ID,@@ -29,6 +28,7 @@ from posthog.hogql_queries.insights.utils.breakdowns import (from posthog.test.test_journeys import journeys_forfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner# Compare runs its two period sub-queries in threads outside unit tests; force the serial path sodiff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_aggregation_operations.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_aggregation_operations.pyindex ca9d23c46c55..8046051dfb97 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_aggregation_operations.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_aggregation_operations.py@@ -10,10 +10,13 @@ from posthog.schema import DateRange, EventsNode, FunnelsFilter, FunnelsQueryfrom posthog.hogql import astfrom posthog.hogql.parser import parse_expr-from posthog.hogql_queries.insights.funnels.funnel_aggregation_operations import FirstTimeForUserAggregationQuery-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContextfrom posthog.hogql_queries.insights.utils.aggregations import FirstTimeForUserDataWarehouseConfig+from products.product_analytics.backend.hogql_queries.funnels.funnel_aggregation_operations import (+ FirstTimeForUserAggregationQuery,+)+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContext+def _dwh_config(timestamp_expr: ast.Expr | None = None) -> FirstTimeForUserDataWarehouseConfig:return FirstTimeForUserDataWarehouseConfig(diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_breakdowns_by_current_url.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_breakdowns_by_current_url.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_breakdowns_by_current_url.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_breakdowns_by_current_url.pyindex 26053202f0ee..35bf2072a214 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_breakdowns_by_current_url.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_breakdowns_by_current_url.py@@ -4,9 +4,10 @@ from posthog.test.base import APIBaseTest, ClickhouseTestMixin, snapshot_clickhofrom posthog.schema import BreakdownFilter, DateRange, EventsNode, FunnelsFilter, FunnelsQuery-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+class TestFunnelBreakdownsByCurrentURL(ClickhouseTestMixin, APIBaseTest):def setUp(self):diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation.pyindex e39c3aba2941..3d56adbd0b46 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation.py@@ -33,18 +33,19 @@ from posthog.schema import (PropertyOperator,)-from posthog.hogql_queries.insights.funnels.funnel_correlation_query_runner import (- EventContingencyTable,- EventStats,- FunnelCorrelationQueryRunner,-)-from posthog.hogql_queries.insights.funnels.test.test_funnel_correlation_actors import get_actorsfrom posthog.models.element import Elementfrom posthog.models.group.util import create_groupfrom posthog.models.instance_setting import override_instance_configfrom posthog.test.test_journeys import journeys_forfrom posthog.test.test_utils import create_group_type_mapping_without_created_at+from products.product_analytics.backend.hogql_queries.funnels.funnel_correlation_query_runner import (+ EventContingencyTable,+ EventStats,+ FunnelCorrelationQueryRunner,+)+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_correlation_actors import get_actors+class TestClickhouseFunnelCorrelation(ClickhouseTestMixin, APIBaseTest):maxDiff = Nonediff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_correlation_actors.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_correlation_actors.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.pydiff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_data_warehouse.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_data_warehouse.pysimilarity index 95%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_data_warehouse.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_data_warehouse.pyindex 3ae962eb47be..a24e7534fca5 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_data_warehouse.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_data_warehouse.py@@ -16,6 +16,8 @@ from parameterized import parameterizedfrom posthog.schema import (ActorsQuery,+ BreakdownFilter,+ BreakdownType,DataWarehousePersonPropertyFilter,DataWarehousePropertyFilter,DateRange,@@ -25,20 +27,22 @@ from posthog.schema import (FunnelsDataWarehouseNode,FunnelsFilter,FunnelsQuery,+ HogQLQueryModifiers,+ PersonsOnEventsMode,PropertyOperator,StepOrderValue,)from posthog.errors import ExposedCHQueryErrorfrom posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.test.test_journeys import journeys_forfrom posthog.types import AnyPropertyFilterfrom products.data_tools.backend.models.join import DataWarehouseJoin+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunnerfrom products.warehouse_sources.backend.facade.testing import create_data_warehouse_table_from_csv-TEST_BUCKET = "test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse"+TEST_BUCKET = "test_storage_bucket-products.product_analytics.backend.hogql_queries.funnels.funnel_data_warehouse"class TestFunnelDataWarehouse(ClickhouseTestMixin, BaseTest):@@ -549,6 +553,35 @@ class TestFunnelDataWarehouse(ClickhouseTestMixin, BaseTest):assert results[0]["count"] == 1assert results[1]["count"] == 1+ def test_funnels_breakdown_on_warehouse_person_property_in_joined_poe_mode(self):+ # A warehouse person property in joined PoE mode resolves through two chained lazy joins.+ # Getting that resolution wrong raises rather than returning a wrong number, so running the+ # query is the assertion.+ table_name = self.setup_data_warehouse()++ DataWarehouseJoin.objects.create(+ team=self.team,+ source_table_name="persons",+ source_table_key="properties.email",+ joining_table_name=table_name,+ joining_table_key="user_id",+ field_name=table_name,+ )++ funnels_query = FunnelsQuery(+ series=[EventsNode(event="$pageview"), EventsNode(event="$checkout")],+ breakdownFilter=BreakdownFilter(+ breakdown_type=BreakdownType.DATA_WAREHOUSE_PERSON_PROPERTY,+ breakdown=f"{table_name}.event_name",+ ),+ )++ FunnelsQueryRunner(+ query=funnels_query,+ team=self.team,+ modifiers=HogQLQueryModifiers(personsOnEventsMode=PersonsOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_JOINED),+ ).calculate()+@snapshot_clickhouse_queriesdef test_funnels_salesforce_lead_to_opportunity(self):lead_table_name, opportunity_table_name = self.setup_salesforce_data_warehouse()diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_event_query.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_event_query.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_event_query.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_event_query.pyindex 62b313927b79..55c2dcdc6bcd 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_event_query.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_event_query.py@@ -24,10 +24,9 @@ from posthog.schema import (from posthog.hogql import ast-from posthog.hogql_queries.insights.funnels.funnel_event_query import FunnelEventQuery-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from products.actions.backend.models.action import Action+from products.product_analytics.backend.hogql_queries.funnels.funnel_event_query import FunnelEventQuery+from products.product_analytics.backend.hogql_queries.funnels.funnel_query_context import FunnelQueryContextfrom products.warehouse_sources.backend.facade.models import DataWarehouseCredential, DataWarehouseTablediff --git a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_insight_actors.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_insight_actors.pynew file mode 100644index 000000000000..bd50f007cd86--- /dev/null+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_insight_actors.py@@ -0,0 +1,136 @@+from typing import Any, Optional++from freezegun import freeze_time+from posthog.test.base import (+ APIBaseTest,+ ClickhouseTestMixin,+ _create_event,+ _create_person,+ snapshot_clickhouse_queries,+)++from posthog.schema import HogQLQueryModifiers++from posthog.hogql.query import execute_hogql_query++from posthog.models.group.util import create_group+from posthog.test.test_utils import create_group_type_mapping_without_created_at+++class TestFunnelInsightActors(ClickhouseTestMixin, APIBaseTest):+ maxDiff = None++ def _create_test_groups(self):+ create_group_type_mapping_without_created_at(+ team=self.team, project_id=self.team.project_id, group_type="organization", group_type_index=0+ )+ create_group(+ team_id=self.team.pk,+ group_type_index=0,+ group_key="org:1",+ properties={"name": "org1"},+ )+ create_group(+ team_id=self.team.pk,+ group_type_index=0,+ group_key="org:2",+ properties={"name": "org2"},+ )++ def _create_events(self, data, event="$pageview"):+ for id, timestamps in data:+ with freeze_time(timestamps[0]):+ _create_person(+ team_id=self.team.pk,+ distinct_ids=[id],+ properties={+ "name": id,+ **({"email": "[email protected]"} if id == "p1" else {}),+ },+ )+ for timestamp in timestamps:+ _create_event(+ team=self.team, event=event, distinct_id=id, timestamp=timestamp, properties={"$group_0": "org:1"}+ )++ def _create_test_events(self):+ self._create_events(+ data=[+ (+ "p1",+ [+ "2020-01-11T12:00:00Z",+ "2020-01-12T12:00:00Z",+ "2020-01-13T12:00:00Z",+ "2020-01-15T12:00:00Z",+ "2020-01-17T12:00:00Z",+ "2020-01-19T12:00:00Z",+ ],+ ),+ ("p2", ["2020-01-09T12:00:00Z", "2020-01-12T12:00:00Z"]),+ ("p3", ["2020-01-12T12:00:00Z"]),+ ("p4", ["2020-01-15T12:00:00Z"]),+ ]+ )++ def select(self, query: str, placeholders: Optional[dict[str, Any]] = None, modifiers: Optional[dict] = None):+ if placeholders is None:+ placeholders = {}+ return execute_hogql_query(+ query=query,+ team=self.team,+ placeholders=placeholders,+ modifiers=HogQLQueryModifiers(**modifiers) if modifiers else None,+ )++ @snapshot_clickhouse_queries+ def test_insight_persons_funnels_query(self):+ self._create_test_events()+ self.team.timezone = "US/Pacific"+ self.team.save()++ response = self.select(+ """+ select * from (+ <ActorsQuery select={['properties.name']}>+ <FunnelsActorsQuery funnelStep={2}>+ <FunnelsQuery+ dateRange={<DateRange date_from='2020-01-01' date_to='2020-01-19' />}+ series={[<EventsNode event='$pageview' />, <EventsNode event='$pageview' />]}+ />+ </FunnelsActorsQuery>+ </ActorsQuery>+ )+ """+ )++ self.assertEqual([("p1",), ("p2",)], response.results)++ def test_insight_groups_funnels_query(self):+ self._create_test_groups()+ self._create_test_events()+ self.team.timezone = "US/Pacific"+ self.team.save()++ response = self.select(+ """+ select * from (+ <ActorsQuery select={['properties.name']}>+ <FunnelsActorsQuery funnelStep={2}>+ <FunnelsQuery+ aggregation_group_type_index={0}+ dateRange={<DateRange date_from='2020-01-01' date_to='2020-01-19' />}+ series={[<EventsNode event='$pageview' />, <EventsNode event='$pageview' />]}+ />+ </FunnelsActorsQuery>+ </ActorsQuery>+ )+ """+ )++ self.assertEqual(+ [+ ("org1",),+ ],+ response.results,+ )diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_persons.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_persons.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_persons.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_persons.pyindex afa7e3fe9c2d..75ccb7b2d8e7 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_persons.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_persons.py@@ -33,13 +33,13 @@ from posthog.schema import ()from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.models.event.util import bulk_create_eventsfrom posthog.models.team.team import Teamfrom posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summaryfrom posthog.test.test_journeys import journeys_forfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunnerFORMAT_TIME = "%Y-%m-%d 00:00:00"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_strict.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict.pyindex 21eb9f6bee49..5356edf46547 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict.py@@ -18,16 +18,19 @@ from posthog.hogql.parser import parse_exprfrom posthog.hogql.query import execute_hogql_queryfrom posthog.constants import FunnelOrderType-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.breakdown_cases import (+from posthog.models.instance_setting import override_instance_config+from posthog.test.test_journeys import journeys_for++from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.breakdown_cases import (assert_funnel_results_equal,funnel_breakdown_group_test_factory,funnel_breakdown_test_factory,)-from posthog.hogql_queries.insights.funnels.test.conversion_time_cases import funnel_conversion_time_test_factory-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actors-from posthog.models.instance_setting import override_instance_config-from posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.test.conversion_time_cases import (+ funnel_conversion_time_test_factory,+)+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actorsFORMAT_TIME = "%Y-%m-%d 00:00:00"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict_persons.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict_persons.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_strict_persons.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict_persons.pyindex 132572790930..68f1fd56cec3 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_strict_persons.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_strict_persons.py@@ -16,12 +16,13 @@ from django.utils import timezonefrom posthog.schema import FunnelsQueryfrom posthog.constants import INSIGHT_FUNNELS-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.hogql_queries.legacy_compatibility.filter_to_query import filter_to_queryfrom posthog.models import Teamfrom posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summaryfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actors+FORMAT_TIME = "%Y-%m-%d 00:00:00"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert.pyindex a447abd5c239..a90f2fa971d0 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert.py@@ -24,9 +24,10 @@ from posthog.schema import (StepOrderValue,)-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+FORMAT_TIME = "%Y-%m-%d %H:%M:%S"FORMAT_TIME_DAY_END = "%Y-%m-%d 23:59:59"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert_bins.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert_bins.pysimilarity index 95%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert_bins.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert_bins.pyindex 57889cfeff68..caa0df06e008 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_time_to_convert_bins.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_time_to_convert_bins.py@@ -1,6 +1,6 @@from django.test import SimpleTestCase-from posthog.hogql_queries.insights.funnels.funnel_time_to_convert_bins import (+from products.product_analytics.backend.hogql_queries.funnels.funnel_time_to_convert_bins import (ConversionTimeRange,compute_shared_bin_boundaries,)diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_trends.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends.pyindex df40662299a7..98b6fc29a582 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends.py@@ -34,11 +34,11 @@ from posthog.schema import (from posthog.hogql import astfrom posthog.constants import FunnelOrderType-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.test.test_journeys import journeys_forfrom products.cohorts.backend.models.cohort import Cohort+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actorsFORMAT_TIME = "%Y-%m-%d %H:%M:%S"FORMAT_TIME_DAY_END = "%Y-%m-%d 23:59:59"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_actors.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends_actors.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_trends_actors.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends_actors.pyindex c7ce6442057b..1e86e3fa9d25 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_trends_actors.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_trends_actors.py@@ -13,10 +13,11 @@ from posthog.schema import (IntervalType,)-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summaryfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actors+funnels_query = FunnelsQuery(series=[EventsNode(event="step one"),diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_unordered.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered.pysimilarity index 99%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_unordered.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered.pyindex 6d3614dc32dc..8f0bff2bb11e 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_unordered.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered.py@@ -30,19 +30,21 @@ from posthog.schema import ()from posthog.constants import FunnelOrderType-from posthog.hogql_queries.insights.funnels import FunnelUDF-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.test.breakdown_cases import (+from posthog.test.test_journeys import journeys_for++from products.event_definitions.backend.models.property_definition import PropertyDefinition+from products.product_analytics.backend.hogql_queries.funnels import FunnelUDF+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.test.breakdown_cases import (FunnelStepResult,assert_funnel_results_equal,funnel_breakdown_group_test_factory,funnel_breakdown_test_factory,)-from posthog.hogql_queries.insights.funnels.test.conversion_time_cases import funnel_conversion_time_test_factory-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actors-from posthog.test.test_journeys import journeys_for--from products.event_definitions.backend.models.property_definition import PropertyDefinition+from products.product_analytics.backend.hogql_queries.funnels.test.conversion_time_cases import (+ funnel_conversion_time_test_factory,+)+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actorsdef unordered_funnels_query(diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_unordered_persons.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered_persons.pysimilarity index 98%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_unordered_persons.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered_persons.pyindex 601c749d8c71..c5e3b1bb2d24 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_unordered_persons.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_unordered_persons.py@@ -6,11 +6,12 @@ from posthog.test.base import APIBaseTest, ClickhouseTestMixinfrom posthog.schema import FunnelsQueryfrom posthog.constants import INSIGHT_FUNNELS-from posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actorsfrom posthog.hogql_queries.legacy_compatibility.filter_to_query import filter_to_queryfrom posthog.models import Teamfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.test.test_funnel_persons import get_actors+FORMAT_TIME = "%Y-%m-%d 00:00:00"diff --git a/posthog/hogql_queries/insights/funnels/test/test_funnel_validation_rules.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.pysimilarity index 96%rename from posthog/hogql_queries/insights/funnels/test/test_funnel_validation_rules.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.pyindex 41e7914c2cc0..446b3a048a34 100644--- a/posthog/hogql_queries/insights/funnels/test/test_funnel_validation_rules.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_validation_rules.py@@ -16,16 +16,19 @@ from posthog.schema import (StepOrderValue,)-from posthog.hogql_queries.insights.funnels.funnel_correlation_query_runner import FunnelCorrelationQueryRunner-from posthog.hogql_queries.insights.funnels.funnel_validation_rules import (+from posthog.hogql_queries.validation.validation import QueryValidationContext++from products.product_analytics.backend.hogql_queries.funnels.funnel_correlation_query_runner import (+ FunnelCorrelationQueryRunner,+)+from products.product_analytics.backend.hogql_queries.funnels.funnel_validation_rules import (MAX_FUNNEL_STEPS,RequireAtLeastTwoFunnelSteps,ValidateFunnelExclusions,ValidateFunnelStepRange,ValidateOptionalFunnelSteps,)-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.validation.validation import QueryValidationContext+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunnerclass TestFunnelValidationRules(BaseTest):diff --git a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnels_query_runner.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnels_query_runner.pynew file mode 100644index 000000000000..89428409b167--- /dev/null+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnels_query_runner.py@@ -0,0 +1,134 @@+from datetime import UTC, datetime++from posthog.test.base import BaseTest++from parameterized import parameterized++from posthog.schema import CachedFunnelsQueryResponse, DashboardFilter, EventsNode, FunnelsQuery, IntervalType++from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+++class TestFunnelsDashboardFilters(BaseTest):+ def _runner(self) -> FunnelsQueryRunner:+ return FunnelsQueryRunner(+ query=FunnelsQuery(series=[EventsNode(event="$pageview")], interval=IntervalType.DAY),+ team=self.team,+ )++ @parameterized.expand(+ [+ ("override_written_onto_query", IntervalType.WEEK, IntervalType.WEEK),+ ("absent_override_leaves_query_untouched", None, IntervalType.DAY),+ ]+ )+ def test_dashboard_interval_override(+ self, _name: str, dashboard_interval: IntervalType | None, expected: IntervalType+ ) -> None:+ runner = self._runner()++ runner.apply_dashboard_filters(DashboardFilter(interval=dashboard_interval))++ assert runner.query.interval == expected++ @parameterized.expand(+ [+ ("override_forces_on", None, True, True),+ ("override_forces_off", True, False, False),+ ("absent_override_leaves_query_untouched", True, None, True),+ ]+ )+ def test_dashboard_test_accounts_override(+ self, _name: str, initial: bool | None, dashboard_filter: bool | None, expected: bool+ ) -> None:+ runner = self._runner()+ if initial is not None:+ runner.query.filterTestAccounts = initial++ runner.apply_dashboard_filters(DashboardFilter(filterTestAccounts=dashboard_filter))++ assert runner.query.filterTestAccounts is expected+++class TestFunnelsSeriesCustomNames(BaseTest):+ @parameterized.expand(+ [+ (+ "patches_funnel_steps_without_breakdown",+ [+ {"order": 0, "custom_name": "Old Step 1", "count": 100},+ {"order": 1, "custom_name": "Old Step 2", "count": 50},+ ],+ [+ {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},+ {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},+ ],+ True,+ ),+ (+ "patches_funnel_steps_with_breakdown",+ [+ [+ {"order": 0, "custom_name": None, "count": 100, "breakdown": "Chrome"},+ {"order": 1, "custom_name": None, "count": 50, "breakdown": "Chrome"},+ ],+ [+ {"order": 0, "custom_name": None, "count": 80, "breakdown": "Firefox"},+ {"order": 1, "custom_name": None, "count": 40, "breakdown": "Firefox"},+ ],+ ],+ [+ [+ {"order": 0, "custom_name": "Step 1 Renamed", "count": 100, "breakdown": "Chrome"},+ {"order": 1, "custom_name": "Step 2 Renamed", "count": 50, "breakdown": "Chrome"},+ ],+ [+ {"order": 0, "custom_name": "Step 1 Renamed", "count": 80, "breakdown": "Firefox"},+ {"order": 1, "custom_name": "Step 2 Renamed", "count": 40, "breakdown": "Firefox"},+ ],+ ],+ True,+ ),+ (+ "not_modified_when_names_match",+ [+ {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},+ {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},+ ],+ [+ {"order": 0, "custom_name": "Step 1 Renamed", "count": 100},+ {"order": 1, "custom_name": "Step 2 Renamed", "count": 50},+ ],+ False,+ ),+ ]+ )+ def test_apply_funnels_custom_names(+ self,+ _name: str,+ cached_results: list,+ expected_results: list,+ expect_modified: bool,+ ):+ query = FunnelsQuery(+ series=[+ EventsNode(event="step1", custom_name="Step 1 Renamed"),+ EventsNode(event="step2", custom_name="Step 2 Renamed"),+ ]+ )++ runner = FunnelsQueryRunner(query=query, team=self.team)++ cached_response = CachedFunnelsQueryResponse(+ results=cached_results,+ is_cached=True,+ last_refresh=datetime.now(UTC),+ next_allowed_client_refresh=datetime.now(UTC),+ cache_key="test_key",+ timezone="UTC",+ )++ patched_response, was_modified = runner.apply_series_custom_names(cached_response)++ self.assertEqual(patched_response.results, expected_results)+ self.assertEqual(was_modified, expect_modified)diff --git a/posthog/hogql_queries/insights/funnels/test/test_utils.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_utils.pysimilarity index 96%rename from posthog/hogql_queries/insights/funnels/test/test_utils.pyrename to products/product_analytics/backend/hogql_queries/funnels/test/test_utils.pyindex d0d52609b3ac..37b5d858175c 100644--- a/posthog/hogql_queries/insights/funnels/test/test_utils.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_utils.py@@ -8,7 +8,10 @@ from posthog.hogql import astfrom posthog.hogql.parser import parse_selectfrom posthog.hogql.visitor import clone_expr-from posthog.hogql_queries.insights.funnels.utils import alias_columns_in_select, entity_config_mismatch+from products.product_analytics.backend.hogql_queries.funnels.utils import (+ alias_columns_in_select,+ entity_config_mismatch,+)def _funnels_data_warehouse_node(**overrides) -> FunnelsDataWarehouseNode:diff --git a/posthog/hogql_queries/insights/funnels/utils.py b/products/product_analytics/backend/hogql_queries/funnels/utils.pysimilarity index 100%rename from posthog/hogql_queries/insights/funnels/utils.pyrename to products/product_analytics/backend/hogql_queries/funnels/utils.pydiff --git a/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py b/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.pyindex 4812bdeb35f7..b59b1c2cde02 100644--- a/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py@@ -31,8 +31,6 @@ from posthog.hogql.timings import HogQLTimingsfrom posthog.caching.insights_api import BASE_MINIMUM_INSIGHT_REFRESH_INTERVAL, REDUCED_MINIMUM_INSIGHT_REFRESH_INTERVALfrom posthog.clickhouse.query_tagging import tag_contains_user_hogqlfrom posthog.constants import HOGQL, PAGEVIEW_EVENT, SCREEN_EVENT-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunner-from posthog.hogql_queries.insights.funnels.utils import funnel_window_interval_unit_to_sqlfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.models import Team@@ -40,6 +38,9 @@ from posthog.models.filters.mixins.utils import cached_propertyfrom posthog.models.user import Userfrom posthog.queries.util import correct_result_for_sampling+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunner+from products.product_analytics.backend.hogql_queries.funnels.utils import funnel_window_interval_unit_to_sql+EVENT_IN_SESSION_LIMIT_DEFAULT = 5SESSION_TIME_THRESHOLD_DEFAULT_SECONDS = 30 * 60 # 30 minutesEDGE_LIMIT_DEFAULT = 50diff --git a/products/product_analytics/backend/hogql_queries/paths_v2/paths_v2_query_runner.py b/products/product_analytics/backend/hogql_queries/paths_v2/paths_v2_query_runner.pyindex 19af30e3ce8d..eed91a67fa2e 100644--- a/products/product_analytics/backend/hogql_queries/paths_v2/paths_v2_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/paths_v2/paths_v2_query_runner.py@@ -30,11 +30,14 @@ from posthog.hogql.parser import parse_expr, parse_selectfrom posthog.hogql.property import property_to_exprfrom posthog.hogql.query import execute_hogql_query-from posthog.hogql_queries.insights.funnels.utils import CONVERSION_WINDOW_INTERVAL_BOUNDS, conversion_window_to_secondsfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.hogql_queries.validation.validation import QueryValidationContext, QueryValidationRule+from products.product_analytics.backend.hogql_queries.funnels.utils import (+ CONVERSION_WINDOW_INTERVAL_BOUNDS,+ conversion_window_to_seconds,+)from products.product_analytics.backend.hogql_queries.paths_v2.path_item import (DEFAULT_COLLAPSE_REPEATS,DEFAULT_CONVERSION_WINDOW_INTERVAL,diff --git a/products/product_analytics/backend/hogql_queries/paths_v2/test/test_funnel_converter.py b/products/product_analytics/backend/hogql_queries/paths_v2/test/test_funnel_converter.pyindex 08bf39c16b57..e84dc7eda536 100644--- a/products/product_analytics/backend/hogql_queries/paths_v2/test/test_funnel_converter.py+++ b/products/product_analytics/backend/hogql_queries/paths_v2/test/test_funnel_converter.py@@ -24,9 +24,9 @@ from posthog.schema import (StepOrderValue,)-from posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.test.test_journeys import journeys_for+from products.product_analytics.backend.hogql_queries.funnels.funnels_query_runner import FunnelsQueryRunnerfrom products.product_analytics.backend.hogql_queries.paths_v2.funnel_converter import (anchored_segment_to_funnels_query,edge_to_funnels_query,diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.pyindex 53f42bc4bfd7..8d6843f0655d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py@@ -38,27 +38,14 @@ from temporalio.service import RPCError, RPCStatusCodefrom temporalio.testing import WorkflowEnvironmentfrom temporalio.worker import UnsandboxedWorkflowRunner, Worker-from posthog.schema import (- BreakdownFilter,- BreakdownType,- EventsNode,- FunnelsQuery,- HogQLQueryModifiers,- PersonsOnEventsMode,-)--from posthog.hogql.modifiers import create_default_modifiers_for_teamfrom posthog.hogql.query import execute_hogql_query-from posthog.hogql_queries.insights.funnels.funnel import FunnelUDF-from posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContextfrom posthog.models.event.util import format_clickhouse_timestampfrom posthog.models.team.team import Teamfrom posthog.temporal.common.shutdown import ShutdownMonitor, WorkerShuttingDownErrorfrom posthog.temporal.utils import ExternalDataWorkflowInputsfrom products.cdp.backend.models.hog_functions.hog_function import HogFunction-from products.data_tools.backend.models.join import DataWarehouseJoinfrom products.data_warehouse.backend.facade.api import WebhookConsumerConfig, WebhookS3Sinkfrom products.managed_warehouse.backend.facade.temporal import (ACTIVITIES as DUCKLAKE_ACTIVITIES,@@ -1062,50 +1049,6 @@ async def test_delta_wrapper_files(team, stripe_balance_transaction, mock_stripeassert len(s3_objects["Contents"]) != 0[email protected]_db(transaction=True)-async def test_funnels_lazy_joins_ordering(team, stripe_customer, mock_stripe_client):- # Tests that funnels work in PERSON_ID_OVERRIDE_PROPERTIES_JOINED PoE mode when using extended person properties- await _run(- team=team,- schema_name="Customer",- table_name="stripe_customer",- source_type="Stripe",- job_inputs={- "auth_method": {"selection": "api_key", "stripe_secret_key": "test-key"},- "stripe_account_id": "acct_id",- },- mock_data_response=stripe_customer["data"],- )-- await sync_to_async(DataWarehouseJoin.objects.create)(- team=team,- source_table_name="persons",- source_table_key="properties.email",- joining_table_name="stripe_customer",- joining_table_key="email",- field_name="stripe_customer",- )-- query = FunnelsQuery(- series=[EventsNode(), EventsNode()],- breakdownFilter=BreakdownFilter(- breakdown_type=BreakdownType.DATA_WAREHOUSE_PERSON_PROPERTY, breakdown="stripe_customer.email"- ),- )- funnel_class = FunnelUDF(context=FunnelQueryContext(query=query, team=team))-- query_ast = funnel_class.get_query()- await sync_to_async(execute_hogql_query)(- query_type="FunnelsQuery",- query=query_ast,- team=team,- modifiers=create_default_modifiers_for_team(- team, HogQLQueryModifiers(personsOnEventsMode=PersonsOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_JOINED)- ),- )--@pytest.mark.django_db(transaction=True)@pytest.mark.asyncioasync def test_postgres_schema_evolution(team, postgres_config, postgres_connection):diff --git a/tach.toml b/tach.tomlindex 860135e1ee35..b3222068b647 100644--- a/tach.toml+++ b/tach.toml@@ -423,6 +423,8 @@ depends_on = ["products.event_definitions","products.feature_flags","products.notifications",+ # An experiment with a funnel metric runs the funnel through product analytics.+ "products.product_analytics","products.product_tours","products.surveys","products.tasks",