: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(data-warehouse): typed validate response with match-rate stats (#75085)
Thiago Salvatore17ac1b573d8d
diff --git a/products/data_warehouse/backend/presentation/views/view_link.py b/products/data_warehouse/backend/presentation/views/view_link.pyindex 61b5f3489008..9e6ab09e952d 100644--- a/products/data_warehouse/backend/presentation/views/view_link.py+++ b/products/data_warehouse/backend/presentation/views/view_link.py@@ -1,9 +1,11 @@from typing import Optional, castfrom clickhouse_driver.errors import ServerException+from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_fieldfrom rest_framework import filters, response, serializers, status, viewsetsfrom posthog.hogql import ast+from posthog.hogql.constants import HogQLGlobalSettingsfrom posthog.hogql.context import HogQLContextfrom posthog.hogql.database.database import Databasefrom posthog.hogql.database.lazy_join_tags import DATA_WAREHOUSE@@ -20,11 +22,21 @@ from posthog.api.utils import actionfrom posthog.clickhouse.query_tagging import Feature, Product, tag_queriesfrom posthog.errors import look_up_clickhouse_error_code_metafrom posthog.exceptions_capture import capture_exception+from posthog.models.team import Teamfrom posthog.models.user import Userfrom posthog.rbac.access_control_api_mixin import AccessControlViewSetMixinfrom products.data_tools.backend.facade.models import DataWarehouseJoin+MATCH_RATE_SAMPLE_SIZE = 10_000+PREVIEW_SCAN_ROWS = 1000+PREVIEW_DISTINCT_PAIRS = 5+# The match-rate stats query tests each sampled source key against the joining table's key column,+# which reads that column in full. Cap its execution so this best-effort scan can't tie up warehouse+# query capacity; over-limit runs raise and fall back to null stats rather than sampling the joining+# side, which would silently corrupt the match rate.+MATCH_RATE_MAX_EXECUTION_TIME = 30+class ViewLinkValidationMixin:def _database(self, team_id: int) -> Database:@@ -106,6 +118,17 @@ class ViewLinkSerializer(serializers.ModelSerializer, ViewLinkValidationMixin):"configuration",]read_only_fields = ["id", "created_by", "created_at"]+ extra_kwargs = {+ "deleted": {"help_text": "Whether this join has been soft-deleted."},+ "source_table_name": {"help_text": "Name of the table the join starts from, for example events."},+ "source_table_key": {"help_text": "Column or HogQL expression on the source table used as the join key."},+ "joining_table_name": {"help_text": "Name of the table or view being joined onto the source table."},+ "joining_table_key": {"help_text": "Column or HogQL expression on the joining table used as the join key."},+ "field_name": {+ "help_text": "Accessor added to the source table to reach the joined rows, for example person in events.person."+ },+ "configuration": {"help_text": "Optional join configuration, for example experiments optimization flags."},+ }def to_representation(self, instance):view = super().to_representation(instance)@@ -139,10 +162,18 @@ class ViewLinkSerializer(serializers.ModelSerializer, ViewLinkValidationMixin):class ViewLinkValidationSerializer(serializers.Serializer, ViewLinkValidationMixin):- joining_table_name = serializers.CharField(max_length=255, required=True)- joining_table_key = serializers.CharField(max_length=255, required=True)- source_table_name = serializers.CharField(max_length=255, required=True)- source_table_key = serializers.CharField(max_length=255, required=True)+ joining_table_name = serializers.CharField(+ max_length=255, required=True, help_text="Name of the table or view being joined onto the source table."+ )+ joining_table_key = serializers.CharField(+ max_length=255, required=True, help_text="Column or HogQL expression on the joining table used as the join key."+ )+ source_table_name = serializers.CharField(+ max_length=255, required=True, help_text="Name of the table the join starts from, for example events."+ )+ source_table_key = serializers.CharField(+ max_length=255, required=True, help_text="Column or HogQL expression on the source table used as the join key."+ )def run_validation(self, data=...):value = super().run_validation(data=data)@@ -162,6 +193,80 @@ class ViewLinkValidationSerializer(serializers.Serializer, ViewLinkValidationMixreturn value+@extend_schema_field({"type": "array", "items": {}})+class JoinSampleRowField(serializers.JSONField):+ pass+++class ViewLinkValidationResponseSerializer(serializers.Serializer):+ # The response key is the existing API contract; the DRF metaclass pops declared+ # fields off the class, so the is_valid() method is not shadowed at runtime.+ is_valid = serializers.BooleanField( # type: ignore[assignment]+ help_text="Whether the join compiled and returned rows when executed against a sample of the source table."+ )+ msg = serializers.CharField(+ allow_null=True,+ help_text="Warning about the validation result, for example when the sampled join returned no rows.",+ )+ hogql = serializers.CharField(allow_null=True, help_text="The HogQL statement used to validate the join.")+ columns = serializers.ListField(child=serializers.CharField(), help_text="Column names for each row in results.")+ results = serializers.ListField(+ child=JoinSampleRowField(),+ help_text=f"Distinct source and joining key pairs from the joined result, at most {PREVIEW_DISTINCT_PAIRS}.",+ )+ total_rows = serializers.IntegerField(+ allow_null=True,+ help_text=f"Number of sampled source rows checked for a join match, at most {MATCH_RATE_SAMPLE_SIZE}. Null when the match-rate query failed.",+ )+ matched_rows = serializers.IntegerField(+ allow_null=True,+ help_text="Number of sampled source rows with at least one match in the joining table. Null when the match-rate query failed.",+ )+ match_rate = serializers.FloatField(+ allow_null=True,+ help_text="matched_rows divided by total_rows, between 0 and 1. Null when the match-rate query failed or no rows were sampled.",+ )+++class ViewLinkValidationErrorSerializer(serializers.Serializer):+ attr = serializers.CharField(allow_null=True, help_text="Request field the error relates to, if any.")+ code = serializers.CharField(help_text="Machine-readable error code, for example QueryError.")+ detail = serializers.CharField(help_text="Why the join failed to validate.")+ type = serializers.CharField(help_text="Error category; always query_error for validation failures.")+ hogql = serializers.CharField(allow_null=True, help_text="The HogQL statement that failed to validate.")+++def _join_match_stats(+ team: Team, database: Database, user: User, validated_data: dict[str, str]+) -> tuple[Optional[int], Optional[int], Optional[float]]:+ try:+ stats_query = parse_select(+ "SELECT count() AS total, countIf(k IN (SELECT {joining_key} FROM {joining_table})) AS matched "+ "FROM (SELECT {source_key} AS k FROM {source_table} LIMIT {sample_size})",+ placeholders={+ "joining_key": parse_expr(validated_data["joining_table_key"]),+ "joining_table": parse_expr(validated_data["joining_table_name"]),+ "source_key": parse_expr(validated_data["source_table_key"]),+ "source_table": parse_expr(validated_data["source_table_name"]),+ "sample_size": ast.Constant(value=MATCH_RATE_SAMPLE_SIZE),+ },+ )+ stats_response = execute_hogql_query(+ query=stats_query,+ team=team,+ context=HogQLContext(database=database, user=user),+ settings=HogQLGlobalSettings(max_execution_time=MATCH_RATE_MAX_EXECUTION_TIME),+ )+ total, matched = stats_response.results[0]+ total_rows, matched_rows = int(total), int(matched)+ except Exception as e:+ # Match stats are best-effort: a failed or too-expensive stats query must never+ # turn a valid join into a validation failure.+ capture_exception(e)+ return None, None, None+ return total_rows, matched_rows, matched_rows / total_rows if total_rows else None++class ViewLinkViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.ModelViewSet):"""Create, Read, Update and Delete View Columns.@@ -194,13 +299,31 @@ class ViewLinkViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsetserializer = self.get_serializer(queryset, many=True)return response.Response(serializer.data)+ @extend_schema(+ request=ViewLinkValidationSerializer,+ responses={+ 200: ViewLinkValidationResponseSerializer,+ 400: OpenApiResponse(+ response=ViewLinkValidationErrorSerializer,+ description="The join does not compile or reference valid fields.",+ ),+ 500: OpenApiResponse(+ response=ViewLinkValidationErrorSerializer,+ description="Validation failed with an internal query error.",+ ),+ },+ )@action(methods=["POST"], detail=False)def validate(self, request, *args, **kwargs):- response_data: dict[str, Optional[bool | str | list]] = {+ response_data: dict[str, Optional[bool | str | list | int | float]] = {"is_valid": False,"msg": None,"hogql": None,+ "columns": [],"results": [],+ "total_rows": None,+ "matched_rows": None,+ "match_rate": None,}status_code = status.HTTP_200_OKserializer = self.get_serializer(data=request.data)@@ -236,11 +359,19 @@ class ViewLinkViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsetoverride_join_type="INNER JOIN",),)+ # DISTINCT over an unbounded scan would keep reading until it finds enough+ # distinct pairs, so the inner LIMIT caps the scan first and DISTINCT dedupes+ # only within that bounded sample.validation_query = parse_select(- "SELECT {to_field} FROM {source_table_name} LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM "+ "(SELECT {source_key} AS source_key, {to_field} AS joining_key "+ "FROM {source_table_name} LIMIT {scan_rows}) LIMIT {distinct_pairs}",placeholders={+ "source_key": parse_expr(source_table_key),"to_field": ast.Field(chain=["validation", *to_field]),"source_table_name": parse_expr(source_table_name),+ "scan_rows": ast.Constant(value=PREVIEW_SCAN_ROWS),+ "distinct_pairs": ast.Constant(value=PREVIEW_DISTINCT_PAIRS),},)@@ -253,10 +384,20 @@ class ViewLinkViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsetcontext=HogQLContext(database=database, user=user),)response_data["hogql"] = query_response.hogql+ response_data["columns"] = query_response.columnsresponse_data["results"] = query_response.resultsresponse_data["is_valid"] = Trueif len(query_response.results) == 0:response_data["msg"] = "Validation query returned no results"+ total_rows, matched_rows, match_rate = _join_match_stats(+ team=self.team,+ database=database,+ user=cast(User, request.user),+ validated_data=serializer.validated_data,+ )+ response_data["total_rows"] = total_rows+ response_data["matched_rows"] = matched_rows+ response_data["match_rate"] = match_rateexcept ServerException as e:capture_exception(e)response_data = {diff --git a/products/data_warehouse/backend/tests/api/test_view_link.py b/products/data_warehouse/backend/tests/api/test_view_link.pyindex b9f38d480c88..aea73ab70f6d 100644--- a/products/data_warehouse/backend/tests/api/test_view_link.py+++ b/products/data_warehouse/backend/tests/api/test_view_link.py@@ -362,6 +362,21 @@ def _mock_execute_hogql_side_effect(*args, **kwargs):)+def _mock_execute_hogql_with_stats_side_effect(*args, **kwargs):+ """Like the plain side effect, but returns numeric counts for the match-rate stats query."""+ query_response = _mock_execute_hogql_side_effect(*args, **kwargs)+ if "countIf" in (query_response.hogql or ""):+ query_response.results = [(10000, 8200)]+ return query_response+++def _mock_execute_hogql_stats_error_side_effect(*args, **kwargs):+ query_response = _mock_execute_hogql_side_effect(*args, **kwargs)+ if "countIf" in (query_response.hogql or ""):+ raise Exception("stats query failed")+ return query_response++class TestViewLinkValidation(APIBaseTest):PATH = "products.data_warehouse.backend.presentation.views.view_link"@@ -439,9 +454,49 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- f"SELECT validation.{payload['joining_table_key']} FROM {payload['source_table_name']} LIMIT 10",+ f"SELECT DISTINCT source_key, joining_key FROM (SELECT {payload['source_table_key']} AS source_key, validation.{payload['joining_table_key']} AS joining_key FROM {payload['source_table_name']} LIMIT 1000) LIMIT 5",)+ @patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_with_stats_side_effect)+ def test_validate_returns_columns_and_match_stats(self, _):+ response = self.client.post(+ f"/api/environments/{self.team.id}/warehouse_view_links/validate/",+ {+ "source_table_name": "events",+ "source_table_key": "uuid",+ "joining_table_name": "persons",+ "joining_table_key": "id",+ },+ )++ self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)+ data = response.json()+ self.assertTrue(data["is_valid"])+ self.assertEqual(data["results"], [["foo", "bar"]])+ self.assertEqual(data["columns"], ["source_key", "joining_key"])+ self.assertEqual(data["total_rows"], 10000)+ self.assertEqual(data["matched_rows"], 8200)+ self.assertEqual(data["match_rate"], 0.82)++ @patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_stats_error_side_effect)+ def test_validate_stats_failure_does_not_break_validation(self, _):+ response = self.client.post(+ f"/api/environments/{self.team.id}/warehouse_view_links/validate/",+ {+ "source_table_name": "events",+ "source_table_key": "uuid",+ "joining_table_name": "persons",+ "joining_table_key": "id",+ },+ )++ self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)+ data = response.json()+ self.assertTrue(data["is_valid"])+ self.assertIsNone(data["total_rows"])+ self.assertIsNone(data["matched_rows"])+ self.assertIsNone(data["match_rate"])+@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)def test_system_table_success(self, _):response = self.client.post(@@ -460,7 +515,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.id FROM groups LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT index AS source_key, validation.id AS joining_key FROM groups LIMIT 1000) LIMIT 5",)@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)@@ -483,7 +538,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.distinct_id FROM `postgres.foo.bar` AS postgres__foo__bar LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT id AS source_key, validation.distinct_id AS joining_key FROM `postgres.foo.bar` AS postgres__foo__bar LIMIT 1000) LIMIT 5",)@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)@@ -504,7 +559,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.id FROM events LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT upper(distinct_id) AS source_key, validation.id AS joining_key FROM events LIMIT 1000) LIMIT 5",)@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)@@ -525,7 +580,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.id FROM events LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT toString(distinct_id) AS source_key, validation.id AS joining_key FROM events LIMIT 1000) LIMIT 5",)@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)@@ -546,7 +601,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.id FROM events LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT toString(ifNull(distinct_id, '')) AS source_key, validation.id AS joining_key FROM events LIMIT 1000) LIMIT 5",)def test_nonexistent_field(self):@@ -564,9 +619,12 @@ class TestViewLinkValidation(APIBaseTest):data = response.json()self.assertEqual(data["attr"], None)self.assertEqual(data["code"], "QueryError")- self.assertEqual(data["detail"], "Field not found: nonexistent_field")+ self.assertEqual(data["detail"], "Unable to resolve field: nonexistent_field")self.assertEqual(data["type"], "query_error")- self.assertEqual(data["hogql"], "SELECT validation.id FROM events LIMIT 10")+ self.assertEqual(+ data["hogql"],+ "SELECT DISTINCT source_key, joining_key FROM (SELECT nonexistent_field AS source_key, validation.id AS joining_key FROM events LIMIT 1000) LIMIT 5",+ )def test_invalid_source_table(self):response = self.client.post(@@ -707,7 +765,10 @@ class TestViewLinkValidation(APIBaseTest):self.assertEqual(data["attr"], None)self.assertEqual(data["code"], "CHQueryErrorIllegalTypeOfArgument")self.assertEqual(data["type"], "query_error")- self.assertEqual(data["hogql"], "SELECT validation.id FROM events LIMIT 10")+ self.assertEqual(+ data["hogql"],+ "SELECT DISTINCT source_key, joining_key FROM (SELECT timestamp AS source_key, validation.id AS joining_key FROM events LIMIT 1000) LIMIT 5",+ )@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)def test_ambiguous_keys(self, _):@@ -730,7 +791,7 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.email FROM `postgres.test.foo` AS postgres__test__foo LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT email AS source_key, validation.email AS joining_key FROM `postgres.test.foo` AS postgres__test__foo LIMIT 1000) LIMIT 5",)@patch(f"{PATH}.execute_hogql_query", side_effect=_mock_execute_hogql_side_effect)@@ -752,5 +813,5 @@ class TestViewLinkValidation(APIBaseTest):self.assertIsNone(data["msg"])self.assertHogQLEqual(data["hogql"],- "SELECT validation.distinct_id FROM `postgres.test.user` AS postgres__test__user LIMIT 10",+ "SELECT DISTINCT source_key, joining_key FROM (SELECT lower(email) AS source_key, validation.distinct_id AS joining_key FROM `postgres.test.user` AS postgres__test__user LIMIT 1000) LIMIT 5",)diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.tsindex e9e9c33b1d4f..ea5989b161ac 100644--- a/products/data_warehouse/frontend/generated/api.schemas.ts+++ b/products/data_warehouse/frontend/generated/api.schemas.ts@@ -3977,20 +3977,39 @@ export interface FileUploadResponseApi {export interface ViewLinkApi {readonly id: string- /** @nullable */+ /**+ * Whether this join has been soft-deleted.+ * @nullable+ */deleted?: boolean | nullreadonly created_by: UserBasicApireadonly created_at: string- /** @maxLength 400 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 400+ */source_table_name: string- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 400+ */source_table_key: string- /** @maxLength 400 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 400+ */joining_table_name: string- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 400+ */joining_table_key: string- /** @maxLength 400 */+ /**+ * Accessor added to the source table to reach the joined rows, for example person in events.person.+ * @maxLength 400+ */field_name: string+ /** Optional join configuration, for example experiments optimization flags. */configuration?: unknown}@@ -4005,34 +4024,118 @@ export interface PaginatedViewLinkListApi {export interface PatchedViewLinkApi {readonly id?: string- /** @nullable */+ /**+ * Whether this join has been soft-deleted.+ * @nullable+ */deleted?: boolean | nullreadonly created_by?: UserBasicApireadonly created_at?: string- /** @maxLength 400 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 400+ */source_table_name?: string- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 400+ */source_table_key?: string- /** @maxLength 400 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 400+ */joining_table_name?: string- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 400+ */joining_table_key?: string- /** @maxLength 400 */+ /**+ * Accessor added to the source table to reach the joined rows, for example person in events.person.+ * @maxLength 400+ */field_name?: string+ /** Optional join configuration, for example experiments optimization flags. */configuration?: unknown}export interface ViewLinkValidationApi {- /** @maxLength 255 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 255+ */joining_table_name: string- /** @maxLength 255 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 255+ */joining_table_key: string- /** @maxLength 255 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 255+ */source_table_name: string- /** @maxLength 255 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 255+ */source_table_key: string}+export interface ViewLinkValidationResponseApi {+ /** Whether the join compiled and returned rows when executed against a sample of the source table. */+ is_valid: boolean+ /**+ * Warning about the validation result, for example when the sampled join returned no rows.+ * @nullable+ */+ msg: string | null+ /**+ * The HogQL statement used to validate the join.+ * @nullable+ */+ hogql: string | null+ /** Column names for each row in results. */+ columns: string[]+ /** Distinct source and joining key pairs from the joined result, at most 5. */+ results: unknown[][]+ /**+ * Number of sampled source rows checked for a join match, at most 10000. Null when the match-rate query failed.+ * @nullable+ */+ total_rows: number | null+ /**+ * Number of sampled source rows with at least one match in the joining table. Null when the match-rate query failed.+ * @nullable+ */+ matched_rows: number | null+ /**+ * matched_rows divided by total_rows, between 0 and 1. Null when the match-rate query failed or no rows were sampled.+ * @nullable+ */+ match_rate: number | null+}++export interface ViewLinkValidationErrorApi {+ /**+ * Request field the error relates to, if any.+ * @nullable+ */+ attr: string | null+ /** Machine-readable error code, for example QueryError. */+ code: string+ /** Why the join failed to validate. */+ detail: string+ /** Error category; always query_error for validation failures. */+ type: string+ /**+ * The HogQL statement that failed to validate.+ * @nullable+ */+ hogql: string | null+}+export type DataModelingJobsListParams = {/*** Number of results to return per page.diff --git a/products/data_warehouse/frontend/generated/api.ts b/products/data_warehouse/frontend/generated/api.tsindex 9889ba1c4b16..e48b60759a1a 100644--- a/products/data_warehouse/frontend/generated/api.ts+++ b/products/data_warehouse/frontend/generated/api.ts@@ -62,6 +62,7 @@ import type {TableApi,ViewLinkApi,ViewLinkValidationApi,+ ViewLinkValidationResponseApi,WarehouseColumnAnnotationApi,WarehouseColumnAnnotationsListParams,WarehouseColumnStatisticsApi,@@ -2289,8 +2290,8 @@ export const warehouseViewLinkValidateCreate = async (projectId: string,viewLinkValidationApi: ViewLinkValidationApi,options?: RequestInit-): Promise<void> => {- return apiMutator<void>(getWarehouseViewLinkValidateCreateUrl(projectId), {+): Promise<ViewLinkValidationResponseApi> => {+ return apiMutator<ViewLinkValidationResponseApi>(getWarehouseViewLinkValidateCreateUrl(projectId), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },@@ -2437,8 +2438,8 @@ export const warehouseViewLinksValidateCreate = async (projectId: string,viewLinkValidationApi: ViewLinkValidationApi,options?: RequestInit-): Promise<void> => {- return apiMutator<void>(getWarehouseViewLinksValidateCreateUrl(projectId), {+): Promise<ViewLinkValidationResponseApi> => {+ return apiMutator<ViewLinkValidationResponseApi>(getWarehouseViewLinksValidateCreateUrl(projectId), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },diff --git a/products/data_warehouse/frontend/generated/api.zod.ts b/products/data_warehouse/frontend/generated/api.zod.tsindex 24144305a625..394b8bd265c0 100644--- a/products/data_warehouse/frontend/generated/api.zod.ts+++ b/products/data_warehouse/frontend/generated/api.zod.ts@@ -1055,13 +1055,31 @@ export const warehouseViewLinkCreateBodyJoiningTableKeyMax = 400export const warehouseViewLinkCreateBodyFieldNameMax = 400export const WarehouseViewLinkCreateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinkCreateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinkCreateBodySourceTableKeyMax),- joining_table_name: zod.string().max(warehouseViewLinkCreateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinkCreateBodyJoiningTableKeyMax),- field_name: zod.string().max(warehouseViewLinkCreateBodyFieldNameMax),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinkCreateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinkCreateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinkCreateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinkCreateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinkCreateBodyFieldNameMax)+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1078,13 +1096,31 @@ export const warehouseViewLinkUpdateBodyJoiningTableKeyMax = 400export const warehouseViewLinkUpdateBodyFieldNameMax = 400export const WarehouseViewLinkUpdateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinkUpdateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinkUpdateBodySourceTableKeyMax),- joining_table_name: zod.string().max(warehouseViewLinkUpdateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinkUpdateBodyJoiningTableKeyMax),- field_name: zod.string().max(warehouseViewLinkUpdateBodyFieldNameMax),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinkUpdateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinkUpdateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinkUpdateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinkUpdateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinkUpdateBodyFieldNameMax)+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1101,13 +1137,36 @@ export const warehouseViewLinkPartialUpdateBodyJoiningTableKeyMax = 400export const warehouseViewLinkPartialUpdateBodyFieldNameMax = 400export const WarehouseViewLinkPartialUpdateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinkPartialUpdateBodySourceTableNameMax).optional(),- source_table_key: zod.string().max(warehouseViewLinkPartialUpdateBodySourceTableKeyMax).optional(),- joining_table_name: zod.string().max(warehouseViewLinkPartialUpdateBodyJoiningTableNameMax).optional(),- joining_table_key: zod.string().max(warehouseViewLinkPartialUpdateBodyJoiningTableKeyMax).optional(),- field_name: zod.string().max(warehouseViewLinkPartialUpdateBodyFieldNameMax).optional(),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinkPartialUpdateBodySourceTableNameMax)+ .optional()+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinkPartialUpdateBodySourceTableKeyMax)+ .optional()+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinkPartialUpdateBodyJoiningTableNameMax)+ .optional()+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinkPartialUpdateBodyJoiningTableKeyMax)+ .optional()+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinkPartialUpdateBodyFieldNameMax)+ .optional()+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1122,10 +1181,22 @@ export const warehouseViewLinkValidateCreateBodySourceTableNameMax = 255export const warehouseViewLinkValidateCreateBodySourceTableKeyMax = 255export const WarehouseViewLinkValidateCreateBody = /* @__PURE__ */ zod.object({- joining_table_name: zod.string().max(warehouseViewLinkValidateCreateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinkValidateCreateBodyJoiningTableKeyMax),- source_table_name: zod.string().max(warehouseViewLinkValidateCreateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinkValidateCreateBodySourceTableKeyMax),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinkValidateCreateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinkValidateCreateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinkValidateCreateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinkValidateCreateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),})/**@@ -1142,13 +1213,31 @@ export const warehouseViewLinksCreateBodyJoiningTableKeyMax = 400export const warehouseViewLinksCreateBodyFieldNameMax = 400export const WarehouseViewLinksCreateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinksCreateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinksCreateBodySourceTableKeyMax),- joining_table_name: zod.string().max(warehouseViewLinksCreateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinksCreateBodyJoiningTableKeyMax),- field_name: zod.string().max(warehouseViewLinksCreateBodyFieldNameMax),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinksCreateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinksCreateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinksCreateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinksCreateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinksCreateBodyFieldNameMax)+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1165,13 +1254,31 @@ export const warehouseViewLinksUpdateBodyJoiningTableKeyMax = 400export const warehouseViewLinksUpdateBodyFieldNameMax = 400export const WarehouseViewLinksUpdateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinksUpdateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinksUpdateBodySourceTableKeyMax),- joining_table_name: zod.string().max(warehouseViewLinksUpdateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinksUpdateBodyJoiningTableKeyMax),- field_name: zod.string().max(warehouseViewLinksUpdateBodyFieldNameMax),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinksUpdateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinksUpdateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinksUpdateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinksUpdateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinksUpdateBodyFieldNameMax)+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1188,13 +1295,36 @@ export const warehouseViewLinksPartialUpdateBodyJoiningTableKeyMax = 400export const warehouseViewLinksPartialUpdateBodyFieldNameMax = 400export const WarehouseViewLinksPartialUpdateBody = /* @__PURE__ */ zod.object({- deleted: zod.boolean().nullish(),- source_table_name: zod.string().max(warehouseViewLinksPartialUpdateBodySourceTableNameMax).optional(),- source_table_key: zod.string().max(warehouseViewLinksPartialUpdateBodySourceTableKeyMax).optional(),- joining_table_name: zod.string().max(warehouseViewLinksPartialUpdateBodyJoiningTableNameMax).optional(),- joining_table_key: zod.string().max(warehouseViewLinksPartialUpdateBodyJoiningTableKeyMax).optional(),- field_name: zod.string().max(warehouseViewLinksPartialUpdateBodyFieldNameMax).optional(),- configuration: zod.unknown().optional(),+ deleted: zod.boolean().nullish().describe('Whether this join has been soft-deleted.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinksPartialUpdateBodySourceTableNameMax)+ .optional()+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinksPartialUpdateBodySourceTableKeyMax)+ .optional()+ .describe('Column or HogQL expression on the source table used as the join key.'),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinksPartialUpdateBodyJoiningTableNameMax)+ .optional()+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinksPartialUpdateBodyJoiningTableKeyMax)+ .optional()+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ field_name: zod+ .string()+ .max(warehouseViewLinksPartialUpdateBodyFieldNameMax)+ .optional()+ .describe('Accessor added to the source table to reach the joined rows, for example person in events.person.'),+ configuration: zod+ .unknown()+ .optional()+ .describe('Optional join configuration, for example experiments optimization flags.'),})/**@@ -1209,8 +1339,20 @@ export const warehouseViewLinksValidateCreateBodySourceTableNameMax = 255export const warehouseViewLinksValidateCreateBodySourceTableKeyMax = 255export const WarehouseViewLinksValidateCreateBody = /* @__PURE__ */ zod.object({- joining_table_name: zod.string().max(warehouseViewLinksValidateCreateBodyJoiningTableNameMax),- joining_table_key: zod.string().max(warehouseViewLinksValidateCreateBodyJoiningTableKeyMax),- source_table_name: zod.string().max(warehouseViewLinksValidateCreateBodySourceTableNameMax),- source_table_key: zod.string().max(warehouseViewLinksValidateCreateBodySourceTableKeyMax),+ joining_table_name: zod+ .string()+ .max(warehouseViewLinksValidateCreateBodyJoiningTableNameMax)+ .describe('Name of the table or view being joined onto the source table.'),+ joining_table_key: zod+ .string()+ .max(warehouseViewLinksValidateCreateBodyJoiningTableKeyMax)+ .describe('Column or HogQL expression on the joining table used as the join key.'),+ source_table_name: zod+ .string()+ .max(warehouseViewLinksValidateCreateBodySourceTableNameMax)+ .describe('Name of the table the join starts from, for example events.'),+ source_table_key: zod+ .string()+ .max(warehouseViewLinksValidateCreateBodySourceTableKeyMax)+ .describe('Column or HogQL expression on the source table used as the join key.'),})diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 1ff666b82672..4ec2be8214a6 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -48244,20 +48244,39 @@ export namespace Schemas {export interface ViewLink {readonly id: string;- /** @nullable */+ /**+ * Whether this join has been soft-deleted.+ * @nullable+ */deleted?: boolean | null;readonly created_by: UserBasic;readonly created_at: string;- /** @maxLength 400 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 400+ */source_table_name: string;- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 400+ */source_table_key: string;- /** @maxLength 400 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 400+ */joining_table_name: string;- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 400+ */joining_table_key: string;- /** @maxLength 400 */+ /**+ * Accessor added to the source table to reach the joined rows, for example person in events.person.+ * @maxLength 400+ */field_name: string;+ /** Optional join configuration, for example experiments optimization flags. */configuration?: unknown;}@@ -56168,20 +56187,39 @@ export namespace Schemas {export interface PatchedViewLink {readonly id?: string;- /** @nullable */+ /**+ * Whether this join has been soft-deleted.+ * @nullable+ */deleted?: boolean | null;readonly created_by?: UserBasic;readonly created_at?: string;- /** @maxLength 400 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 400+ */source_table_name?: string;- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 400+ */source_table_key?: string;- /** @maxLength 400 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 400+ */joining_table_name?: string;- /** @maxLength 400 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 400+ */joining_table_key?: string;- /** @maxLength 400 */+ /**+ * Accessor added to the source table to reach the joined rows, for example person in events.person.+ * @maxLength 400+ */field_name?: string;+ /** Optional join configuration, for example experiments optimization flags. */configuration?: unknown;}@@ -72365,16 +72403,81 @@ export namespace Schemas {}export interface ViewLinkValidation {- /** @maxLength 255 */+ /**+ * Name of the table or view being joined onto the source table.+ * @maxLength 255+ */joining_table_name: string;- /** @maxLength 255 */+ /**+ * Column or HogQL expression on the joining table used as the join key.+ * @maxLength 255+ */joining_table_key: string;- /** @maxLength 255 */+ /**+ * Name of the table the join starts from, for example events.+ * @maxLength 255+ */source_table_name: string;- /** @maxLength 255 */+ /**+ * Column or HogQL expression on the source table used as the join key.+ * @maxLength 255+ */source_table_key: string;}+ export interface ViewLinkValidationError {+ /**+ * Request field the error relates to, if any.+ * @nullable+ */+ attr: string | null;+ /** Machine-readable error code, for example QueryError. */+ code: string;+ /** Why the join failed to validate. */+ detail: string;+ /** Error category; always query_error for validation failures. */+ type: string;+ /**+ * The HogQL statement that failed to validate.+ * @nullable+ */+ hogql: string | null;+ }++ export interface ViewLinkValidationResponse {+ /** Whether the join compiled and returned rows when executed against a sample of the source table. */+ is_valid: boolean;+ /**+ * Warning about the validation result, for example when the sampled join returned no rows.+ * @nullable+ */+ msg: string | null;+ /**+ * The HogQL statement used to validate the join.+ * @nullable+ */+ hogql: string | null;+ /** Column names for each row in results. */+ columns: string[];+ /** Distinct source and joining key pairs from the joined result, at most 5. */+ results: unknown[][];+ /**+ * Number of sampled source rows checked for a join match, at most 10000. Null when the match-rate query failed.+ * @nullable+ */+ total_rows: number | null;+ /**+ * Number of sampled source rows with at least one match in the joining table. Null when the match-rate query failed.+ * @nullable+ */+ matched_rows: number | null;+ /**+ * matched_rows divided by total_rows, between 0 and 1. Null when the match-rate query failed or no rows were sampled.+ * @nullable+ */+ match_rate: number | null;+ }+/*** Full run detail: the list fields plus the synthesized report and the recordings it summarized.*/