Skip to content

Conversation

@krlmlr
Copy link
Collaborator

@krlmlr krlmlr commented Aug 1, 2025

Fixes recursive flattening failure when columns serve as both primary and foreign keys.

This PR resolves the issue described in #2234 where dm_flatten_to_tbl(.recursive = TRUE) would fail with "Join columns in x must be present in the data" when a column served dual roles.

Generated with Claude Code

…2234)

When a column serves as both a primary key and foreign key, recursive
flattening failed because join column names weren''t tracked properly
across multiple join operations.

Root cause: After joining tables where a column (e.g., ''c'') served as
both PK and FK, that column would disappear from the result set, but
subsequent joins would still try to reference it.

Solution: Implemented column name tracking in dm_flatten_to_tbl_impl()
that maps consumed join columns to their surviving counterparts in the
accumulated result set.

- Added join_column_tracker to track column name changes during joins
- Updated by specifications for subsequent joins based on tracking
- Handles both single-column and multi-column joins correctly
- Added comprehensive regression tests covering various scenarios
- Tested across all database backends (df, postgres, maria, duckdb)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Kirill Müller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants