Skip to content

Should dbDataType dispatch to the default AsIs method in custom backends? #514

@MichaelChirico

Description

@MichaelChirico

I have a custom backend where we need a custom method for dbDataType() for logical() ("BOOL" instead of "SMALLINT").

https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types

I'd rather back up to the default dispatch where possible, so instead of writing out a full custom R type->backend type mapping, I've just added one method for logical():

setMethod(
  "dbDataType", c("MyDBIConnection", "logical"),
  \(dbObj, obj, ...) "BOOL"
)

However, that fails the {DBItest} suite:

`expect_identical(...)` threw an unexpected error. ('test-DBITest.R:54:1')
--------------------------------------------------------------------------------
`expect_identical(...)` threw an unexpected error.
Message: dbDataType(dbObj, I(FALSE)) (`actual`) not identical to dbDataType(dbObj, FALSE) (`expected`).

`actual`:   "SMALLINT"
`expected`: "BOOL"    
Class:   expectation_failure/expectation/error/condition

My S4 knowledge is pretty weak, but IIUC the issue is that AsIs does not dispatch to the correct method:

dbiDataType_AsIs <- function(x) {
oldClass(x) <- oldClass(x)[-1]
dbiDataType(x)
}
setMethod("dbiDataType", signature("AsIs"), dbiDataType_AsIs)

So I had to wind up just copy-pasting that as a new c("MyDBIConnection", "AsIs") method.

But shouldn't that be the default behavior so I don't need to copy over boilerplate? That would just mean adding a specific c("DBIConnection", "AsIs") method, right?

(happy to file a PR, but checking my understanding first)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions