Changeset: c3306d01e55e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c3306d01e55e
Modified Files:
        clients/R/MonetDB.R/DESCRIPTION
        clients/R/MonetDB.R/NAMESPACE
        clients/R/MonetDB.R/NEWS
        clients/R/MonetDB.R/R/monetdb.R
Branch: default
Log Message:

R Connector: new query info method etc.


diffs (121 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
@@ -1,11 +1,11 @@
 Package: MonetDB.R
-Version: 0.9.1
-Date: 2013-03-06
+Version: 0.9.2
+Date: 2013-03-18
 Title: Connect MonetDB to R
 Authors@R: c(person("Hannes Muehleisen", role = c("aut", "cre"),email = 
"han...@cwi.nl"),
        person("Thomas Lumley", role = "ctb"),
        person("Anthony Damico", role = "ctb"))
-Depends: DBI (>= 0.2-5), digest (>= 0.6.0), methods
+Depends: DBI (>= 0.2-7), digest (>= 0.6.4), methods
 Description: Allows to pull data from MonetDB into R
 License: MPL (== 1.1)
 URL: http://monetr.r-forge.r-project.org
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
@@ -7,6 +7,7 @@ export(monet.read.csv,monetdb.read.csv)
 exportMethods(dbSendUpdate,dbSendUpdateAsync,dbTransaction)
 export(monetdbGetTransferredBytes)
 export(monetdbRtype)
+export(monetdb_queryinfo)
 
 # shorthand for db connections
 export(mc)
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,3 +1,7 @@
+0.9.2
+- monetdb_queryinfo method to find out things about an arbitrary query cheaply
+- new option monetdb.sequential
+
 0.9.1
 - dbGetInfo() now supported on MonetDBConnection (dplyr compatibility)
 - dbTransaction(), dbCommit() and dbRollback() support
diff --git a/clients/R/MonetDB.R/R/monetdb.R b/clients/R/MonetDB.R/R/monetdb.R
--- a/clients/R/MonetDB.R/R/monetdb.R
+++ b/clients/R/MonetDB.R/R/monetdb.R
@@ -26,7 +26,7 @@ MonetR <- MonetDB <- MonetDBR <- MonetDB
 setMethod("dbGetInfo", "MonetDBDriver", def=function(dbObj, ...)
                        list(name="MonetDBDriver", 
                                        driver.version="0.9.1",
-                                       DBI.version="0.2-5",
+                                       DBI.version="0.2-7",
                                        client.version=NA,
                                        max.connections=NA)
 )
@@ -36,6 +36,14 @@ mc <- function(dbname="demo", user="mone
        
dbConnect(MonetDB.R(),dbname,user,password,host,port,timeout,wait,language,...)
 }
 
+# TODO: document, export etc
+mq <- function(db,query,...) {
+  conn <- mc(db,...)
+  res <- dbGetQuery(conn,query)
+  dbDisconnect(conn)
+  return(res)
+}
+
 setMethod("dbConnect", "MonetDBDriver", def=function(drv,dbname="demo", 
user="monetdb", password="monetdb", host="localhost",port=50000L, 
timeout=86400L, wait=FALSE,language="sql",...,url="") {
                        if (substring(url,1,10) == "monetdb://") {
                                dbname <- url
@@ -68,17 +76,10 @@ setMethod("dbConnect", "MonetDBDriver", 
                                        continue <- FALSE
                                        tryCatch ({
                                                                # open socket 
with 5-sec timeout so we can check whether everything works
-                                                               #socket <- 
socket <<- socketConnection(host = host, port = port, 
-                                                               #       
blocking = TRUE, open="r+b",timeout = 5 )
-                                                               
-                                                               # this goes to 
src/mapi.c
-                                                               # TODO: this 
ends up in the global environment. Bad.
                                                                socket <- 
socket <<- .Call("mapiConnect",host,port,5,PACKAGE=C_LIBRARY)
                                                                # authenticate
                                                                
.monetAuthenticate(socket,dbname,user,password,language=language)
                                                                # test the 
connection to make sure it works before
-                                                               
.mapiWrite(socket,"sSELECT 42;"); .mapiRead(socket)
-                                                               #close(socket)
                                                                
.Call("mapiDisconnect",socket,PACKAGE=C_LIBRARY)
                                                                break
                                                        }, error = function(e) {
@@ -101,8 +102,14 @@ setMethod("dbConnect", "MonetDBDriver", 
                        connenv$lock <- 0
                        connenv$deferred <- list()
                        connenv$exception <- list()
+      
+      conn <- new("MonetDBConnection",socket=socket,connenv=connenv,Id=-1L)
+      if (getOption("monetdb.sequential",F)) {
+        message("MonetDB: Switching to single-threaded query execution")
+        dbSendQuery(conn,"set optimizer='sequential_pipe'")
+      }
 
-                       
return(new("MonetDBConnection",socket=socket,connenv=connenv,Id=-1L))
+                       return(conn)
                },
                valueClass="MonetDBConnection")
 
@@ -901,3 +908,19 @@ monetdbd.liststatus <- monetdb.liststatu
   
   return(dbdf[order(dbdf$dbname),])
 }
+
+monetdb_queryinfo <- function(conn,query) {
+  info <- emptyenv()
+  tryCatch({
+    .mapiRequest(conn,"Xreply_size 1")
+    res <- dbSendQuery(conn,query)
+    info <- res@env$info
+    dbClearResult(res);
+  }, error = function(e) {
+    print(e)
+    warning("Failed to calculate result set size for ",query)
+  }, finally = {
+    .mapiRequest(conn, paste0("Xreply_size ",REPLY_SIZE))
+  })
+  info
+}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to