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

Caching issue #171

Closed
DyfanJones opened this issue Nov 15, 2021 · 2 comments
Closed

Caching issue #171

DyfanJones opened this issue Nov 15, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@DyfanJones
Copy link
Owner

Caching fails when statement is in SQL class type:

library(DBI)

noctua::noctua_options(cache_size = 10)

con = dbConnect(noctua::athena())

df = dbGetQuery(con, "select * from iris")
#> Info: (Data scanned: 3.63 KB)

df = dbGetQuery(con, SQL("select * from iris"))
#> Error in .set_ops_arg_check(x, y, all, .seqn = TRUE): Item 2 of x is 'SQL' but the corresponding item of y is 'character'.

Created on 2021-11-15 by the reprex package (v2.0.1)

This behave also persists when using dplyr lazy evalution method tbl.

Thanks to @ramnathv for identifying this issue in #96 (comment) .

@DyfanJones DyfanJones added the bug Something isn't working label Nov 15, 2021
@DyfanJones DyfanJones self-assigned this Nov 15, 2021
@DyfanJones DyfanJones mentioned this issue Nov 15, 2021
@DyfanJones
Copy link
Owner Author

PR #172 seems to fix issue. @ramnathv can you double check branch cache_issue fixes your initial issue.

remotes::install_github("dyfanjones/noctua", ref="cache_issue")

Working example:

library(DBI)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

noctua::noctua_options(cache_size = 10)

con = dbConnect(noctua::athena())

df = dbGetQuery(con, "select * from iris")
#> Info: (Data scanned: 3.63 KB)

df = dbGetQuery(con, SQL("select * from iris"))
#> Info: (Data scanned: 3.63 KB)

# Check cache
noctua:::athena_option_env$cache_dt
#>                                 QueryId              Query     State
#> 1: 181b8974-2288-4ea0-b7fb-d146daea61b8 select * from iris SUCCEEDED
#>    StatementType WorkGroup UnloadDir
#> 1:           DML   primary

tbl_iris = tbl(con, "iris")

# Check cache
noctua:::athena_option_env$cache_dt
#>                                 QueryId              Query     State
#> 1: 181b8974-2288-4ea0-b7fb-d146daea61b8 select * from iris SUCCEEDED
#>    StatementType WorkGroup UnloadDir
#> 1:           DML   primary

tbl_iris
#> Info: (Data scanned: 3.63 KB)
#> # Source:   table<iris> [?? x 5]
#> # Database: Athena 0.1.12 [default@eu-west-1/default]
#>    sepal_length sepal_width petal_length petal_width species
#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  
#>  1          5.1         3.5          1.4         0.2 setosa 
#>  2          4.9         3            1.4         0.2 setosa 
#>  3          4.7         3.2          1.3         0.2 setosa 
#>  4          4.6         3.1          1.5         0.2 setosa 
#>  5          5           3.6          1.4         0.2 setosa 
#>  6          5.4         3.9          1.7         0.4 setosa 
#>  7          4.6         3.4          1.4         0.3 setosa 
#>  8          5           3.4          1.5         0.2 setosa 
#>  9          4.4         2.9          1.4         0.2 setosa 
#> 10          4.9         3.1          1.5         0.1 setosa 
#> # … with more rows

# Check cache
noctua:::athena_option_env$cache_dt
#>                                 QueryId                           Query
#> 1: 43970523-da56-4e59-8d7b-625e8bc7a8af SELECT *\nFROM "iris"\nLIMIT 11
#> 2: 181b8974-2288-4ea0-b7fb-d146daea61b8              select * from iris
#>        State StatementType WorkGroup UnloadDir
#> 1: SUCCEEDED           DML   primary          
#> 2: SUCCEEDED           DML   primary

Created on 2021-11-15 by the reprex package (v2.0.1)

Looks like repeat queries are being used multiple times, which is great news :D

@DyfanJones
Copy link
Owner Author

This has now been pushed to the cran in release 2.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant