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

Data type datetime and timezone_ntz convert to character in dplyr-snowflakedb. Is this normal or a bug? #23

Open
harmverschuren opened this issue Aug 7, 2019 · 1 comment

Comments

@harmverschuren
Copy link

harmverschuren commented Aug 7, 2019

I am integrating Snowflake and R via dplyr-snowflakedb package. Columns of data type datetime or timezone are being converted to character in R. I would expect the column to be converted to POSIXct.
Has anyone have run into this problem before? Is it a bug or feature/normal behaviour?

TIA.

Test case:

Create a table in snowflake, like this

`create table test
(date_time_1 timestamp_ntz
,date_time_2 datetime
);

insert into test values ('2019-08-05 10:05:00', '2019-08-05 10:05:10');
insert into test values ('2019-08-06 18:45:00', '2019-08-06 18:45:10');

commit;`

In RStudio, query the table. Following R-script provides a working example test script.

`##############################

local function, fill in your credentials

##############################
query_snowflake <- function(query) {
tryCatch({
message(paste("INFO - run Snowflake query:", query, sep = " "))
conn <- src_snowflakedb(
user = user,
password = password,
account = account,
region = region,
opts = list(
warehouse = warehouse,
db = database,
schema = schema
)
)
resultset <- dbSendQuery(conn$con, query)
ds <- dbFetch(resultset)
dbClearResult(resultset)
},
finally = dbDisconnect(conn$con)
)
return(ds)
}

##############################

environment

##############################
if (!require(RJDBC)) install.packages("RJDBC")
library(RJDBC)

if (!require(DBI)) install.packages("DBI")
library(DBI)

if (!require(rJava)) install.packages("rJava")
library(rJava)

if (!require(devtools)) install.packages("devtools")
library(devtools)

if (!require(dplyr.snowflakedb)) devtools::install_github("snowflakedb/dplyr-snowflakedb")
library(dplyr.snowflakedb)
options(dplyr.jdbc.classpath = "../snowflake-jdbc-3.6.28.jar")

library(dplyr)

##############################

Main.

##############################
ds <- query_snowflake("select * from test")

both attributes are character (chr)

str(ds)

expected:

ds$DATE_TIME_1 <- as.POSIXct(ds$DATE_TIME_1)
ds$DATE_TIME_2 <- as.POSIXct(ds$DATE_TIME_2)
str(ds)`

@harmverschuren harmverschuren changed the title Data type datetime and timezone_ntz convert to character in dplyr.snowflake. Is this normal or a bug? Data type datetime and timezone_ntz convert to character in dplyr-snowflakedb. Is this normal or a bug? Aug 7, 2019
@rdatasculptor
Copy link

I encountered the same problem.

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

No branches or pull requests

2 participants