Skip to content

Ensure join/semi_join/set ops generate minimal SQL #236

@hadley

Description

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

lf <- lazy_frame(x = 1, y = 2)

union(lf, lf)
#> <SQL>
#> (SELECT *
#> FROM `df`)
#> UNION
#> (SELECT *
#> FROM `df`)
left_join(lf, lf)
#> Joining, by = c("x", "y")
#> <SQL>
#> SELECT `TBL_LEFT`.`x` AS `x`, `TBL_LEFT`.`y` AS `y`
#>   FROM (SELECT *
#> FROM `df`) `TBL_LEFT`
#>   LEFT JOIN (SELECT *
#> FROM `df`) `TBL_RIGHT`
#>   ON (`TBL_LEFT`.`x` = `TBL_RIGHT`.`x` AND `TBL_LEFT`.`y` = `TBL_RIGHT`.`y`)
anti_join(lf, lf)
#> Joining, by = c("x", "y")
#> <SQL>
#> SELECT * FROM (SELECT *
#> FROM `df`) `TBL_LEFT`
#> 
#> WHERE NOT EXISTS (
#>   SELECT 1 FROM (SELECT *
#> FROM `df`) `TBL_RIGHT`
#>   WHERE (`TBL_LEFT`.`x` = `TBL_RIGHT`.`x` AND `TBL_LEFT`.`y` = `TBL_RIGHT`.`y`)
#> )

Created on 2019-02-06 by the reprex package (v0.2.1.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    dplyr verbs 🤖Translation of dplyr verbs to SQLfeaturea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions