Changeset: ab762b4058c7 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ab762b4058c7 Modified Files: clients/R/MonetDB.R/DESCRIPTION clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/dplyr.R clients/R/Tests/dbapply.R clients/R/Tests/dbi.R clients/R/Tests/dbi.stable.err clients/R/Tests/dplyr.R Branch: embedded Log Message:
no longer importing dbi diffs (264 lines): diff --git a/clients/R/MonetDB.R/DESCRIPTION b/clients/R/MonetDB.R/DESCRIPTION --- a/clients/R/MonetDB.R/DESCRIPTION +++ b/clients/R/MonetDB.R/DESCRIPTION @@ -6,8 +6,7 @@ Authors@R: c(person("Hannes Muehleisen", person("Thomas Lumley", role = "ctb")) Author: Hannes Muehleisen [aut, cre], Anthony Damico [aut], Thomas Lumley [ctb] Maintainer: Hannes Muehleisen <han...@cwi.nl> -Depends: DBI (>= 0.3.1) -Imports: digest (>= 0.6.4), methods, codetools +Imports: DBI (>= 0.3.1), digest (>= 0.6.4), methods, codetools Enhances: dplyr (>= 0.3.0), MonetDBLite Description: Allows to pull data from MonetDB into R. Includes a DBI implementation and a dplyr backend. License: MPL (== 2.0) diff --git a/clients/R/MonetDB.R/NEWS b/clients/R/MonetDB.R/NEWS --- a/clients/R/MonetDB.R/NEWS +++ b/clients/R/MonetDB.R/NEWS @@ -1,7 +1,7 @@ 1.0.1 - added isIdCurrent for improved compatibility with RSQLite - new option monetdb.log.query allows export of dbSendQuery statements to file - +- no longer depends on DBI but imports it 1.0.0 - Added support for esoteric data types such as MONTH_INTERVAL (Thanks, Roman) diff --git a/clients/R/MonetDB.R/R/dbi.R b/clients/R/MonetDB.R/R/dbi.R --- a/clients/R/MonetDB.R/R/dbi.R +++ b/clients/R/MonetDB.R/R/dbi.R @@ -21,7 +21,7 @@ setMethod("dbGetInfo", "MonetDBDriver", list(name="MonetDBDriver", driver.version=utils::packageVersion("MonetDB.R"), DBI.version=utils::packageVersion("DBI"), - client.version="NA", + client.version=NA, max.connections=125) # R can only handle 128 connections, three of which are pre-allocated ) diff --git a/clients/R/MonetDB.R/R/dplyr.R b/clients/R/MonetDB.R/R/dplyr.R --- a/clients/R/MonetDB.R/R/dplyr.R +++ b/clients/R/MonetDB.R/R/dplyr.R @@ -1,11 +1,10 @@ src_monetdb <- function(dbname="demo", host = "localhost", port = 50000L, user = "monetdb", password = "monetdb", con = FALSE, ...) { - if (!inherits(con, "MonetDBConnection") || !dbIsValid(con)) { - con <- dbConnect(MonetDB.R(), dbname = dbname , host = host, port = port, + if (!inherits(con, "MonetDBConnection") || !DBI::dbIsValid(con)) { + con <- DBI::dbConnect(MonetDB.R(), dbname = dbname , host = host, port = port, user = user, password = password, ...) } - requireNamespace("dplyr") - dplyr::src_sql("monetdb", con, info = dbGetInfo(con)) + dplyr::src_sql("monetdb", con, info = DBI::dbGetInfo(con)) } src_translate_env.src_monetdb <- function(x) { @@ -38,7 +37,7 @@ sample_n.tbl_monetdb <- function(x, size stop("Sorry, replace and weight are not supported for MonetDB tables. \ Consider collect()'ing first.") } - dbGetQuery(x$src$con, dplyr::build_sql(x$query$sql, " SAMPLE ", as.integer(size))) + DBI::dbGetQuery(x$src$con, dplyr::build_sql(x$query$sql, " SAMPLE ", as.integer(size))) } sample_frac.tbl_monetdb <- function(tbl, frac=1, replace = FALSE, weight = NULL) { @@ -54,11 +53,11 @@ sample_frac.tbl_monetdb <- function(tbl, db_query_fields.MonetDBConnection <- function(con, sql, ...) { # prepare gives us column info without actually running a query. Nice. - dbGetQuery(con, dplyr::build_sql("PREPARE SELECT * FROM ", sql))$column + DBI::dbGetQuery(con, dplyr::build_sql("PREPARE SELECT * FROM ", sql))$column } db_query_fields.MonetDBEmbeddedConnection <- function(con, sql, ...) { - names(dbGetQuery(con, dplyr::build_sql("SELECT * FROM ", sql), notreally=T)) + names(DBI::dbGetQuery(con, dplyr::build_sql("SELECT * FROM ", sql), notreally=T)) } db_query_rows.MonetDBConnection <- function(con, sql, ...) { @@ -70,15 +69,15 @@ db_query_rows.MonetDBEmbeddedConnection } db_insert_into.MonetDBConnection <- function(con, table, values, ...) { - dbWriteTable(con,dbQuoteIdentifier(con,table),values, - append=T,transaction=F,csvdump=T) + DBI::dbWriteTable(con, DBI::dbQuoteIdentifier(con, table), values, + append=T, transaction=F, csvdump=T) } db_save_query.MonetDBConnection <- function(con, sql, name, temporary = TRUE, ...) { tt_sql <- dplyr::build_sql("CREATE TEMPORARY TABLE ", dplyr::ident(name), " AS ", sql, " WITH DATA ON COMMIT PRESERVE ROWS", con = con) - dbGetQuery(con, tt_sql) + DBI::dbGetQuery(con, tt_sql) name } diff --git a/clients/R/Tests/dbapply.R b/clients/R/Tests/dbapply.R --- a/clients/R/Tests/dbapply.R +++ b/clients/R/Tests/dbapply.R @@ -2,7 +2,7 @@ ll <- NULL if (Sys.getenv("TSTTRGDIR") != "") { ll <- paste0(Sys.getenv("TSTTRGDIR"),"/rlibdir") } -library(MonetDB.R,quietly=T,lib.loc=ll) +library(DBI, quietly = T) args <- commandArgs(trailingOnly = TRUE) dbport <- 50000 @@ -17,7 +17,7 @@ options(monetdb.profile=F) tname <- "monetdbtest" -con <- dbConnect(MonetDB(), port=dbport, dbname=dbname, wait=T) +con <- dbConnect(MonetDB.R::MonetDB(), port=dbport, dbname=dbname, wait=T) stopifnot(dbIsValid(con)) #options(monetdb.debug.query=T) @@ -55,7 +55,7 @@ print(length(predictions)) # make sure we bubble up the error haderror <- FALSE tryCatch({ - res <- mdbapply(con,tname,function(d) { + res <- MonetDB.R::mdbapply(con,tname,function(d) { stop("i am an error") }) }, error=function(e) { diff --git a/clients/R/Tests/dbi.R b/clients/R/Tests/dbi.R --- a/clients/R/Tests/dbi.R +++ b/clients/R/Tests/dbi.R @@ -2,7 +2,7 @@ ll <- NULL if (Sys.getenv("TSTTRGDIR") != "") { ll <- paste0(Sys.getenv("TSTTRGDIR"),"/rlibdir") } -library(MonetDB.R,quietly=T,lib.loc=ll) +library(DBI) args <- commandArgs(trailingOnly = TRUE) dbport <- 50000 @@ -18,8 +18,8 @@ options(monetdb.profile=F) tname <- "monetdbtest" -drv <- dbDriver("MonetDB") -stopifnot(identical(dbGetInfo(drv)$name,"MonetDBDriver")) +drv <- MonetDB.R::MonetDB() +stopifnot(identical(dbGetInfo(drv)$name, "MonetDBDriver")) con <- conn <- dbConnect(drv, port=dbport, dbname=dbname, wait=T) stopifnot(identical(class(con)[[1]],"MonetDBConnection")) @@ -37,10 +37,10 @@ stopifnot(identical(dbExistsTable(con,tn # test raw handling -dbSendUpdate(con,"CREATE TABLE monetdbtest (a varchar(10),b integer,c blob)") +MonetDB.R::dbSendUpdate(con,"CREATE TABLE monetdbtest (a varchar(10),b integer,c blob)") stopifnot(identical(dbExistsTable(con,tname),TRUE)) -dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('one',1,'1111')") -dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('two',2,'22222222')") +MonetDB.R::dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('one',1,'1111')") +MonetDB.R::dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('two',2,'22222222')") stopifnot(identical(dbGetQuery(con,"SELECT count(*) FROM monetdbtest")[[1]],2L)) stopifnot(identical(dbReadTable(con,tname)[[3]],list(charToRaw("1111"),charToRaw("22222222")))) dbRemoveTable(con,tname) @@ -62,7 +62,7 @@ stopifnot(identical(dim(iris),dim(iris2) # then manually res <- dbSendQuery(con,"SELECT \"Species\", \"Sepal.Width\" FROM monetdbtest") stopifnot(dbIsValid(res)) -stopifnot(isIdCurrent(res)) +stopifnot(MonetDB.R::isIdCurrent(res)) stopifnot(identical(class(res)[[1]],"MonetDBResult")) stopifnot(identical(res@env$success,TRUE)) @@ -95,8 +95,8 @@ tf <- tempfile() write.table(iris,tf,sep=",",row.names=FALSE) tname2 <- "Need to quote this table name" tname3 <- "othermethod" -monetdb.read.csv(con,tf,tname) -monetdb.read.csv(con,tf,tname2) +MonetDB.R::monetdb.read.csv(con,tf,tname) +MonetDB.R::monetdb.read.csv(con,tf,tname2) dbWriteTable(con, tname3, tf) ### @@ -161,7 +161,7 @@ dbWriteTable(conn,tname,mtcars,append=F, dbRemoveTable(conn,tname) # info -stopifnot(identical("MonetDBDriver", dbGetInfo(MonetDB.R())$name)) +stopifnot(identical("MonetDBDriver", dbGetInfo(MonetDB.R::MonetDB.R())$name)) stopifnot(identical("MonetDBConnection", dbGetInfo(conn)$name)) # transactions... @@ -186,7 +186,7 @@ sq <- dbSendQuery(conn,"CREATE TABLE mon sq <- dbSendQuery(conn,"INSERT INTO monetdbtest VALUES ('Роман Mühleisen')") stopifnot(identical("Роман Mühleisen", dbGetQuery(conn,"SELECT a FROM monetdbtest")$a[[1]])) sq <- dbSendQuery(conn,"DELETE FROM monetdbtest") -dbSendUpdate(conn, "INSERT INTO monetdbtest (a) VALUES (?)", "Роман Mühleisen") +MonetDB.R::dbSendUpdate(conn, "INSERT INTO monetdbtest (a) VALUES (?)", "Роман Mühleisen") stopifnot(identical("Роман Mühleisen", dbGetQuery(conn,"SELECT a FROM monetdbtest")$a[[1]])) dbRollback(conn) diff --git a/clients/R/Tests/dbi.stable.err b/clients/R/Tests/dbi.stable.err --- a/clients/R/Tests/dbi.stable.err +++ b/clients/R/Tests/dbi.stable.err @@ -32,7 +32,7 @@ stderr of test 'dbi` in directory 'clien Identifier(s) "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species" contain uppercase or reserved SQL characters and need(s) to be quoted in queries. Warning message: -'isIdCurrent' is deprecated. +'MonetDB.R::isIdCurrent' is deprecated. Use 'dbIsValid' instead. See help("Deprecated") Identifier(s) "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species" contain uppercase or reserved SQL characters and need(s) to be quoted in queries. diff --git a/clients/R/Tests/dplyr.R b/clients/R/Tests/dplyr.R --- a/clients/R/Tests/dplyr.R +++ b/clients/R/Tests/dplyr.R @@ -8,11 +8,8 @@ ff <- textConnection("asdf", open="w") # so if things go south it might be a good idea to uncomment the cat(dd) below dd <- capture.output( suppressMessages ( { -library(MonetDB.R,quietly=T,lib.loc=ll) -library(dplyr,quietly=T) -library(Lahman,quietly=T) - -options(monetdb.profile=F) +library(dplyr, quietly = T) +library(Lahman, quietly = T) args <- commandArgs(trailingOnly = TRUE) dbport <- 50000 @@ -23,20 +20,11 @@ if (length(args) > 1) dbname <- args[[2]] -# old way -if (exists("lahman_monetdb")) { - # overwrite all args because lahman_monetdb sets a default arg in the first pos. - dps <- lahman_monetdb(host="localhost", dbname=dbname, port=dbport , - user="monetdb",password="monetdb",timeout=100,wait=T,language="sql") -# new way -} else { - dps <- src_monetdb(dbname=dbname, port=dbport) - copy_lahman(dps) -} +dps <- MonetDB.R::src_monetdb(dbname=dbname, port=dbport) +copy_lahman(dps) + })) -#cat(dd) - # the remainder is pretty much the example from the manpage. # Methods ------------------------------------------------------------------- @@ -140,7 +128,7 @@ print(nrow(aa)) -dbRemoveTable(dps$con, "mtcars") +DBI::dbRemoveTable(dps$con, "mtcars") print("SUCCESS") _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list