: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(experiments): add a unit binding to warehouse-native sources (#128170)
Juraj Majerik5581dbff9c04
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 8f74aa0c96db..b8e4fe2a35c7 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -27871,7 +27871,7 @@},"ExperimentWarehouseNativeExposureConfig": {"additionalProperties": false,- "description": "Exposures that live in the customer's warehouse, read through a direct connection. An experiment with this exposure runs entirely in the warehouse, so every metric source must be an `ExperimentWarehouseNativeNode` on the same connection.",+ "description": "Exposures that live in the customer's warehouse, read through a direct connection. An experiment with this exposure runs entirely in the warehouse, so every metric source must be an `ExperimentWarehouseNativeNode` on the same connection with the same unit binding.","properties": {"connection_id": {"description": "The direct-query source (an ExternalDataSource id) the SQL is written for.",@@ -27888,12 +27888,15 @@"response": {"type": "object"},+ "unit": {+ "$ref": "#/definitions/ExperimentWarehouseNativeUnitBinding"+ },"version": {"description": "version of the node, used for schema migrations","type": "number"}},- "required": ["connection_id", "kind", "query"],+ "required": ["connection_id", "kind", "query", "unit"],"type": "object"},"ExperimentWarehouseNativeMathType": {@@ -27931,12 +27934,31 @@"response": {"type": "object"},+ "unit": {+ "$ref": "#/definitions/ExperimentWarehouseNativeUnitBinding"+ },"version": {"description": "version of the node, used for schema migrations","type": "number"}},- "required": ["connection_id", "kind", "query"],+ "required": ["connection_id", "kind", "query", "unit"],+ "type": "object"+ },+ "ExperimentWarehouseNativeUnitBinding": {+ "additionalProperties": false,+ "description": "What the `entity_id` column of a warehouse-native query identifies. Exposures and outcomes join on `entity_id` inside the warehouse, and the same connection does not make two queries compatible: one can return account ids and another customer ids. Every warehouse-native source stores its binding so a saved metric keeps it when it is attached to another experiment, and so attachment can compare bindings instead of guessing from SQL. Equal labels are required for compatibility but cannot prove the SQL returns the same identities; the author confirms that.",+ "properties": {+ "id_namespace": {+ "description": "Which ids represent that unit, such as `billing_customer_id`.",+ "type": "string"+ },+ "unit_type": {+ "description": "What was randomized, as a stable project-scoped label such as `customer` or `account`.",+ "type": "string"+ }+ },+ "required": ["unit_type", "id_namespace"],"type": "object"},"ExternalQueryError": {diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 7ca5febab890..b43c6dd50019 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -5962,9 +5962,22 @@ export interface ExperimentEventExposureConfig extends Node {properties: AnyPropertyFilter[]}+/** What the `entity_id` column of a warehouse-native query identifies. Exposures and outcomes join on+ * `entity_id` inside the warehouse, and the same connection does not make two queries compatible:+ * one can return account ids and another customer ids. Every warehouse-native source stores its+ * binding so a saved metric keeps it when it is attached to another experiment, and so attachment+ * can compare bindings instead of guessing from SQL. Equal labels are required for compatibility+ * but cannot prove the SQL returns the same identities; the author confirms that. */+export interface ExperimentWarehouseNativeUnitBinding {+ /** What was randomized, as a stable project-scoped label such as `customer` or `account`. */+ unit_type: string+ /** Which ids represent that unit, such as `billing_customer_id`. */+ id_namespace: string+}+/** Exposures that live in the customer's warehouse, read through a direct connection. An experiment* with this exposure runs entirely in the warehouse, so every metric source must be an- * `ExperimentWarehouseNativeNode` on the same connection. */+ * `ExperimentWarehouseNativeNode` on the same connection with the same unit binding. */export interface ExperimentWarehouseNativeExposureConfig extends Node {kind: NodeKind.ExperimentWarehouseNativeExposureConfig/** The direct-query source (an ExternalDataSource id) the SQL is written for. */@@ -5973,6 +5986,7 @@ export interface ExperimentWarehouseNativeExposureConfig extends Node {* `variant` and `timestamp` columns. PostHog keeps the first exposure per entity and applies* the experiment's date range and multiple-variant handling. */query: string+ unit: ExperimentWarehouseNativeUnitBinding}// ── Slim API types for experiment create/update ──────────────────────@@ -6248,6 +6262,7 @@ export interface ExperimentWarehouseNativeNode extends Node {/** Read-only SQL in the warehouse's dialect, returning one row per outcome with `entity_id` and* `timestamp` columns plus any numeric columns a metric can measure. */query: string+ unit: ExperimentWarehouseNativeUnitBinding/** How to aggregate the rows per entity. Defaults to `total` (row count). */math?: ExperimentWarehouseNativeMathType/** The numeric column `math` reads. Required when `math` is `sum`. One SQL relation can servediff --git a/frontend/src/queries/validators.js b/frontend/src/queries/validators.jsindex ac50e3fc6e10..5a3953b6f77c 100644--- a/frontend/src/queries/validators.js+++ b/frontend/src/queries/validators.js@@ -11142,9 +11142,10 @@ const schema103 = {type: 'string',},response: { type: 'object' },+ unit: { $ref: '#/definitions/ExperimentWarehouseNativeUnitBinding' },version: { description: 'version of the node, used for schema migrations', type: 'number' },},- required: ['connection_id', 'kind', 'query'],+ required: ['connection_id', 'kind', 'query', 'unit'],type: 'object',}const schema104 = {@@ -11152,6 +11153,20 @@ const schema104 = {enum: ['total', 'sum'],type: 'string',}+const schema105 = {+ additionalProperties: false,+ description:+ 'What the `entity_id` column of a warehouse-native query identifies. Exposures and outcomes join on `entity_id` inside the warehouse, and the same connection does not make two queries compatible: one can return account ids and another customer ids. Every warehouse-native source stores its binding so a saved metric keeps it when it is attached to another experiment, and so attachment can compare bindings instead of guessing from SQL. Equal labels are required for compatibility but cannot prove the SQL returns the same identities; the author confirms that.',+ properties: {+ id_namespace: { description: 'Which ids represent that unit, such as `billing_customer_id`.', type: 'string' },+ unit_type: {+ description: 'What was randomized, as a stable project-scoped label such as `customer` or `account`.',+ type: 'string',+ },+ },+ required: ['unit_type', 'id_namespace'],+ type: 'object',+}function validate111(data, { instancePath = '', parentData, parentDataProperty, rootData = data } = {}) {let vErrors = nulllet errors = 0@@ -11161,7 +11176,8 @@ function validate111(data, { instancePath = '', parentData, parentDataProperty,if ((data.connection_id === undefined && (missing0 = 'connection_id')) ||(data.kind === undefined && (missing0 = 'kind')) ||- (data.query === undefined && (missing0 = 'query'))+ (data.query === undefined && (missing0 = 'query')) ||+ (data.unit === undefined && (missing0 = 'unit'))) {validate111.errors = [{@@ -11176,18 +11192,7 @@ function validate111(data, { instancePath = '', parentData, parentDataProperty,} else {const _errs1 = errorsfor (const key0 in data) {- if (- !(- key0 === 'connection_id' ||- key0 === 'custom_name' ||- key0 === 'kind' ||- key0 === 'math' ||- key0 === 'math_property' ||- key0 === 'query' ||- key0 === 'response' ||- key0 === 'version'- )- ) {+ if (!func2.call(schema103.properties, key0)) {validate111.errors = [{instancePath,@@ -11362,25 +11367,147 @@ function validate111(data, { instancePath = '', parentData, parentDataProperty,var valid0 = true}if (valid0) {- if (data.version !== undefined) {- let data7 = data.version+ if (data.unit !== undefined) {+ let data7 = data.unitconst _errs17 = errors- if (!(typeof data7 == 'number' && isFinite(data7))) {- validate111.errors = [- {- instancePath: instancePath + '/version',- schemaPath: '#/properties/version/type',- keyword: 'type',- params: { type: 'number' },- message: 'must be number',- },- ]- return false+ const _errs18 = errors+ if (errors === _errs18) {+ if (+ data7 &&+ typeof data7 == 'object' &&+ !Array.isArray(data7)+ ) {+ let missing1+ if (+ (data7.unit_type === undefined &&+ (missing1 = 'unit_type')) ||+ (data7.id_namespace === undefined &&+ (missing1 = 'id_namespace'))+ ) {+ validate111.errors = [+ {+ instancePath: instancePath + '/unit',+ schemaPath:+ '#/definitions/ExperimentWarehouseNativeUnitBinding/required',+ keyword: 'required',+ params: { missingProperty: missing1 },+ message:+ "must have required property '" ++ missing1 ++ "'",+ },+ ]+ return false+ } else {+ const _errs20 = errors+ for (const key1 in data7) {+ if (+ !(+ key1 === 'id_namespace' ||+ key1 === 'unit_type'+ )+ ) {+ validate111.errors = [+ {+ instancePath: instancePath + '/unit',+ schemaPath:+ '#/definitions/ExperimentWarehouseNativeUnitBinding/additionalProperties',+ keyword: 'additionalProperties',+ params: { additionalProperty: key1 },+ message:+ 'must NOT have additional properties',+ },+ ]+ return false+ break+ }+ }+ if (_errs20 === errors) {+ if (data7.id_namespace !== undefined) {+ const _errs21 = errors+ if (typeof data7.id_namespace !== 'string') {+ validate111.errors = [+ {+ instancePath:+ instancePath ++ '/unit/id_namespace',+ schemaPath:+ '#/definitions/ExperimentWarehouseNativeUnitBinding/properties/id_namespace/type',+ keyword: 'type',+ params: { type: 'string' },+ message: 'must be string',+ },+ ]+ return false+ }+ var valid3 = _errs21 === errors+ } else {+ var valid3 = true+ }+ if (valid3) {+ if (data7.unit_type !== undefined) {+ const _errs23 = errors+ if (typeof data7.unit_type !== 'string') {+ validate111.errors = [+ {+ instancePath:+ instancePath ++ '/unit/unit_type',+ schemaPath:+ '#/definitions/ExperimentWarehouseNativeUnitBinding/properties/unit_type/type',+ keyword: 'type',+ params: { type: 'string' },+ message: 'must be string',+ },+ ]+ return false+ }+ var valid3 = _errs23 === errors+ } else {+ var valid3 = true+ }+ }+ }+ }+ } else {+ validate111.errors = [+ {+ instancePath: instancePath + '/unit',+ schemaPath:+ '#/definitions/ExperimentWarehouseNativeUnitBinding/type',+ keyword: 'type',+ params: { type: 'object' },+ message: 'must be object',+ },+ ]+ return false+ }}var valid0 = _errs17 === errors} else {var valid0 = true}+ if (valid0) {+ if (data.version !== undefined) {+ let data10 = data.version+ const _errs25 = errors+ if (!(typeof data10 == 'number' && isFinite(data10))) {+ validate111.errors = [+ {+ instancePath: instancePath + '/version',+ schemaPath: '#/properties/version/type',+ keyword: 'type',+ params: { type: 'number' },+ message: 'must be number',+ },+ ]+ return false+ }+ var valid0 = _errs25 === errors+ } else {+ var valid0 = true+ }+ }}}}@@ -12161,7 +12288,7 @@ function validate85(data, { instancePath = '', parentData, parentDataProperty, rvalidate85.errors = vErrorsreturn errors === 0}-const schema105 = {+const schema106 = {additionalProperties: false,properties: {breakdownAttributionType: {@@ -12192,9 +12319,9 @@ const schema105 = {required: ['kind', 'metric_type', 'series'],type: 'object',}-const schema106 = { enum: ['first_touch', 'last_touch', 'all_events', 'step'], type: 'string' }-const schema109 = { enum: ['strict', 'unordered', 'ordered'], type: 'string' }-const schema111 = {+const schema107 = { enum: ['first_touch', 'last_touch', 'all_events', 'step'], type: 'string' }+const schema110 = { enum: ['strict', 'unordered', 'ordered'], type: 'string' }+const schema112 = {discriminator: { propertyName: 'kind' },oneOf: [{ $ref: '#/definitions/EventsNode' },@@ -12331,7 +12458,7 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,} else {const _errs1 = errorsfor (const key0 in data) {- if (!func2.call(schema105.properties, key0)) {+ if (!func2.call(schema106.properties, key0)) {validate115.errors = [{instancePath,@@ -12374,7 +12501,7 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,instancePath: instancePath + '/breakdownAttributionType',schemaPath: '#/definitions/BreakdownAttributionType/enum',keyword: 'enum',- params: { allowedValues: schema106.enum },+ params: { allowedValues: schema107.enum },message: 'must be equal to one of the allowed values',},]@@ -12532,7 +12659,7 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,instancePath: instancePath + '/funnel_order_type',schemaPath: '#/definitions/StepOrderValue/enum',keyword: 'enum',- params: { allowedValues: schema109.enum },+ params: { allowedValues: schema110.enum },message: 'must be equal to one of the allowed values',},]@@ -12878,7 +13005,7 @@ function validate115(data, { instancePath = '', parentData, parentDataProperty,validate115.errors = vErrorsreturn errors === 0}-const schema112 = {+const schema113 = {additionalProperties: false,properties: {breakdownFilter: { $ref: '#/definitions/BreakdownFilter' },@@ -12902,7 +13029,7 @@ const schema112 = {required: ['denominator', 'kind', 'metric_type', 'numerator'],type: 'object',}-const schema115 = {+const schema116 = {additionalProperties: false,properties: {ignore_zeros: { type: 'boolean' },@@ -12948,7 +13075,7 @@ function validate123(data, { instancePath = '', parentData, parentDataProperty,} else {const _errs1 = errorsfor (const key0 in data) {- if (!func2.call(schema112.properties, key0)) {+ if (!func2.call(schema113.properties, key0)) {validate123.errors = [{instancePath,@@ -13868,7 +13995,7 @@ function validate123(data, { instancePath = '', parentData, parentDataProperty,validate123.errors = vErrorsreturn errors === 0}-const schema118 = {+const schema119 = {additionalProperties: false,properties: {breakdownFilter: { $ref: '#/definitions/BreakdownFilter' },@@ -13903,7 +14030,7 @@ const schema118 = {],type: 'object',}-const schema119 = {+const schema120 = {discriminator: { propertyName: 'kind' },oneOf: [{ $ref: '#/definitions/EventsNode' },@@ -14016,7 +14143,7 @@ function validate130(data, { instancePath = '', parentData, parentDataProperty,validate130.errors = vErrorsreturn errors === 0}-const schema126 = {+const schema127 = {discriminator: { propertyName: 'kind' },oneOf: [{ $ref: '#/definitions/EventsNode' },@@ -14027,7 +14154,7 @@ const schema126 = {required: ['kind'],type: 'object',}-const schema127 = {+const schema128 = {additionalProperties: false,description:"Sentinel start source for retention metrics. It carries no event of its own: at query time it resolves to the experiment's exposure, so one shared metric anchors correctly on any experiment regardless of that experiment's exposure event.",@@ -14325,7 +14452,7 @@ function validate128(data, { instancePath = '', parentData, parentDataProperty,} else {const _errs1 = errorsfor (const key0 in data) {- if (!func2.call(schema118.properties, key0)) {+ if (!func2.call(schema119.properties, key0)) {validate128.errors = [{instancePath,@@ -14824,7 +14951,7 @@ function validate128(data, { instancePath = '', parentData, parentDataProperty,keyword: 'enum',params: {allowedValues:- schema118+ schema119.properties.start_handling.enum,diff --git a/frontend/src/queries/web-analytics-validators.js b/frontend/src/queries/web-analytics-validators.jsindex 286b7c8e0556..85222317a404 100644--- a/frontend/src/queries/web-analytics-validators.js+++ b/frontend/src/queries/web-analytics-validators.js@@ -1,8 +1,8 @@// AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY'use strict'export const WebAnalyticsPropertyFilters = validate141-const schema128 = { items: { $ref: '#/definitions/WebAnalyticsPropertyFilter' }, type: 'array' }-const schema129 = {+const schema129 = { items: { $ref: '#/definitions/WebAnalyticsPropertyFilter' }, type: 'array' }+const schema130 = {anyOf: [{ $ref: '#/definitions/EventPropertyFilter' },{ $ref: '#/definitions/PersonPropertyFilter' },@@ -1366,7 +1366,7 @@ function validate141(data, { instancePath = '', parentData, parentDataProperty,return errors === 0}export const CompareFilter = validate148-const schema130 = {+const schema131 = {additionalProperties: false,properties: {compare: {diff --git a/frontend/src/scenes/experiments/exposureContract.test.ts b/frontend/src/scenes/experiments/exposureContract.test.tsindex fb8c0f570759..8ea74b89bbb9 100644--- a/frontend/src/scenes/experiments/exposureContract.test.ts+++ b/frontend/src/scenes/experiments/exposureContract.test.ts@@ -262,7 +262,12 @@ describe('exposureContract', () => {],['a warehouse exposure',- { kind: NodeKind.ExperimentWarehouseNativeExposureConfig, connection_id: 'x', query: 'SELECT 1' },+ {+ kind: NodeKind.ExperimentWarehouseNativeExposureConfig,+ connection_id: 'x',+ query: 'SELECT 1',+ unit: { unit_type: 'customer', id_namespace: 'billing_customer_id' },+ },false,],])(diff --git a/posthog/schema.py b/posthog/schema.pyindex 08945bcb9fc3..bbc5dd9b81c0 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -1779,59 +1779,15 @@ class ExperimentRunningTimeCalculation(BaseModel):)-class ExperimentWarehouseNativeExposureConfig(BaseModel):- model_config = ConfigDict(- extra="forbid",- )- connection_id: str = Field(- ...,- description=("The direct-query source (an ExternalDataSource id) the SQL is written for."),- )- kind: Literal["ExperimentWarehouseNativeExposureConfig"] = "ExperimentWarehouseNativeExposureConfig"- query: str = Field(- ...,- description=(- "Read-only SQL in the warehouse's dialect, returning one row per exposure"- " with `entity_id`, `variant` and `timestamp` columns. PostHog keeps the"- " first exposure per entity and applies the experiment's date range and"- " multiple-variant handling."- ),- )- response: dict[str, Any] | None = None- version: float | None = Field(default=None, description="version of the node, used for schema migrations")---class ExperimentWarehouseNativeNode(BaseModel):+class ExperimentWarehouseNativeUnitBinding(BaseModel):model_config = ConfigDict(extra="forbid",)- connection_id: str = Field(- ...,- description=("The direct-query source (an ExternalDataSource id) the SQL is written for."),- )- custom_name: str | None = None- kind: Literal["ExperimentWarehouseNativeNode"] = "ExperimentWarehouseNativeNode"- math: ExperimentWarehouseNativeMathType | None = Field(- default=None,- description=("How to aggregate the rows per entity. Defaults to `total` (row count)."),- )- math_property: str | None = Field(- default=None,- description=(- "The numeric column `math` reads. Required when `math` is `sum`. One SQL"- " relation can serve several metrics, each reading a different column."- ),- )- query: str = Field(+ id_namespace: str = Field(..., description="Which ids represent that unit, such as `billing_customer_id`.")+ unit_type: str = Field(...,- description=(- "Read-only SQL in the warehouse's dialect, returning one row per outcome"- " with `entity_id` and `timestamp` columns plus any numeric columns a"- " metric can measure."- ),+ description=("What was randomized, as a stable project-scoped label such as `customer` or `account`."),)- response: dict[str, Any] | None = None- version: float | None = Field(default=None, description="version of the node, used for schema migrations")class FailureMessage(BaseModel):@@ -6090,6 +6046,63 @@ class ExperimentVariantResultFrequentist(BaseModel):validation_failures: list[ExperimentStatsValidationFailure] | None = None+class ExperimentWarehouseNativeExposureConfig(BaseModel):+ model_config = ConfigDict(+ extra="forbid",+ )+ connection_id: str = Field(+ ...,+ description=("The direct-query source (an ExternalDataSource id) the SQL is written for."),+ )+ kind: Literal["ExperimentWarehouseNativeExposureConfig"] = "ExperimentWarehouseNativeExposureConfig"+ query: str = Field(+ ...,+ description=(+ "Read-only SQL in the warehouse's dialect, returning one row per exposure"+ " with `entity_id`, `variant` and `timestamp` columns. PostHog keeps the"+ " first exposure per entity and applies the experiment's date range and"+ " multiple-variant handling."+ ),+ )+ response: dict[str, Any] | None = None+ unit: ExperimentWarehouseNativeUnitBinding+ version: float | None = Field(default=None, description="version of the node, used for schema migrations")+++class ExperimentWarehouseNativeNode(BaseModel):+ model_config = ConfigDict(+ extra="forbid",+ )+ connection_id: str = Field(+ ...,+ description=("The direct-query source (an ExternalDataSource id) the SQL is written for."),+ )+ custom_name: str | None = None+ kind: Literal["ExperimentWarehouseNativeNode"] = "ExperimentWarehouseNativeNode"+ math: ExperimentWarehouseNativeMathType | None = Field(+ default=None,+ description=("How to aggregate the rows per entity. Defaults to `total` (row count)."),+ )+ math_property: str | None = Field(+ default=None,+ description=(+ "The numeric column `math` reads. Required when `math` is `sum`. One SQL"+ " relation can serve several metrics, each reading a different column."+ ),+ )+ query: str = Field(+ ...,+ description=(+ "Read-only SQL in the warehouse's dialect, returning one row per outcome"+ " with `entity_id` and `timestamp` columns plus any numeric columns a"+ " metric can measure."+ ),+ )+ response: dict[str, Any] | None = None+ unit: ExperimentWarehouseNativeUnitBinding+ version: float | None = Field(default=None, description="version of the node, used for schema migrations")++class ExternalQueryError(BaseModel):model_config = ConfigDict(extra="forbid",diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex f628e58169f6..cf0392ffeb8e 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -6667,6 +6667,13 @@ export interface ExperimentEventExposureConfigApi {version?: number | null}+export interface ExperimentWarehouseNativeUnitBindingApi {+ /** Which ids represent that unit, such as `billing_customer_id`. */+ id_namespace: string+ /** What was randomized, as a stable project-scoped label such as `customer` or `account`. */+ unit_type: string+}+export type ExperimentWarehouseNativeExposureConfigApiResponse = { [key: string]: unknown } | nullexport interface ExperimentWarehouseNativeExposureConfigApi {@@ -6676,6 +6683,7 @@ export interface ExperimentWarehouseNativeExposureConfigApi {/** Read-only SQL in the warehouse's dialect, returning one row per exposure with `entity_id`, `variant` and `timestamp` columns. PostHog keeps the first exposure per entity and applies the experiment's date range and multiple-variant handling. */query: stringresponse?: ExperimentWarehouseNativeExposureConfigApiResponse+ unit: ExperimentWarehouseNativeUnitBindingApi/** version of the node, used for schema migrations */version?: number | null}@@ -6806,6 +6814,7 @@ export interface ExperimentWarehouseNativeNodeApi {/** Read-only SQL in the warehouse's dialect, returning one row per outcome with `entity_id` and `timestamp` columns plus any numeric columns a metric can measure. */query: stringresponse?: ExperimentWarehouseNativeNodeApiResponse+ unit: ExperimentWarehouseNativeUnitBindingApi/** version of the node, used for schema migrations */version?: number | null}diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.tsindex 14b5932a8f30..a43ebdeb27ec 100644--- a/products/desktop/packages/api-client/src/generated.ts+++ b/products/desktop/packages/api-client/src/generated.ts@@ -3800,6 +3800,16 @@ export namespace Schemas {response?: (Record<string, unknown> | null) | undefined;version?: (number | null) | undefined;};+ export type ExperimentWarehouseNativeUnitBinding = {+ /**+ * Which ids represent that unit, such as `billing_customer_id`.+ */+ id_namespace: string;+ /**+ * What was randomized, as a stable project-scoped label such as `customer` or `account`.+ */+ unit_type: string;+ };export type ExperimentWarehouseNativeExposureConfig = {/*** The direct-query source (an ExternalDataSource id) the SQL is written for.@@ -3811,6 +3821,7 @@ export namespace Schemas {*/query: string;response?: (Record<string, unknown> | null) | undefined;+ unit: ExperimentWarehouseNativeUnitBinding;version?: (number | null) | undefined;};export type MultipleVariantHandling = "exclude" | "first_seen";@@ -3919,6 +3930,7 @@ export namespace Schemas {*/query: string;response?: (Record<string, unknown> | null) | undefined;+ unit: ExperimentWarehouseNativeUnitBinding;version?: (number | null) | undefined;};export type ExperimentMeanMetric = {diff --git a/products/experiments/backend/health/test/test_exposure_columns.py b/products/experiments/backend/health/test/test_exposure_columns.pyindex 600116c67c1c..9d763d1cb0d7 100644--- a/products/experiments/backend/health/test/test_exposure_columns.py+++ b/products/experiments/backend/health/test/test_exposure_columns.py@@ -201,6 +201,7 @@ class TestLoadFiltersWithoutColumn(BaseTest):"kind": "ExperimentWarehouseNativeExposureConfig","connection_id": "source","query": "SELECT 1",+ "unit": {"unit_type": "customer", "id_namespace": "billing_customer_id"},}},None,diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.pyindex 4a30ba41d3c7..d670500fdfea 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py@@ -112,6 +112,7 @@ class TestExperimentExposuresQueryRunner(ExperimentQueryRunnerBaseTest):exposure_config=ExperimentWarehouseNativeExposureConfig(connection_id="00000000-0000-0000-0000-000000000000",query="SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ unit={"unit_type": "customer", "id_namespace": "billing_customer_id"},))diff --git a/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py b/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.pyindex 2a554d8f6f8d..272999bdf978 100644--- a/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py+++ b/products/experiments/backend/hogql_queries/test/test_experiment_actors_query.py@@ -242,6 +242,7 @@ class TestExperimentActorsQuery(ExperimentQueryRunnerBaseTest, ClickhouseTestMixexposureConfig=ExperimentWarehouseNativeExposureConfig(connection_id="00000000-0000-0000-0000-000000000000",query="SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ unit={"unit_type": "customer", "id_namespace": "billing_customer_id"},),),select=["id", "person"],diff --git a/products/experiments/backend/hogql_queries/test/test_exposure_query_logic.py b/products/experiments/backend/hogql_queries/test/test_exposure_query_logic.pyindex 0dff109baa5f..3e1a83bb1511 100644--- a/products/experiments/backend/hogql_queries/test/test_exposure_query_logic.py+++ b/products/experiments/backend/hogql_queries/test/test_exposure_query_logic.py@@ -32,6 +32,7 @@ def _event_config(event):_WAREHOUSE_NATIVE_EXPOSURE = ExperimentWarehouseNativeExposureConfig(connection_id="00000000-0000-0000-0000-000000000000",query="SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ unit={"unit_type": "customer", "id_namespace": "billing_customer_id"},)diff --git a/products/experiments/backend/test/test_experiment_saved_metric_service.py b/products/experiments/backend/test/test_experiment_saved_metric_service.pyindex 272661eb1dbb..8b17f31edb1a 100644--- a/products/experiments/backend/test/test_experiment_saved_metric_service.py+++ b/products/experiments/backend/test/test_experiment_saved_metric_service.py@@ -22,8 +22,10 @@ _WAREHOUSE_NATIVE_MEAN: dict[str, object] = {"source": {"kind": "ExperimentWarehouseNativeNode","connection_id": "00000000-0000-0000-0000-000000000000",- "query": "SELECT user_id AS entity_id, paid_at AS timestamp, amount AS value FROM payments",+ "query": "SELECT user_id AS entity_id, paid_at AS timestamp, amount FROM payments",+ "unit": {"unit_type": "customer", "id_namespace": "billing_customer_id"},"math": "sum",+ "math_property": "amount",},}diff --git a/products/experiments/backend/test/test_experiment_service.py b/products/experiments/backend/test/test_experiment_service.pyindex 04691bf9935f..680c0ea1f366 100644--- a/products/experiments/backend/test/test_experiment_service.py+++ b/products/experiments/backend/test/test_experiment_service.py@@ -884,6 +884,7 @@ class TestExperimentService(APIBaseTest):"kind": "ExperimentWarehouseNativeExposureConfig","connection_id": "00000000-0000-0000-0000-000000000000","query": "SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ "unit": {"unit_type": "customer", "id_namespace": "billing_customer_id"},}},"exposure_criteria.exposure_config: warehouse-native exposures are not supported yet",@@ -895,6 +896,7 @@ class TestExperimentService(APIBaseTest):"kind": "ExperimentWarehouseNativeExposureConfig","connection_id": "00000000-0000-0000-0000-000000000000","query": "SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ "unit": {"unit_type": "customer", "id_namespace": "billing_customer_id"},}},"exposure_criteria.activation_config.kind must be one of "@@ -905,6 +907,17 @@ class TestExperimentService(APIBaseTest):{"exposure_config": {"kind": "ExperimentWarehouseNativeExposureConfig", "connection_id": "c"}},"Invalid exposure_criteria.exposure_config (kind='ExperimentWarehouseNativeExposureConfig')",),+ (+ "exposure_config_warehouse_native_missing_unit",+ {+ "exposure_config": {+ "kind": "ExperimentWarehouseNativeExposureConfig",+ "connection_id": "c",+ "query": "SELECT user_id AS entity_id, variant, exposed_at AS timestamp FROM exposures",+ }+ },+ "Invalid exposure_criteria.exposure_config (kind='ExperimentWarehouseNativeExposureConfig')",+ ),("exposure_config_event_kind_missing_event",{"exposure_config": {"kind": "ExperimentEventExposureConfig", "properties": []}},diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.tsindex 61e69481a6e4..678c92212da6 100644--- a/products/experiments/frontend/generated/api.schemas.ts+++ b/products/experiments/frontend/generated/api.schemas.ts@@ -1868,6 +1868,13 @@ export const ExperimentWarehouseNativeMathTypeApi = {Sum: 'sum',} as const+export interface ExperimentWarehouseNativeUnitBindingApi {+ /** Which ids represent that unit, such as `billing_customer_id`. */+ id_namespace: string+ /** What was randomized, as a stable project-scoped label such as `customer` or `account`. */+ unit_type: string+}+export type ExperimentWarehouseNativeNodeApiResponse = { [key: string]: unknown } | nullexport interface ExperimentWarehouseNativeNodeApi {@@ -1882,6 +1889,7 @@ export interface ExperimentWarehouseNativeNodeApi {/** Read-only SQL in the warehouse's dialect, returning one row per outcome with `entity_id` and `timestamp` columns plus any numeric columns a metric can measure. */query: stringresponse?: ExperimentWarehouseNativeNodeApiResponse+ unit: ExperimentWarehouseNativeUnitBindingApi/** version of the node, used for schema migrations */version?: number | null}diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex 2005a05893fc..0aa073fca99f 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -5462,6 +5462,13 @@ export interface ExperimentEventExposureConfigApi {version?: number | null}+export interface ExperimentWarehouseNativeUnitBindingApi {+ /** Which ids represent that unit, such as `billing_customer_id`. */+ id_namespace: string+ /** What was randomized, as a stable project-scoped label such as `customer` or `account`. */+ unit_type: string+}+export type ExperimentWarehouseNativeExposureConfigApiResponse = { [key: string]: unknown } | nullexport interface ExperimentWarehouseNativeExposureConfigApi {@@ -5471,6 +5478,7 @@ export interface ExperimentWarehouseNativeExposureConfigApi {/** Read-only SQL in the warehouse's dialect, returning one row per exposure with `entity_id`, `variant` and `timestamp` columns. PostHog keeps the first exposure per entity and applies the experiment's date range and multiple-variant handling. */query: stringresponse?: ExperimentWarehouseNativeExposureConfigApiResponse+ unit: ExperimentWarehouseNativeUnitBindingApi/** version of the node, used for schema migrations */version?: number | null}@@ -5601,6 +5609,7 @@ export interface ExperimentWarehouseNativeNodeApi {/** Read-only SQL in the warehouse's dialect, returning one row per outcome with `entity_id` and `timestamp` columns plus any numeric columns a metric can measure. */query: stringresponse?: ExperimentWarehouseNativeNodeApiResponse+ unit: ExperimentWarehouseNativeUnitBindingApi/** version of the node, used for schema migrations */version?: number | null}diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 061fc1d7f954..e04119629068 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -7615,6 +7615,13 @@ export namespace Schemas {version?: number | null;}+ export interface ExperimentWarehouseNativeUnitBinding {+ /** Which ids represent that unit, such as `billing_customer_id`. */+ id_namespace: string;+ /** What was randomized, as a stable project-scoped label such as `customer` or `account`. */+ unit_type: string;+ }+export type ExperimentWarehouseNativeExposureConfigResponse = { [key: string]: unknown } | null;export interface ExperimentWarehouseNativeExposureConfig {@@ -7624,6 +7631,7 @@ export namespace Schemas {/** Read-only SQL in the warehouse's dialect, returning one row per exposure with `entity_id`, `variant` and `timestamp` columns. PostHog keeps the first exposure per entity and applies the experiment's date range and multiple-variant handling. */query: string;response?: ExperimentWarehouseNativeExposureConfigResponse;+ unit: ExperimentWarehouseNativeUnitBinding;/** version of the node, used for schema migrations */version?: number | null;}@@ -7700,6 +7708,7 @@ export namespace Schemas {/** Read-only SQL in the warehouse's dialect, returning one row per outcome with `entity_id` and `timestamp` columns plus any numeric columns a metric can measure. */query: string;response?: ExperimentWarehouseNativeNodeResponse;+ unit: ExperimentWarehouseNativeUnitBinding;/** version of the node, used for schema migrations */version?: number | null;}