Skip to content

fix(react): deduplicate filters for multi-occurrence table nodes#2

Merged
cooker-code merged 1 commit into
masterfrom
fix/duplicate-filters-multi-occurrence
May 18, 2026
Merged

fix(react): deduplicate filters for multi-occurrence table nodes#2
cooker-code merged 1 commit into
masterfrom
fix/duplicate-filters-multi-occurrence

Conversation

@cooker-code
Copy link
Copy Markdown
Owner

Summary

Ref: pondpilot/flowscope#44

When the same table is referenced multiple times within a single SQL statement (e.g., two subqueries over the same table inside one CTE), the Rust core appends each occurrence's WHERE predicates to node.filters, producing N identical filter sets. The FILTERS section of TableNode displayed all duplicates.

Before fix: dwd_eng_device_active_da (referenced twice) showed 8 filter predicates
After fix: Shows 4 unique predicates

Changes

File Change
graphBuilders.ts Add deduplicateFilters() helper; apply to node.filters before TableNodeData
graphBuilder.worker.ts Same deduplication in worker path
nodeOccurrences.ts Store per-occurrence filters in metadata.occurrenceFilters[][] for cross-statement cases
TableNode.tsx Subscribe to focusedOccurrenceIndex; use occurrenceFilters[index] when available
types.ts TableNodeData gains occurrenceFilters?: FilterPredicate[][]

Test plan

  • Load SQL with same table in two subqueries within one CTE
  • Confirm OccurrenceCycler shows ◀ 1/2 ▶
  • Confirm FILTERS shows 4 unique predicates (not 8)
  • Confirm single-occurrence nodes unaffected

Made with Cursor

When the same table is referenced multiple times within a single SQL
statement (e.g., self-join or two subqueries over the same table), the
Rust core appends each occurrence's WHERE predicates to node.filters,
producing N identical sets for N references. This caused the FILTERS
section of a TableNode to display the same predicates twice (or more).

Root cause: node.filters already arrives from the backend with duplicates
baked in (visible in metadata.statementFilters). The frontend had no
deduplication before rendering.

Fixes:
- Add deduplicateFilters() helper in graphBuilders.ts and
  graphBuilder.worker.ts that collapses node.filters to unique
  expressions (preserving first occurrence order) before the data
  reaches TableNodeData.
- Add per-occurrence filter storage (occurrenceFilters[][]) in
  mergeNodesForNavigation so that cross-statement multi-occurrence cases
  can also display per-occurrence filters in the future.
- TableNode subscribes to focusedOccurrenceIndex and uses
  occurrenceFilters[index] when available (cross-statement path), falling
  back to the now-deduplicated flat filters for the same-statement path.
- TableNodeData gains occurrenceFilters?: FilterPredicate[][] for the
  per-occurrence display path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cooker-code cooker-code merged commit 8fdd032 into master May 18, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants