Changeset: 0360a448af4f for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0360a448af4f Modified Files: clients/R/MonetDB.R/DESCRIPTION clients/R/MonetDB.R/NAMESPACE clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/dplyr.R clients/R/MonetDB.R/R/mapi.R clients/R/Tests/dbi.R clients/R/Tests/dbi.stable.out clients/R/Tests/dplyr.R clients/R/Tests/dplyr.stable.err clients/R/Tests/dplyr.stable.out Branch: Oct2014 Log Message:
R Connector: Bugfixes Unterschiede (gekürzt von 1388 auf 300 Zeilen): 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 @@ -5,13 +5,9 @@ Authors@R: c(person("Hannes Muehleisen", person("Thomas Lumley", role = "ctb"), person("Anthony Damico", role = "ctb")) Depends: DBI (>= 0.3), digest (>= 0.6.4), bitops (>= 1.0), methods -Suggests: dplyr(>= 0.2.0.9000) -Description: Allows to pull data from MonetDB into R +Suggests: dplyr(>= 0.3) +Description: Allows to pull data from MonetDB into R. Includes a DBI implementation and a dplyr backend. License: MPL (== 1.1) URL: http://monetr.r-forge.r-project.org Maintainer: Hannes Muehleisen <han...@cwi.nl> -SystemRequirements: MonetDB installation, available at - http://www.monetdb.org -Author: Hannes Muehleisen [aut, cre], - Thomas Lumley [ctb], - Anthony Damico [ctb] +SystemRequirements: MonetDB, available from http://www.monetdb.org \ No newline at end of file diff --git a/clients/R/MonetDB.R/NAMESPACE b/clients/R/MonetDB.R/NAMESPACE --- a/clients/R/MonetDB.R/NAMESPACE +++ b/clients/R/MonetDB.R/NAMESPACE @@ -18,8 +18,8 @@ useDynLib(MonetDB.R) # dplyr.R export(src_monetdb) -export(translate_env.src_monetdb) -export(brief_desc.src_monetdb) +export(src_translate_env.src_monetdb) +export(src_desc.src_monetdb) export(tbl.src_monetdb) export(db_query_fields.MonetDBConnection) export(db_query_rows.MonetDBConnection) @@ -27,5 +27,6 @@ export(db_save_query.MonetDBConnection) export(db_insert_into.MonetDBConnection) export(db_create_index.MonetDBConnection) export(db_analyze.MonetDBConnection) -export(db_begin.MonetDBConnection) export(sql_subquery.MonetDBConnection) +export(sql_join.MonetDBConnection) +export(monetdb_queryinfo) 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,12 +1,12 @@ 0.9.5 -- Fixed package date (Thanks, Dimitar) +- Removed package date (Thanks, Dimitar) - Added sys. schema name to internal queries, so SET SCHEMA xx would not break things (Thanks again, Dimitar) - Fixed monetdb:// URL handling on newer R versions (Thanks, Alex) - DBI 0.3 compatibility (isValid etc.) - deprecated dbTransaction() (DBI has standardized dbBegin()) - Back to R socket code for peace of mind - Code cleanup -- dplyr integration moved to MonetDB.R +- dplyr integration moved to MonetDB.R package 0.9.4 - dbWriteTable overhaul (thanks, Anthony) 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 @@ -24,11 +24,11 @@ setGeneric("dbIsValid", valueClass = "logical") setMethod("dbIsValid", "MonetDBDriver", def=function(dbObj, ...) { - return(TRUE) # driver object cannot be invalid + return(invisible(TRUE)) # driver object cannot be invalid }) setMethod("dbUnloadDriver", "MonetDBDriver", def=function(drv, ...) { - return(TRUE) # there is nothing to really unload here... + return(invisible(TRUE)) # there is nothing to really unload here... }) setMethod("dbGetInfo", "MonetDBDriver", def=function(dbObj, ...) @@ -124,7 +124,7 @@ setMethod("dbConnect", "MonetDBDriver", } # make new socket with user-specified timeout - socket <- .mapiConnect(host, port, 5) + socket <- .mapiConnect(host, port, timeout) .mapiAuthenticate(socket, dbname, user, password, language=language) connenv <- new.env(parent=emptyenv()) connenv$lock <- 0 @@ -156,7 +156,7 @@ setMethod("dbGetInfo", "MonetDBConnectio }) setMethod("dbIsValid", "MonetDBConnection", def=function(dbObj, ...) { - return(!is.na(tryCatch(dbGetInfo(dbObj), error=function(e){NA}))) + return(invisible(!is.na(tryCatch({dbGetInfo(dbObj);TRUE}, error=function(e){NA})))) }) setMethod("dbDisconnect", "MonetDBConnection", def=function(conn, ...) { @@ -315,7 +315,7 @@ setMethod("dbWriteTable", "MonetDBConnec if (overwrite && append) { stop("Setting both overwrite and append to true makes no sense.") } - qname <- dbQuoteIdentifier(conn, name) + qname <- make.db.names(conn, name) if (dbExistsTable(conn, qname)) { if (overwrite) dbRemoveTable(conn, qname) if (!overwrite && !append) stop("Table ", qname, " already exists. Set overwrite=TRUE if you want @@ -324,7 +324,7 @@ setMethod("dbWriteTable", "MonetDBConnec } if (!dbExistsTable(conn, qname)) { fts <- sapply(value, dbDataType, dbObj=conn) - fdef <- paste(dbQuoteIdentifier(conn, names(value)), fts, collapse=', ') + fdef <- paste(make.db.names(conn, names(value)), fts, collapse=', ') ct <- paste("CREATE TABLE ", qname, " (", fdef, ")", sep= '') dbSendUpdate(conn, ct) } @@ -580,21 +580,21 @@ setMethod("dbClearResult", "MonetDBResul res@env$open <- FALSE } } - invisible(TRUE) + return(invisible(TRUE)) }, valueClass = "logical") setMethod("dbHasCompleted", "MonetDBResult", def = function(res, ...) { if (res@env$info$type == Q_TABLE) { return(res@env$delivered == res@env$info$rows) } - return(TRUE) + return(invisible(TRUE)) }, valueClass = "logical") setMethod("dbIsValid", signature(dbObj="MonetDBResult"), def=function(dbObj, ...) { if (dbObj@env$info$type == Q_TABLE) { return(dbObj@env$open) } - return(TRUE) + return(invisible(TRUE)) }) monetTypes <- rep(c("numeric", "character", "character", "logical", "raw"), c(9, 3, 4, 1, 1)) 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 @@ -5,7 +5,7 @@ src_monetdb <- function(dbname, host = " src_sql("monetdb", con, info = dbGetInfo(con)) } -translate_env.src_monetdb <- function(x) { +src_translate_env.src_monetdb <- function(x) { sql_variant( base_scalar, sql_translator(.parent = base_agg, @@ -17,19 +17,22 @@ translate_env.src_monetdb <- function(x) ) } -brief_desc.src_monetdb <- function(x) { +sql_join.MonetDBConnection <- function(con, x, y, type = "inner", by = NULL, ...) { + NextMethod("sql_join",...) +} + +src_desc.src_monetdb <- function(x) { paste0("MonetDB ",x$info$monet_version, " (",x$info$monet_release, ") [", x$info$merovingian_uri,"]") } tbl.src_monetdb <- function(src, from, ...) { monetdb_check_subquery(from) - tbl_sql("mownetdb", src = src, from = from, ...) + tbl_sql("monetdb", src = src, from = from, ...) } db_query_fields.MonetDBConnection <- function(con, sql, ...) { - # prepare gives us column info without actually running a query - # TODO: how about more complex queries? - dbGetQuery(con,build_sql("PREPARE SELECT * FROM ", ident(sql)))$column + # prepare gives us column info without actually running a query. Nice. + dbGetQuery(con, build_sql("PREPARE SELECT * FROM ", sql))$column } db_query_rows.MonetDBConnection <- function(con, sql, ...) { @@ -48,10 +51,6 @@ db_save_query.MonetDBConnection <- funct name } -db_begin.MonetDBConnection <- function(con, ...) { - dbBegin(con) -} - db_create_index.MonetDBConnection <- function(con, table, columns, name = NULL, ...) { TRUE @@ -62,6 +61,7 @@ db_analyze.MonetDBConnection <- function } sql_subquery.MonetDBConnection <- function(con, sql, name = unique_name(), ...) { + print(str(sql)) if (is.ident(sql)) return(sql) monetdb_check_subquery(sql) build_sql("(", sql, ") AS ", ident(name), con = con) @@ -87,4 +87,14 @@ monetdb_queryinfo <- function(conn, quer .mapiRequest(conn, paste0("Xreply_size ", REPLY_SIZE)) }) info -} \ No newline at end of file +} + +# copied from dplyr's utils.r, sql_subquery needs it +unique_name <- local({ + i <- 0 + + function() { + i <<- i + 1 + paste0("_W", i) + } +}) \ No newline at end of file diff --git a/clients/R/MonetDB.R/R/mapi.R b/clients/R/MonetDB.R/R/mapi.R --- a/clients/R/MonetDB.R/R/mapi.R +++ b/clients/R/MonetDB.R/R/mapi.R @@ -192,7 +192,9 @@ REPLY_SIZE <- 100 # Apparently, -1 me .mapiParseResponse <- function(response) { #lines <- .Call("mapiSplitLines", response, PACKAGE="MonetDB.R") lines <- strsplit(response, "\n", fixed=TRUE, useBytes=TRUE)[[1]] - + if (length(lines) < 1) { + stop("Invalid response from server. Try re-connecting.") + } typeLine <- lines[[1]] resKey <- substring(typeLine, 1, 1) 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 @@ -46,20 +46,21 @@ stopifnot(identical(dbExistsTable(con,tn stopifnot(identical(dbExistsTable(con,"monetdbtest2"),FALSE)) stopifnot(tname %in% dbListTables(con)) -stopifnot(identical(dbListFields(con,tname),c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"))) +stopifnot(identical(dbListFields(con,tname),c("sepal_length","sepal_width", + "petal_length","petal_width","species"))) # get stuff, first very convenient iris2 <- dbReadTable(con,tname) stopifnot(identical(dim(iris),dim(iris2))) # then manually -res <- dbSendQuery(con,"SELECT \"Species\", \"Sepal.Width\" FROM monetdbtest") +res <- dbSendQuery(con,"SELECT species, sepal_width FROM monetdbtest") stopifnot(dbIsValid(res)) stopifnot(identical(class(res)[[1]],"MonetDBResult")) stopifnot(identical(res@env$success,TRUE)) -stopifnot(dbColumnInfo(res)[[1,1]] == "Species") -stopifnot(dbColumnInfo(res)[[2,1]] == "Sepal.Width") +stopifnot(dbColumnInfo(res)[[1,1]] == "species") +stopifnot(dbColumnInfo(res)[[2,1]] == "sepal_width") stopifnot(dbGetInfo(res)$row.count == 150 && res@env$info$rows == 150) @@ -90,7 +91,8 @@ unlink(file) stopifnot(identical(dbExistsTable(con,tname),TRUE)) iris3 <- dbReadTable(con,tname) stopifnot(identical(dim(iris),dim(iris3))) -stopifnot(identical(dbListFields(con,tname),c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"))) +stopifnot(identical(dbListFields(con,tname),c("sepal_length","sepal_width", + "petal_length","petal_width","species"))) dbRemoveTable(con,tname) stopifnot(identical(dbExistsTable(con,tname),FALSE)) diff --git a/clients/R/Tests/dbi.stable.out b/clients/R/Tests/dbi.stable.out --- a/clients/R/Tests/dbi.stable.out +++ b/clients/R/Tests/dbi.stable.out @@ -64,6 +64,11 @@ 1 150 [1] FALSE [1] TRUE [1] TRUE +[1] TRUE +[1] TRUE +[1] TRUE +[1] TRUE +[1] TRUE [1] "SUCCESS" # 14:24:04 > 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 @@ -9,21 +9,30 @@ dbname <- "mTests_clients_R" if (length(args) > 0) dbport <- args[[1]] +if (exists("lahman_monetdb")) { + # overwrite all args because lahman_monetdb sets a default arg in the first pos. + srct <- function() lahman_monetdb(host="localhost", dbname=dbname, port=dbport , + user="monetdb",password="monetdb",timeout=100,wait=T,language="sql") +} else { + srct <- function() src_monetdb(dbname=dbname, port=dbport) + copy_lahman(srct()) +} + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list