Return the corresponding presto data type for the given R object
Source: R/dbDataType.R
dbDataType.Rd
Return the corresponding presto data type for the given R object
Usage
# S4 method for PrestoDriver
dbDataType(dbObj, obj, ...)
Arguments
- dbObj
A PrestoDriver object
- obj
Any R object
- ...
Extra optional parameters, not currently used
Details
The default value for unknown classes is ‘VARCHAR’.
‘ARRAY’s and ‘MAP’s are supported with some caveats. Unnamed lists will be treated as ‘ARRAY’s and named lists will be a ‘MAP’. All items are expected to be of the same corresponding Presto type, otherwise the default ‘VARCHAR’ value is returned. The key type for ‘MAP’s is always ‘VARCHAR’. The ‘value’ type for empty lists is always a ‘VARCHAR’.
Examples
drv <- RPresto::Presto()
dbDataType(drv, list())
#> [1] "ARRAY<VARCHAR>"
dbDataType(drv, 1)
#> [1] "DOUBLE"
dbDataType(drv, NULL)
#> [1] "VARCHAR"
dbDataType(drv, list(list(list(a = Sys.Date()))))
#> [1] "ARRAY<ARRAY<MAP<VARCHAR, DATE>>>"
dbDataType(drv, as.POSIXct("2015-03-01 00:00:00", tz = "UTC"))
#> [1] "TIMESTAMP WITH TIME ZONE"
dbDataType(drv, Sys.time())
#> [1] "TIMESTAMP"
# Data types for ARRAY or MAP values can be tricky
all.equal("VARCHAR", dbDataType(drv, list(1, 2, 3L)))
#> [1] TRUE