:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(hogql): add a useNewEventsSchema query modifier (#106274)
Sandy Spicere633808a34a8
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 15364cbf8722..71c6610ffe4c 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -29371,6 +29371,10 @@"useMaterializedViews": {"type": "boolean"},+ "useNewEventsSchema": {+ "description": "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it.",+ "type": "boolean"+ },"usePreaggregatedIntermediateResults": {"type": "boolean"},diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex c44d2aa5f27d..4007e69ea1a3 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -533,6 +533,8 @@ export interface HogQLQueryModifiers {materializedColumnsOptimizationMode?: 'disabled' | 'optimized'propertyGroupsMode?: 'enabled' | 'disabled' | 'optimized'useMaterializedViews?: boolean+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: booleancustomChannelTypeRules?: CustomChannelRule[]customBotDefinitions?: CustomBotRule[]/** Do not treat a missing user agent as automation on cookieless events. Positive bot signals and custom project rules still apply. Resolved server-side; not intended to be set by clients. */diff --git a/posthog/api/team.py b/posthog/api/team.pyindex ab7095e4953d..fc31da37f316 100644--- a/posthog/api/team.py+++ b/posthog/api/team.py@@ -2106,6 +2106,11 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixinif not isinstance(value, dict):raise exceptions.ValidationError("Must provide a dictionary or None.")+ # The native JSON events table is an internal rollout switch that PostHog staff set per project in Django+ # admin. Dropping the key keeps a client from setting or clearing it, including a settings page that echoes+ # the whole modifiers dict back.+ value = {key: item for key, item in value.items() if key != "useNewEventsSchema"}+if "bounceRateDurationSeconds" in value:bounce_rate = value["bounceRateDurationSeconds"]if bounce_rate is not None:diff --git a/posthog/api/test/test_team.py b/posthog/api/test/test_team.pyindex a432a20a23da..cf5eec19e9d8 100644--- a/posthog/api/test/test_team.py+++ b/posthog/api/test/test_team.py@@ -1266,6 +1266,23 @@ def team_api_test_factory():{"id": "test", "channel_type": "Direct", "combiner": "AND", "items": []}]+ def test_modifiers_use_new_events_schema_is_not_client_writable(self) -> None:+ response = self.client.patch(+ f"/api/environments/{self.team.id}",+ {"modifiers": {"useNewEventsSchema": True}},+ )+ assert response.status_code == status.HTTP_200_OK, response.json()+ assert "useNewEventsSchema" not in response.json()["modifiers"]++ self.team.modifiers = {"useNewEventsSchema": True}+ self.team.save()+ response = self.client.patch(+ f"/api/environments/{self.team.id}",+ {"modifiers": {"useNewEventsSchema": False, "bounceRateDurationSeconds": 30}},+ )+ assert response.status_code == status.HTTP_200_OK, response.json()+ assert response.json()["modifiers"] == {"useNewEventsSchema": True, "bounceRateDurationSeconds": 30}+@parameterized.expand([(1, True),diff --git a/posthog/hogql/context.py b/posthog/hogql/context.pyindex 232ad283d120..13aebe3f7ab2 100644--- a/posthog/hogql/context.py+++ b/posthog/hogql/context.py@@ -190,7 +190,7 @@ class HogQLContext:from posthog.models.event.new_events_schema import use_new_events_schema # noqa: PLC0415# Pin per context so an instance-setting flip can't mix schemas within one query.- self.use_new_events_schema = use_new_events_schema(self.team_id)+ self.use_new_events_schema = use_new_events_schema(self.team_id, self.modifiers)return self.use_new_events_schemadef add_value(self, value: Any) -> str:diff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex 4585187beda3..963bc22a8a58 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -1515,7 +1515,16 @@ class TestPrinter(BaseTest):# must pick up a runtime flip.with override_instance_config("CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA", True):sql = self._select("SELECT event FROM events")+ legacy_sql = self._select(+ "SELECT event FROM events",+ HogQLContext(+ team_id=self.team.pk,+ enable_select_queries=True,+ modifiers=HogQLQueryModifiers(useNewEventsSchema=False),+ ),+ )self.assertIn("FROM events_json", sql)+ self.assertNotIn("events_json", legacy_sql)@override_settings(CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA=False)def test_instance_setting_team_allowlist_enables_new_events_schema(self) -> None:@@ -1524,10 +1533,19 @@ class TestPrinter(BaseTest):sql = self._select("SELECT event FROM events")self.assertIn("FROM events_json", sql)- # A list naming only other teams must not flip this team.+ # A list naming only other teams must not flip this team, unless the query's modifier asks for it.with override_instance_config("CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA_TEAMS", "999999"):sql = self._select("SELECT event FROM events")+ native_sql = self._select(+ "SELECT event FROM events",+ HogQLContext(+ team_id=self.team.pk,+ enable_select_queries=True,+ modifiers=HogQLQueryModifiers(useNewEventsSchema=True),+ ),+ )self.assertNotIn("FROM events_json", sql)+ self.assertIn("FROM events_json", native_sql)with override_instance_config("CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA_TEAMS", "invalid"):with pytest.raises(ValueError):diff --git a/posthog/hogql_queries/ai/ai_table_resolver.py b/posthog/hogql_queries/ai/ai_table_resolver.pyindex bab46c0320d2..f0430cf686f0 100644--- a/posthog/hogql_queries/ai/ai_table_resolver.py+++ b/posthog/hogql_queries/ai/ai_table_resolver.py@@ -133,7 +133,7 @@ def query_ai_events(AI_EVENTS_QUERY_TOTAL.labels(source="dedicated_table").inc()return result- events_schema = use_new_events_schema(team.pk)+ events_schema = use_new_events_schema(team.pk, modifiers)events_query = rewrite_query_for_events_table(query)fallback_source_placeholders = fallback_placeholders if fallback_placeholders is not None else placeholdersevents_placeholders = {diff --git a/posthog/hogql_queries/ai/event_taxonomy_query_runner.py b/posthog/hogql_queries/ai/event_taxonomy_query_runner.pyindex e4cc9e98f36e..0b9d2d6d2e6f 100644--- a/posthog/hogql_queries/ai/event_taxonomy_query_runner.py+++ b/posthog/hogql_queries/ai/event_taxonomy_query_runner.py@@ -36,7 +36,7 @@ class EventTaxonomyQueryRunner(TaxonomyCacheMixin, AnalyticsQueryRunner[EventTaxdef __init__(self, *args, settings: HogQLGlobalSettings | None = None, **kwargs):super().__init__(*args, **kwargs)self.settings = settings- self._use_new_events_schema = use_new_events_schema(self.team.pk)+ self._use_new_events_schema = use_new_events_schema(self.team.pk, self.modifiers)self.paginator = HogQLHasMorePaginator(limit=self.query.limit or DEFAULT_LIMIT,offset=self.query.offset or 0,diff --git a/posthog/hogql_queries/ai/session_query_runner.py b/posthog/hogql_queries/ai/session_query_runner.pyindex 1ee969721817..f19f29754c26 100644--- a/posthog/hogql_queries/ai/session_query_runner.py+++ b/posthog/hogql_queries/ai/session_query_runner.py@@ -114,7 +114,7 @@ class SessionQueryRunner(AnalyticsQueryRunner[SessionQueryResponse]):tags_context(product=Product.LLM_ANALYTICS),):tag_queries(ai_query_source="shared_table_fallback")- events_schema = use_new_events_schema(self.team.pk)+ events_schema = use_new_events_schema(self.team.pk, self.modifiers)query_result = self.paginator.execute_hogql_query(query=rewrite_query_for_events_table(query),placeholders={diff --git a/posthog/hogql_queries/insight_actors_query_options_runner.py b/posthog/hogql_queries/insight_actors_query_options_runner.pyindex f912428ee3d2..809763365e16 100644--- a/posthog/hogql_queries/insight_actors_query_options_runner.py+++ b/posthog/hogql_queries/insight_actors_query_options_runner.py@@ -1,15 +1,20 @@-from typing import cast+from typing import Any, Optional, castfrom posthog.schema import (CachedInsightActorsQueryOptionsResponse,+ HogQLQueryModifiers,InsightActorsQueryOptions,InsightActorsQueryOptionsResponse,)from posthog.hogql import ast+from posthog.hogql.constants import LimitContext+from posthog.hogql.timings import HogQLTimings-from posthog.hogql_queries.query_runner import QueryRunner, get_query_runner+from posthog.hogql_queries.query_runner import QueryRunner, get_query_runner, query_node_modifiers+from posthog.models import Teamfrom posthog.models.filters.mixins.utils import cached_property+from posthog.models.user import Userfrom products.product_analytics.backend.facade.queries import (FunnelsQueryRunner,@@ -22,6 +27,27 @@ class InsightActorsQueryOptionsRunner(QueryRunner):query: InsightActorsQueryOptionscached_response: CachedInsightActorsQueryOptionsResponse+ def __init__(+ self,+ query: InsightActorsQueryOptions | dict[str, Any],+ team: Team,+ timings: Optional[HogQLTimings] = None,+ modifiers: Optional[HogQLQueryModifiers] = None,+ limit_context: Optional[LimitContext] = None,+ query_id: Optional[str] = None,+ user: Optional[User] = None,+ ):+ super().__init__(+ query,+ team=team,+ timings=timings,+ modifiers=modifiers,+ limit_context=limit_context,+ query_id=query_id,+ extract_modifiers=lambda query: query_node_modifiers(query.source.source),+ user=user,+ )+@cached_propertydef source_runner(self) -> QueryRunner:# Modifiers must flow through so a cache-only read by the source runner (e.g. funnels)diff --git a/posthog/hogql_queries/insight_actors_query_runner.py b/posthog/hogql_queries/insight_actors_query_runner.pyindex be4f1d639f1f..133b97b52582 100644--- a/posthog/hogql_queries/insight_actors_query_runner.py+++ b/posthog/hogql_queries/insight_actors_query_runner.py@@ -24,7 +24,7 @@ from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.hogql.query import execute_hogql_queryfrom posthog.hogql.timings import HogQLTimings-from posthog.hogql_queries.query_runner import AnalyticsQueryRunner, QueryRunner, get_query_runner+from posthog.hogql_queries.query_runner import AnalyticsQueryRunner, QueryRunner, get_query_runner, query_node_modifiersfrom posthog.models import Teamfrom posthog.models.filters.mixins.utils import cached_propertyfrom posthog.models.user import User@@ -63,7 +63,7 @@ class InsightActorsQueryRunner(AnalyticsQueryRunner[HogQLQueryResponse]):modifiers=modifiers,limit_context=limit_context,query_id=query_id,- extract_modifiers=lambda query: query.source.modifiers if hasattr(query.source, "modifiers") else None,+ extract_modifiers=lambda query: query_node_modifiers(query.source),user=user,)diff --git a/posthog/hogql_queries/property_values_query_runner.py b/posthog/hogql_queries/property_values_query_runner.pyindex 3f4ce89b9ade..bfbc1c302c22 100644--- a/posthog/hogql_queries/property_values_query_runner.py+++ b/posthog/hogql_queries/property_values_query_runner.py@@ -93,7 +93,7 @@ class PropertyValuesQueryRunner(AnalyticsQueryRunner[PropertyValuesQueryResponse@cached_propertydef _use_new_events_schema(self) -> bool:- return use_new_events_schema(self.team.pk)+ return use_new_events_schema(self.team.pk, self.modifiers)@cached_propertydef _restricted_event_property_names(self) -> set[str]:diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.pyindex 437af2ebd71e..c1487313a828 100644--- a/posthog/hogql_queries/query_runner.py+++ b/posthog/hogql_queries/query_runner.py@@ -1801,6 +1801,14 @@ def resolve_series_custom_name(series: Any, raw_label: str | None) -> str | Nonereturn None+def query_node_modifiers(query: BaseModel) -> Optional[HogQLQueryModifiers]:+ # A correlation query has no modifiers field. It uses the modifiers of the funnel it analyzes,+ # so that the correlation reads the same events table and person data as that funnel.+ if isinstance(query, FunnelCorrelationQuery):+ return query.source.source.modifiers+ return getattr(query, "modifiers", None)++class QueryRunner(ABC, Generic[Q, R, CR]):query: Qresponse: R@@ -1831,7 +1839,7 @@ class QueryRunner(ABC, Generic[Q, R, CR]):limit_context: Optional[LimitContext] = None,query_id: Optional[str] = None,workload: Workload = Workload.DEFAULT,- extract_modifiers=lambda query: query.modifiers if hasattr(query, "modifiers") else None,+ extract_modifiers=query_node_modifiers,user: Optional[User] = None,ch_user: ClickHouseUser = ClickHouseUser.DEFAULT,):diff --git a/posthog/hogql_queries/sessions_timeline_query_runner.py b/posthog/hogql_queries/sessions_timeline_query_runner.pyindex 0500941764ed..6440f1932dd6 100644--- a/posthog/hogql_queries/sessions_timeline_query_runner.py+++ b/posthog/hogql_queries/sessions_timeline_query_runner.py@@ -44,7 +44,7 @@ class SessionsTimelineQueryRunner(AnalyticsQueryRunner[SessionsTimelineQueryResp@cached_propertydef _use_new_events_schema(self) -> bool:- return use_new_events_schema(self.team.pk)+ return use_new_events_schema(self.team.pk, self.modifiers)def _get_events_subquery(self) -> ast.SelectQuery:after = relative_date_parse(self.query.after or "-24h", self.team.timezone_info)diff --git a/posthog/models/event/new_events_schema.py b/posthog/models/event/new_events_schema.pyindex 3287efc780f4..4624e20c656d 100644--- a/posthog/models/event/new_events_schema.py+++ b/posthog/models/event/new_events_schema.py@@ -1,16 +1,24 @@+from typing import TYPE_CHECKING+from django.conf import settingsfrom posthog.models.instance_setting import get_instance_setting+if TYPE_CHECKING:+ from posthog.schema import HogQLQueryModifiers+-def use_new_events_schema(team_id: int | None = None) -> bool:+def use_new_events_schema(team_id: int | None = None, modifiers: "HogQLQueryModifiers | None" = None) -> bool:"""Whether HogQL reads should target the native-JSON events tables.- The instance setting flips it globally at runtime, and the *_TEAMS instance setting enables it+ A query's `useNewEventsSchema` modifier decides when it is set, so one query can be run against either table.+ Otherwise the instance setting flips it globally at runtime, and the *_TEAMS instance setting enables itfor individual teams first (both cached for up to 60s per worker). Code running inside a queryshould prefer HogQLContext.uses_new_events_schema(), which resolves this once so a mid-queryflip can't mix schemas."""+ if modifiers is not None and modifiers.useNewEventsSchema is not None:+ return modifiers.useNewEventsSchemaif settings.TEST and settings.CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA:return Trueif get_instance_setting("CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA"):diff --git a/posthog/schema.py b/posthog/schema.pyindex f1702bfebb98..beba05d87d98 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -5812,6 +5812,16 @@ class HogQLQueryModifiers(BaseModel):),)useMaterializedViews: bool | None = None+ useNewEventsSchema: bool | None = Field(+ default=None,+ description=(+ "Read events from the native JSON events table (`true`) or the legacy"+ " events table (`false`). When unset, the project's stored value applies,"+ " then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This"+ " is an internal rollout switch. PostHog staff set the project value in"+ " Django admin and the project settings API ignores it."+ ),+ )usePreaggregatedIntermediateResults: bool | None = NoneusePreaggregatedTableTransforms: bool | None = Field(default=None,diff --git a/products/batch_exports/frontend/generated/api.schemas.ts b/products/batch_exports/frontend/generated/api.schemas.tsindex 31bf195e78d8..e0c5bfb16d01 100644--- a/products/batch_exports/frontend/generated/api.schemas.ts+++ b/products/batch_exports/frontend/generated/api.schemas.ts@@ -861,6 +861,8 @@ export interface HogQLQueryModifiersApi {/** Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types */typeAwareCastSimplification?: boolean | nulluseMaterializedViews?: boolean | null+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: boolean | nullusePreaggregatedIntermediateResults?: boolean | null/** Try to automatically convert HogQL queries to use preaggregated tables at the AST level * */usePreaggregatedTableTransforms?: boolean | nulldiff --git a/products/batch_exports/frontend/generated/api.zod.ts b/products/batch_exports/frontend/generated/api.zod.tsindex c9da39d47ac0..d6f68298ed9f 100644--- a/products/batch_exports/frontend/generated/api.zod.ts+++ b/products/batch_exports/frontend/generated/api.zod.ts@@ -651,6 +651,12 @@ export const BatchExportsCreateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -1590,6 +1596,12 @@ export const BatchExportsUpdateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -2288,6 +2300,12 @@ export const BatchExportsPartialUpdateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -2978,6 +2996,12 @@ export const BatchExportsRunTestStepCreateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -3687,6 +3711,12 @@ export const BatchExportsRunTestStepNewCreateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -4106,6 +4136,12 @@ export const FileDownloadBatchExportsCreateBody = /* @__PURE__ */ zod.union(['Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -4346,6 +4382,12 @@ export const FileDownloadBatchExportsCountRowsCreateBody = /* @__PURE__ */ zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.tsindex 4c41a2434171..570f2f8c1eba 100644--- a/products/customer_analytics/frontend/generated/api.schemas.ts+++ b/products/customer_analytics/frontend/generated/api.schemas.ts@@ -1771,6 +1771,8 @@ export interface HogQLQueryModifiersApi {/** Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types */typeAwareCastSimplification?: boolean | nulluseMaterializedViews?: boolean | null+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: boolean | nullusePreaggregatedIntermediateResults?: boolean | null/** Try to automatically convert HogQL queries to use preaggregated tables at the AST level * */usePreaggregatedTableTransforms?: boolean | nulldiff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 4dc0463ada1f..788e32d43479 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -1610,6 +1610,8 @@ export interface HogQLQueryModifiersApi {/** Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types */typeAwareCastSimplification?: boolean | nulluseMaterializedViews?: boolean | null+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: boolean | nullusePreaggregatedIntermediateResults?: boolean | null/** Try to automatically convert HogQL queries to use preaggregated tables at the AST level * */usePreaggregatedTableTransforms?: boolean | nulldiff --git a/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.py b/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.pyindex 0d2853588036..ed07de84a2c7 100644--- a/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/funnels/funnel_correlation_query_runner.py@@ -116,7 +116,7 @@ class FunnelCorrelationQueryRunner(AnalyticsQueryRunner[FunnelCorrelationResponsuser: Optional[User] = None,):super().__init__(query, team=team, timings=timings, modifiers=modifiers, limit_context=limit_context, user=user)- self._use_new_events_schema = use_new_events_schema(team.pk)+ self._use_new_events_schema = use_new_events_schema(team.pk, self.modifiers)self.actors_query = self.query.sourceself.funnels_query = self.actors_query.sourcediff --git a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.py b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.pyindex d1d272d6b2aa..6baf2079b0be 100644--- a/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.py+++ b/products/product_analytics/backend/hogql_queries/funnels/test/test_funnel_correlation_actors.py@@ -14,6 +14,8 @@ from unittest import skipfrom django.utils import timezone+from parameterized import parameterized+from posthog.schema import (ActorsQuery,DateRange,@@ -24,10 +26,13 @@ from posthog.schema import (FunnelsActorsQuery,FunnelsFilter,FunnelsQuery,+ HogQLQueryModifiers,+ InsightActorsQueryOptions,StepOrderValue,)from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner+from posthog.hogql_queries.query_runner import get_query_runnerfrom posthog.models.team.team import Teamfrom posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summaryfrom posthog.test.test_journeys import journeys_for@@ -68,6 +73,24 @@ def get_actors(class TestFunnelCorrelationActors(ClickhouseTestMixin, APIBaseTest):maxDiff = None+ @parameterized.expand([("correlation",), ("correlation_actors",), ("actors_options",)])+ def test_wrapper_queries_use_source_funnel_modifiers(self, wrapper):+ funnel = FunnelsQuery(+ series=[EventsNode(event="$pageview"), EventsNode(event="$pageview")],+ modifiers=HogQLQueryModifiers(useNewEventsSchema=True),+ )+ correlation = FunnelCorrelationQuery(+ source=FunnelsActorsQuery(source=funnel), funnelCorrelationType=FunnelCorrelationResultsType.EVENTS+ )+ query = {+ "correlation": correlation,+ "correlation_actors": FunnelCorrelationActorsQuery(source=correlation),+ "actors_options": InsightActorsQueryOptions(source=FunnelsActorsQuery(source=funnel)),+ }[wrapper]++ runner = get_query_runner(query, self.team)+ self.assertTrue(runner.modifiers.useNewEventsSchema)+def _setup_basic_test(self):query = FunnelsQuery(series=[diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex d7d19b74eda4..1c788aa6456c 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -667,6 +667,8 @@ export interface HogQLQueryModifiersApi {/** Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types */typeAwareCastSimplification?: boolean | nulluseMaterializedViews?: boolean | null+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: boolean | nullusePreaggregatedIntermediateResults?: boolean | null/** Try to automatically convert HogQL queries to use preaggregated tables at the AST level * */usePreaggregatedTableTransforms?: boolean | nulldiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 68df6e3c1c10..f10d0a30803a 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -1884,6 +1884,8 @@ export namespace Schemas {/** Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types */typeAwareCastSimplification?: boolean | null;useMaterializedViews?: boolean | null;+ /** Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it. */+ useNewEventsSchema?: boolean | null;usePreaggregatedIntermediateResults?: boolean | null;/** Try to automatically convert HogQL queries to use preaggregated tables at the AST level * */usePreaggregatedTableTransforms?: boolean | null;diff --git a/services/mcp/src/generated/batch_exports/api.ts b/services/mcp/src/generated/batch_exports/api.tsindex eb5572134efa..418a36a0e593 100644--- a/services/mcp/src/generated/batch_exports/api.ts+++ b/services/mcp/src/generated/batch_exports/api.ts@@ -663,6 +663,12 @@ export const BatchExportsCreateBody = () => zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -1365,6 +1371,12 @@ export const BatchExportsPartialUpdateBody = () => zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -1798,6 +1810,12 @@ export const FileDownloadBatchExportsCreateBody = () => zod.union(['Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])@@ -2074,6 +2092,12 @@ export const FileDownloadBatchExportsCountRowsCreateBody = () => zod'Remove provably redundant casts and nullability wrappers (e.g. `toString(String)`, `assumeNotNull(non_nullable)`, dead `ifNull` fallbacks) using inferred expression types'),useMaterializedViews: zod.union([zod.boolean(), zod.null()]).optional(),+ useNewEventsSchema: zod+ .union([zod.boolean(), zod.null()])+ .optional()+ .describe(+ "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ ),usePreaggregatedIntermediateResults: zod.union([zod.boolean(), zod.null()]).optional(),usePreaggregatedTableTransforms: zod.union([zod.boolean(), zod.null()])diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-create.jsonindex 70d05643f517..c3cdb9c9c49a 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-create.json@@ -1043,6 +1043,17 @@}]},+ "useNewEventsSchema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ },"usePreaggregatedIntermediateResults": {"anyOf": [{diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-update.jsonindex b41340116f80..ae01b32d68cd 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/batch-export-update.json@@ -1042,6 +1042,17 @@}]},+ "useNewEventsSchema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ },"usePreaggregatedIntermediateResults": {"anyOf": [{diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-count-rows-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-count-rows-create.jsonindex cdf89261024d..c5d37042dd69 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-count-rows-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-count-rows-create.json@@ -518,6 +518,17 @@}]},+ "useNewEventsSchema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ },"usePreaggregatedIntermediateResults": {"anyOf": [{diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.jsonindex c508e7cc54d3..6a9cded8c25b 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json@@ -747,6 +747,17 @@}]},+ "useNewEventsSchema": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Read events from the native JSON events table (`true`) or the legacy events table (`false`). When unset, the project's stored value applies, then the `CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA` instance settings. This is an internal rollout switch. PostHog staff set the project value in Django admin and the project settings API ignores it."+ },"usePreaggregatedIntermediateResults": {"anyOf": [{