Most databases are able to interpret iso-date strings as dates in, e.g., "where" clauses, such as
select * from table where date_column = '2019-01-01'
This is not the case with PrestoDB/AWS Athena, however. Instead, the strings need to be cast as dates first like:
select * from table where date_column = date('2019-01-01'),
select * from table where date_column = date'2019-01-01' or
select * from table where date_column = cast('2019-01-01' as date)
However, when a date variable is used as a parameter id dplyr/dbplyr, is is translated to a iso-date string in the generated sql, so a command such as:
today <- Sys.Date()
tbl(AthenaCon, "table") %>% filter(date_column <= today)
produces and error, as the generated sql does not have the explicit cast to date of the iso-date string. One needs to manually cast the date variable as a date as in
... %>% filter(date_column <= as.Date(today)), but this feels unnecessary, as R knows today is a date already.
A DBI backend for AWS Athena is being developed at https://github.com/DyfanJones/RAthena, and I'm asking for some guidance on how to address this issue there.
My question is: is there a method for overriding the default behavior of dbplyr, where dates are translated to quoted strings and instead have them translated to, e.g., "date'2019-01-01'"?
I'm sorry if this seems like a trivial question, but I'm drawing a blank from reading the database specific source files and packages. All I can come up with is to use assignInNameSpace to replace the escape.Date -method, but this seems pretty brutal.
Thanks for any hints!
Most databases are able to interpret iso-date strings as dates in, e.g., "where" clauses, such as
select * from table where date_column = '2019-01-01'This is not the case with PrestoDB/AWS Athena, however. Instead, the strings need to be cast as dates first like:
select * from table where date_column = date('2019-01-01'),select * from table where date_column = date'2019-01-01'orselect * from table where date_column = cast('2019-01-01' as date)However, when a date variable is used as a parameter id dplyr/dbplyr, is is translated to a iso-date string in the generated sql, so a command such as:
produces and error, as the generated sql does not have the explicit cast to date of the iso-date string. One needs to manually cast the date variable as a date as in
... %>% filter(date_column <= as.Date(today)), but this feels unnecessary, as R knows today is a date already.A DBI backend for AWS Athena is being developed at https://github.com/DyfanJones/RAthena, and I'm asking for some guidance on how to address this issue there.
My question is: is there a method for overriding the default behavior of dbplyr, where dates are translated to quoted strings and instead have them translated to, e.g., "date'2019-01-01'"?
I'm sorry if this seems like a trivial question, but I'm drawing a blank from reading the database specific source files and packages. All I can come up with is to use assignInNameSpace to replace the escape.Date -method, but this seems pretty brutal.
Thanks for any hints!