Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive flattening failure with combined primary and foreign key #2234

Open
nirski opened this issue Sep 25, 2024 · 1 comment
Open

Recursive flattening failure with combined primary and foreign key #2234

nirski opened this issue Sep 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nirski
Copy link

nirski commented Sep 25, 2024

When a column serves as both a primary and foreign key, dm refuses to flatten the model. Below is a minimal example.

mydm <- dm(
    x = tibble(a = 1, b = 2),
    y = tibble(c = 2, d = 3),
    z = tibble(e = 2, f = 4)
    ) %>%
    dm_add_pk(x, a) %>%
    dm_add_pk(y, c) %>%
    dm_add_pk(z, e) %>%
    dm_add_fk(x, b, y) %>%
    dm_add_fk(y, c, z)

Diagram:

mydm %>% dm_draw(view_type = "all")

obraz

Flattening the model

mydm %>% dm_flatten_to_tbl(x, .recursive = TRUE)

Output:

Error in `join()`:
! Join columns in `x` must be present in the data.
✖ Problem with `c`.
Run `rlang::last_trace()` to see where the error occurred.

Expected output:

# A tibble: 1 × 4
      a     b     d     f
  <dbl> <dbl> <dbl> <dbl>
1     1     2     3     4
@krlmlr
Copy link
Collaborator

krlmlr commented Nov 24, 2024

Thanks, confirmed. For some reason, reprex fails to render the code correctly.

library(dm)

mydm <- dm(
  x = tibble(a = 1, b = 2),
  y = tibble(c = 2, d = 3),
  z = tibble(e = 2, f = 4)
) %>%
  dm_add_pk(x, a) %>%
  dm_add_pk(y, c) %>%
  dm_add_pk(z, e) %>%
  dm_add_fk(x, b, y) %>%
  dm_add_fk(y, c, z)

mydm %>%
  dm_draw()

mydm %>%
  dm_flatten_to_tbl(x, .recursive = TRUE)

@krlmlr krlmlr added the bug Something isn't working label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants