Changeset: dcd358d882e1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dcd358d882e1
Added Files:
        monetdb5/extras/rapi/Tests/rapi10.malC
Modified Files:
        monetdb5/extras/rapi/Tests/All
        monetdb5/extras/rapi/rapi.R
        monetdb5/extras/rapi/rapi.c
        monetdb5/extras/rapi/rapi.h
Branch: default
Log Message:

Infrastructure for loopback queries from embedded R functions


diffs (74 lines):

diff --git a/monetdb5/extras/rapi/Tests/All b/monetdb5/extras/rapi/Tests/All
--- a/monetdb5/extras/rapi/Tests/All
+++ b/monetdb5/extras/rapi/Tests/All
@@ -7,3 +7,4 @@ HAVE_LIBR&NOT_WIN32?rapi05
 HAVE_LIBR&NOT_WIN32?rapi06
 HAVE_LIBR&NOT_WIN32?rapi07
 HAVE_LIBR&NOT_WIN32?rapi08
+HAVE_LIBR&NOT_WIN32?rapi10
diff --git a/monetdb5/extras/rapi/Tests/rapi10.malC 
b/monetdb5/extras/rapi/Tests/rapi10.malC
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rapi/Tests/rapi10.malC
@@ -0,0 +1,3 @@
+
+r:bat[:oid,:str] := rapi.eval(nil:ptr,"loopback_query('select * from 
tables;')");
+io.print(r);
diff --git a/monetdb5/extras/rapi/rapi.R b/monetdb5/extras/rapi/rapi.R
--- a/monetdb5/extras/rapi/rapi.R
+++ b/monetdb5/extras/rapi/rapi.R
@@ -51,3 +51,8 @@ rewireFunc("q", quit, "base")
 #rewireFunc("system2", system, "base")
 
 rm(rewireFunc)
+
+loopback_query <- function(query) {
+       dyn.load(file.path(MONETDB_BINDIR, "..", "lib", "monetdb5", 
"lib_rapi.so"))
+       .Call("RAPIloopback", query, package="lib_rapi")
+}
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -271,7 +271,7 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
        // get the lock even before initialization of the R interpreter, as 
this can take a second and must be done only once.
        MT_lock_set(&rapiLock);
 
-       env = PROTECT(eval(lang1(install("new.env")),R_GlobalEnv));
+       env = PROTECT(eval(lang1(install("new.env")), R_GlobalEnv));
        assert(env != NULL);
 
        // first argument after the return contains the pointer to the sql_func 
structure
@@ -444,6 +444,12 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
        return msg;
 }
 
+void* RAPIloopback(void *query) {
+       //FIXME actually do something
+       return (void*) ScalarString(mkCharCE((char*)CHAR(STRING_ELT((SEXP) 
query, 0)), CE_UTF8));
+}
+
+
 str RAPIprelude(void *ret) {
        (void) ret;
        MT_lock_init(&rapiLock, "rapi_lock");
@@ -458,6 +464,8 @@ str RAPIprelude(void *ret) {
                                throw(MAL, "rapi.eval",
                                          "failed to initialise R environment 
(%s)", initstatus);
                        }
+                       Rf_defineVar(Rf_install("MONETDB_BINDIR"), 
ScalarString(mkCharCE(BINDIR, CE_UTF8)), R_GlobalEnv);
+
                }
                MT_lock_unset(&rapiLock);
                printf("# MonetDB/R   module loaded\n");
diff --git a/monetdb5/extras/rapi/rapi.h b/monetdb5/extras/rapi/rapi.h
--- a/monetdb5/extras/rapi/rapi.h
+++ b/monetdb5/extras/rapi/rapi.h
@@ -35,7 +35,7 @@ rapi_export str RAPIevalStd(Client cntxt
                InstrPtr pci);
 rapi_export str RAPIevalAggr(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
                InstrPtr pci);
-
+rapi_export void* RAPIloopback(void *query);
 rapi_export str RAPIprelude(void *ret);
 
 rapi_export void writeConsoleEx(const char * buf, int buflen, int foo);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to