: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): use fuzzy search in the modeling DAG (#91117)
posthog[bot]b81ad22b1899
diff --git a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.ts b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.tsindex 7461c82fadb4..c55988a2155e 100644--- a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.test.ts@@ -136,4 +136,126 @@ describe('dataModelingLogic', () => {const [source, target] = logic.values.enrichedNodesexpect(Math.abs(target.position.x - source.position.x)).toBeLessThan(1000)})++ // A typo must still find the model, matching the SQL editor sidebar. A revert to String.includes()+ // would drop these hits and make a failed search look like a missing model.+ it('fuzzy-matches the list search so a near-miss term still finds the node', async () => {+ useMocks({+ get: {+ '/api/environments/:team_id/data_modeling_nodes/': {+ results: [+ {+ id: 'n1',+ name: 'customer_orders',+ type: 'view',+ dag: 'dag-123',+ created_at: '2024-01-01T00:00:00Z',+ updated_at: '2024-01-01T00:00:00Z',+ upstream_count: 0,+ downstream_count: 0,+ },+ ],+ },+ },+ })+ logic = dataModelingLogic()+ logic.mount()+ await expectLogic(logic).toDispatchActions(['loadDataModelingNodesSuccess'])++ logic.actions.setSearchTerm('custmer')+ expect(logic.values.filteredNodes.map((n) => n.name)).toEqual(['customer_orders'])+ })++ it('fuzzy-matches the graph search so a near-miss term still highlights the node', async () => {+ logic = dataModelingLogic()+ logic.mount()+ await expectLogic(logic)+ .toDispatchActions(['loadDataModelingNodesSuccess', 'loadDataModelingEdgesSuccess'])+ .toFinishAllListeners()++ const nodes: Node[] = [+ {+ id: 'match',+ type: 'model',+ position: { x: 0, y: 0 },+ data: { id: 'match', name: 'customer_orders', type: 'view', upstreamCount: 0, downstreamCount: 0 },+ },+ {+ id: 'other',+ type: 'model',+ position: { x: 100, y: 0 },+ data: { id: 'other', name: 'sessions', type: 'view', upstreamCount: 0, downstreamCount: 0 },+ },+ ]+ logic.actions.setNodesRaw(nodes)+ logic.actions.setDebouncedSearchTerm('custmer')+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.searchMatchedNodeIds).toEqual(new Set(['match']))+ })++ // A typo combined with the +/- lineage syntax must still resolve the start node, matching the+ // plain graph search. Reverting the start-node lookup to exact/substring returns an empty set,+ // which blanks the canvas while the list view still finds the model.+ it.each([+ ['+custmer', ['upstream_view', 'customer_orders']],+ ['custmer+', ['customer_orders', 'downstream_view']],+ ['+custmer+', ['upstream_view', 'customer_orders', 'downstream_view']],+ ])('fuzzy-matches a near-miss lineage term (%s) so the graph is not left blank', async (term, expectedIds) => {+ logic = dataModelingLogic()+ logic.mount()+ await expectLogic(logic)+ .toDispatchActions(['loadDataModelingNodesSuccess', 'loadDataModelingEdgesSuccess'])+ .toFinishAllListeners()++ const nodes: Node[] = [+ {+ id: 'upstream_view',+ type: 'model',+ position: { x: 0, y: 0 },+ data: {+ id: 'upstream_view',+ name: 'upstream_view',+ type: 'view',+ upstreamCount: 0,+ downstreamCount: 1,+ },+ },+ {+ id: 'customer_orders',+ type: 'model',+ position: { x: 100, y: 0 },+ data: {+ id: 'customer_orders',+ name: 'customer_orders',+ type: 'view',+ upstreamCount: 1,+ downstreamCount: 1,+ },+ },+ {+ id: 'downstream_view',+ type: 'model',+ position: { x: 200, y: 0 },+ data: {+ id: 'downstream_view',+ name: 'downstream_view',+ type: 'view',+ upstreamCount: 1,+ downstreamCount: 0,+ },+ },+ ]+ const edges: Edge[] = [+ { id: 'upstream_view->customer_orders', source: 'upstream_view', target: 'customer_orders' },+ { id: 'customer_orders->downstream_view', source: 'customer_orders', target: 'downstream_view' },+ ]++ logic.actions.setNodesRaw(nodes)+ logic.actions.setEdges(edges)+ logic.actions.setDebouncedSearchTerm(term)+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.searchMatchedNodeIds).toEqual(new Set(expectedIds))+ })})diff --git a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.tsindex b056bece2d43..756d743f3f58 100644--- a/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts+++ b/frontend/src/scenes/data-warehouse/scene/dataModelingLogic.ts@@ -15,6 +15,7 @@ import { urlToAction } from 'kea-router'import type { RefObject } from 'react'import api from 'lib/api'+import { createFuse } from 'lib/utils/fuseSearch'import { urls } from 'scenes/urls'import {@@ -33,6 +34,11 @@ import { Edge, ElkDirection, Node, NodeHandle, SearchMode, ViewMode } from './moconst POLL_INTERVAL_MS = 5000const MIN_RUNNING_DURATION_MS = 2000+// Match the SQL editor sidebar's fuzzy search (queryDatabaseLogic) so the same term gives the same+// answer in both places. ignoreLocation lets a match land anywhere in the name.+const graphNodeFuse = createFuse<Node>([], { keys: ['data.name'], ignoreLocation: true })+const modelingNodeFuse = createFuse<DataModelingNode>([], { keys: ['name'], ignoreLocation: true })+const nodeStartTimes: Map<string, number> = new Map()const getEdgeId = (from: string, to: string): string => `${from}->${to}`@@ -824,11 +830,11 @@ export const dataModelingLogic = kea<dataModelingLogicType>([const { upstream, downstream } = buildAdjacencyMaps(edges)return (baseName: string, mode: 'upstream' | 'downstream' | 'all'): Set<string> => {- const lowerBaseName = baseName.toLowerCase()- let startNode = nodes.find((n) => n.data.name.toLowerCase() === lowerBaseName)- if (!startNode) {- startNode = nodes.find((n) => n.data.name.toLowerCase().includes(lowerBaseName))- }+ // Resolve the lineage start node through the same fuzzy instance the plain search+ // uses, so a near-miss term like `custmer+` finds `customer_orders` here too.+ // Exact/substring matching left the graph blank while the list view found the model.+ graphNodeFuse.setCollection(nodes)+ const startNode = graphNodeFuse.search(baseName)[0]?.itemif (!startNode) {return new Set()}@@ -870,8 +876,11 @@ export const dataModelingLogic = kea<dataModelingLogicType>([if (parsedSearch.mode !== 'search') {return highlightedNodeIds(parsedSearch.baseName, parsedSearch.mode)}- const lowerBaseName = parsedSearch.baseName.toLowerCase()- return new Set(nodes.filter((n) => n.data.name.toLowerCase().includes(lowerBaseName)).map((n) => n.id))+ if (!parsedSearch.baseName) {+ return null+ }+ graphNodeFuse.setCollection(nodes)+ return new Set(graphNodeFuse.search(parsedSearch.baseName).map((r) => r.item.id))},],filteredNodes: [@@ -881,7 +890,11 @@ export const dataModelingLogic = kea<dataModelingLogicType>([return dataModelingNodes}const { baseName } = parseSearchTerm(searchTerm)- return dataModelingNodes.filter((n) => n.name.toLowerCase().includes(baseName.toLowerCase()))+ if (!baseName) {+ return dataModelingNodes+ }+ modelingNodeFuse.setCollection(dataModelingNodes)+ return modelingNodeFuse.search(baseName).map((r) => r.item)},],selectedDag: [