Skip to content

Filtering with external vector and max gives lazy_select_query error #1048

@chwpearse

Description

@chwpearse

Filtering a dbplyr table with col %in% ext_vector & col == max(col) causes an error. This works in version 2.1.1, but not 2.2.0

Either of these statements by themselves, or split into seperate filter functions run correctly.

library(tidyverse)
library(dbplyr)
#> Attaching package: 'dbplyr'
#> The following objects are masked from 'package:dplyr':
#> 
#>     ident, sql

lf <- lazy_frame(x = 1L)

to_filter <- c('a', 'b')

lf %>% filter(x == max(x, na.rm = T))
#> <SQL>
#> SELECT `x`
#> FROM (
#>   SELECT *, MAX(`x`) OVER () AS `q01`
#>   FROM `df`
#> ) `q01`
#> WHERE (`x` = `q01`)
lf %>% filter(x %in% to_filter)
#> <SQL>
#> SELECT *
#> FROM `df`
#> WHERE (`x` IN ('a', 'b'))
lf %>% filter(x == max(x, na.rm = T)) %>% filter(x %in% to_filter)
#> <SQL>
#> SELECT *
#> FROM (
#>   SELECT `x`
#>   FROM (
#>     SELECT *, MAX(`x`) OVER () AS `q01`
#>     FROM `df`
#>   ) `q01`
#>   WHERE (`x` = `q01`)
#> ) `q02`
#> WHERE (`x` IN ('a', 'b'))

lf %>% filter(x == max(x, na.rm = T), x %in% to_filter)
#> Error in lazy_select_query(x = mutated$lazy_query, last_op = "filter", : is_lazy_sql_part(where) is not TRUE

Created on 2022-11-18 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviordplyr verbs 🤖Translation of dplyr verbs to SQL

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions