tidyverse / dbplyr

Database (DBI) backend for dplyr
https://dbplyr.tidyverse.org
Other
469 stars 169 forks source link

`sql` in `in_catalog` breaks with `filter` #1485

Open carlganz opened 3 months ago

carlganz commented 3 months ago

I am having trouble generating reproducible example because I don't know how to mock catalogs and table valued functions but effectively issue is:

library(dbplyr)
library(dplyr)

con <- simulate_odbc()

# this works fine, we have select * with no prefix; datawarehouse and dbo will have quotes in query but MyTableValuedFunction won't
tbl(con, in_catalog("Datawarehouse", "DBO", sql("MyTableValuedFunction(Param1, Param2)"))) %>%
  show_query

# now that I have filter it will try to prefix * like "MyTableValuedFunction(Param1, Param2)".*  with quotes and it won't work it needs an alias
tbl(con, in_catalog("Datawarehouse", "DBO", sql("MyTableValuedFunction(Param1, Param2)"))) %>%
  filter(getdate() > 1) %>%
  show_query

This worked before 2.4.0 so it appears fixes in 2.5.0 haven't covered everything.

mgirlich commented 3 months ago

Hmm, we should probably force an alias when the table name is sql. I'll have a look.