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

Inline filter() in semi/anti_join() #884

Closed
mgirlich opened this issue May 20, 2022 · 0 comments · Fixed by #1306
Closed

Inline filter() in semi/anti_join() #884

mgirlich opened this issue May 20, 2022 · 0 comments · Fixed by #1306
Labels
feature a feature request or enhancement verb trans 🤖 Translation of dplyr verbs to SQL

Comments

@mgirlich
Copy link
Collaborator

library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)

lf <- lazy_frame(x = 1, y = 2, z = 3)
lf2 <- lazy_frame(x = 1, a = 2, b = 3)

semi_join(
  lf,
  lf2 %>% 
    filter(a == 1),
  by = "x"
)

Currently produces

SELECT *
FROM `df` AS `LHS`
WHERE EXISTS (
  SELECT 1 FROM (
    SELECT *
    FROM `df`
    WHERE (`a` = 1.0)
  ) `RHS`
  WHERE (`LHS`.`x` = `RHS`.`x`)
)

But could be

SELECT *
FROM `df` AS `LHS`
WHERE EXISTS (
  SELECT 1 FROM
  FROM `df` AS `RHS`
  WHERE (`RHS`.`a` = 1.0) AND (`LHS`.`x` = `RHS`.`x`)
)
@hadley hadley added feature a feature request or enhancement verb trans 🤖 Translation of dplyr verbs to SQL labels Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement verb trans 🤖 Translation of dplyr verbs to SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants