: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
fix(data-warehouse): search warehouse tables by all queryable names (#60424)
George Munyoro65e7201b7088
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 7bf8df129699..73e6477172f2 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -14650,6 +14650,13 @@"schema": {"$ref": "#/definitions/DatabaseSchemaSchema"},+ "search_aliases": {+ "description": "Alternate names the table is queryable by (e.g. the flat underscore form), in addition to `name`.",+ "items": {+ "type": "string"+ },+ "type": "array"+ },"source": {"$ref": "#/definitions/DatabaseSchemaSource"},diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex a6214a981bad..c74a3140a1df 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -4331,6 +4331,8 @@ export interface DatabaseSchemaDataWarehouseTable extends DatabaseSchemaTableComurl_pattern: stringschema?: DatabaseSchemaSchemasource?: DatabaseSchemaSource+ /** Alternate names the table is queryable by (e.g. the flat underscore form), in addition to `name`. */+ search_aliases?: string[]}export interface DatabaseSchemaBatchExportTable extends DatabaseSchemaTableCommon {diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsxindex 2b632afe385e..b5adfa245b81 100644--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx@@ -104,7 +104,11 @@ const getSavedQuerySchemaTable = (}const FUSE_OPTIONS: IFuseOptions<any> = {- keys: [{ name: 'name', weight: 2 }],+ keys: [+ { name: 'name', weight: 2 },+ // Warehouse tables are queryable by alternate names (e.g. the flat underscore form) too+ { name: 'search_aliases', weight: 1 },+ ],ignoreLocation: true,includeMatches: true,}diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.pyindex 162e54a27018..43a3054a95e5 100644--- a/posthog/hogql/database/database.py+++ b/posthog/hogql/database/database.py@@ -782,10 +782,15 @@ class Database(BaseModel):)fields_dict = {field.name: field for field in fields}+ # The table is also queryable by its raw underscore name, which is registered+ # separately from the dotted `table_key`. Surface it so search matches either form.+ search_aliases = [warehouse_table.name] if warehouse_table.name != table_key else None+tables[table_key] = DatabaseSchemaDataWarehouseTable(fields=fields_dict,id=str(warehouse_table.id),name=table_key,+ search_aliases=search_aliases,format=warehouse_table.format,url_pattern=warehouse_table.url_pattern,schema=schema,diff --git a/posthog/hogql/database/test/test_database.py b/posthog/hogql/database/test/test_database.pyindex 73971500f3ff..3ad08cf4ee81 100644--- a/posthog/hogql/database/test/test_database.py+++ b/posthog/hogql/database/test/test_database.py@@ -359,6 +359,9 @@ class TestDatabase(BaseTest, QueryMatchingTest):assert table is not Noneassert len(table.fields.keys()) == 1+ # The table is also queryable by its raw underscore name, so it must be surfaced for search+ assert table.search_aliases == ["stripe_table_1"]+assert table.source is not Noneassert table.source.id == str(source.id)assert table.source.status == "Completed"diff --git a/posthog/schema.py b/posthog/schema.pyindex cf8e05015726..a4400dda2846 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -15414,6 +15414,12 @@ class DatabaseSchemaDataWarehouseTable(BaseModel):name: strrow_count: float | None = Noneschema_: DatabaseSchemaSchema | None = Field(default=None, alias="schema")+ search_aliases: list[str] | None = Field(+ default=None,+ description=(+ "Alternate names the table is queryable by (e.g. the flat underscore form), in addition to `name`."+ ),+ )source: DatabaseSchemaSource | None = Nonetype: Literal["data_warehouse"] = "data_warehouse"url_pattern: strdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 21d664aeedaf..3b994a4c5ef1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -12310,6 +12310,8 @@ export namespace Schemas {name: string;row_count?: number | null;schema?: DatabaseSchemaSchema | null;+ /** Alternate names the table is queryable by (e.g. the flat underscore form), in addition to `name`. */+ search_aliases?: string[] | null;source?: DatabaseSchemaSource | null;type?: 'data_warehouse';url_pattern: string;