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

Fix copy_to() for MSSQL databases #280

Merged
merged 5 commits into from Apr 16, 2019
Merged

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Apr 9, 2019

A regression.

The partial NextMethod() calls didn't work for me, only when the full list of arguments is specified.

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you construct a reprex that illustrates the basic problem? This seems correct to me:

foo <- function(x, y = 1, ...) UseMethod("foo")

foo.bar <- function(x, y = 2, ...) NextMethod(z = 2)
foo.baz <- function(x, y = 3, z = 3, ...) list(y = y, z = z, ...)

foo(structure(list(), class = c("bar", "baz")), y = 0)
#> $y
#> [1] 0
#> 
#> $z
#> [1] 2

Created on 2019-04-10 by the reprex package (v0.2.1.9000)

NextMethod(
name = mssql_temp_name(name, temporary),
temporary = FALSE
name <- mssql_temp_name(name, temporary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason you can no longer use NextMethod() here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax is different in MSSQL. Originally implemented in #50, f283e03 reverted to using the parent method.

https://stackoverflow.com/q/16683758/946850

Adding a comment to the code.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 11, 2019

I have reduced the NextMethod() calls somewhat.

This isn't exactly what I've seen, but something weird is going on:

foo <- function(x, y = 1, ...) UseMethod("foo")

foo.bar <- function(x, y = 2, z = 2, ...) NextMethod(z = z + 1, b = 5)
foo.baz <- function(x, y = 3, z = 3, ...) moo(x, y, z, ...)

moo <- function(x, y, z, ...) UseMethod("moo")
moo.bar <- function(x, y, z, ...) NextMethod(y = 6)
moo.baz <- function(x, y, z, ...) list(y = y, z = z, ...)

foo(structure(list(), class = c("bar", "baz")), y = 2)
#> $y
#> [1] 6
#> 
#> $z
#> [1] 2
#> 
#> [[3]]
#> [1] 3
#> 
#> $b
#> [1] 5

Created on 2019-04-11 by the reprex package (v0.2.1.9000)

@krlmlr
Copy link
Member Author

krlmlr commented Apr 11, 2019

For reference, this is what I see on a live database with krlmlr/dbplyr@390d23a. When debugging, the arguments are garbled:

library(tidyverse)
library(DBI)
library(dbplyr)

mssql_con <- function() {
  DBI::dbConnect(
    odbc::odbc(),
    Driver = "SQL Server Driver",
    ...,
    TDS_Version = 7.4
  )
}

con <- mssql_con()

dbExecute(con, "SET NOCOUNT ON")
#> [1] 0

src <- src_dbi(con)

iris_tbl <- copy_to(src, iris, name = "iris", overwrite = TRUE, temporary = FALSE)
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'dbWriteTable' for signature '"Microsoft SQL Server", "SQL", "character"'

Created on 2019-04-11 by the reprex package (v0.2.1.9000)

@hadley
Copy link
Member

hadley commented Apr 12, 2019

Hmmm, maybe it's some weird interaction with S4.

)
dbExecute(con, tt_sql)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we test this without an activate MS SQL backend by mocking dbExecute() to just return the sql, and then using expect_known_output()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps with an approach similar to dbi-log. But then we still need to double-check the generated SQL.

Would you like me to open a new issue to discuss?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just want a simple way to test this code without adding additional complexity or new dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed an issue: #284. Suggesting to rely on user testing for this PR, discuss/implement #284 for the v1.4.0 release and add some tests too.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 12, 2019

The reprex in #280 (comment) doesn't use S4.

@krlmlr krlmlr requested a review from hadley April 14, 2019 19:49
@hadley hadley merged commit 94275b0 into tidyverse:master Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants