Changeset: 6ef63ca909ae for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6ef63ca909ae Added Files: monetdb5/extras/rapi/Tests/rapi10.stable.err monetdb5/extras/rapi/Tests/rapi10.stable.out Modified Files: monetdb5/extras/rapi/Makefile.ag monetdb5/extras/rapi/Tests/rapi10.malC monetdb5/extras/rapi/converters.c.h monetdb5/extras/rapi/rapi.R monetdb5/extras/rapi/rapi.c Branch: default Log Message:
rapi loopback functional diffs (290 lines): diff --git a/monetdb5/extras/rapi/Makefile.ag b/monetdb5/extras/rapi/Makefile.ag --- a/monetdb5/extras/rapi/Makefile.ag +++ b/monetdb5/extras/rapi/Makefile.ag @@ -10,7 +10,13 @@ INCLUDES = \ ../../../gdk \ ../../mal \ ../../modules/kernel \ + ../../modules/atoms \ + ../../modules/mal \ + ../../../sql/common \ ../../../sql/include \ + ../../../sql/server \ + ../../../sql/storage \ + ../../../sql/backends/monet5 \ $(libr_CFLAGS) MTSAFE diff --git a/monetdb5/extras/rapi/Tests/rapi10.malC b/monetdb5/extras/rapi/Tests/rapi10.malC --- a/monetdb5/extras/rapi/Tests/rapi10.malC +++ b/monetdb5/extras/rapi/Tests/rapi10.malC @@ -1,3 +1,6 @@ +r1:bat[:oid,:int] := rapi.eval(nil:ptr,"loopback_query(\"select cast(42 as integer)\")[[1]]"); +io.print(r1); -r:bat[:oid,:str] := rapi.eval(nil:ptr,"loopback_query('select * from tables;')"); -io.print(r); + +r2:bat[:oid,:str] := rapi.eval(nil:ptr,"loopback_query(\"select 'a' as str union all select 'b' as str\")$str"); +io.print(r2); diff --git a/monetdb5/extras/rapi/Tests/rapi10.stable.err b/monetdb5/extras/rapi/Tests/rapi10.stable.err new file mode 100644 --- /dev/null +++ b/monetdb5/extras/rapi/Tests/rapi10.stable.err @@ -0,0 +1,36 @@ +stderr of test 'rapi10` in directory 'monetdb5/extras/rapi` itself: + + +# 10:06:54 > +# 10:06:54 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=36192" "--set" "mapi_usock=/var/tmp/mtest-42962/.s.monetdb.36192" "--set" "monet_prompt=" "--forcemito" "--dbpath=/tmp/fuckit/var/MonetDB/mTests_monetdb5_extras_rapi" "--set" "embedded_r=yes" "--set" "embedded_py=true" +# 10:06:54 > + +# builtin opt gdk_dbpath = /tmp/fuckit/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 36192 +# cmdline opt mapi_usock = /var/tmp/mtest-42962/.s.monetdb.36192 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /tmp/fuckit/var/MonetDB/mTests_monetdb5_extras_rapi +# cmdline opt embedded_r = yes +# cmdline opt embedded_py = true +# cmdline opt gdk_debug = 536870922 + +# 10:06:55 > +# 10:06:55 > "mclient" "-lmal" "-ftest" "-Eutf-8" "--host=/var/tmp/mtest-42962" "--port=36192" +# 10:06:55 > + + +# 10:06:55 > +# 10:06:55 > "Done." +# 10:06:55 > + diff --git a/monetdb5/extras/rapi/Tests/rapi10.stable.out b/monetdb5/extras/rapi/Tests/rapi10.stable.out new file mode 100644 --- /dev/null +++ b/monetdb5/extras/rapi/Tests/rapi10.stable.out @@ -0,0 +1,80 @@ +stdout of test 'rapi10` in directory 'monetdb5/extras/rapi` itself: + + +# 10:06:54 > +# 10:06:54 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=36192" "--set" "mapi_usock=/var/tmp/mtest-42962/.s.monetdb.36192" "--set" "monet_prompt=" "--forcemito" "--dbpath=/tmp/fuckit/var/MonetDB/mTests_monetdb5_extras_rapi" "--set" "embedded_r=yes" "--set" "embedded_py=true" +# 10:06:54 > + +# MonetDB 5 server v11.24.0 +# This is an unreleased version +# Serving database 'mTests_monetdb5_extras_rapi', using 4 threads +# Compiled for x86_64-apple-darwin15.5.0/64bit with 64bit OIDs and 128bit integers dynamically linked +# Found 16.000 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://dakar.da.cwi.nl:36192/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-42962/.s.monetdb.36192 +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded +# MonetDB/R module loaded + +Ready. +# SQL catalog created, loading sql scripts once +# loading sql script: 09_like.sql +# loading sql script: 10_math.sql +# loading sql script: 11_times.sql +# loading sql script: 12_url.sql +# loading sql script: 13_date.sql +# loading sql script: 14_inet.sql +# loading sql script: 15_querylog.sql +# loading sql script: 16_tracelog.sql +# loading sql script: 17_temporal.sql +# loading sql script: 18_index.sql +# loading sql script: 20_vacuum.sql +# loading sql script: 21_dependency_functions.sql +# loading sql script: 22_clients.sql +# loading sql script: 23_skyserver.sql +# loading sql script: 24_zorder.sql +# loading sql script: 25_debug.sql +# loading sql script: 26_sysmon.sql +# loading sql script: 27_rejects.sql +# loading sql script: 39_analytics.sql +# loading sql script: 39_analytics_hge.sql +# loading sql script: 40_geom.sql +# loading sql script: 40_json.sql +# loading sql script: 40_json_hge.sql +# loading sql script: 41_md5sum.sql +# loading sql script: 45_uuid.sql +# loading sql script: 46_gsl.sql +# loading sql script: 46_profiler.sql +# loading sql script: 51_sys_schema_extension.sql +# loading sql script: 72_fits.sql +# loading sql script: 75_storagemodel.sql +# loading sql script: 80_statistics.sql +# loading sql script: 80_udf.sql +# loading sql script: 80_udf_hge.sql +# loading sql script: 90_generator.sql +# loading sql script: 90_generator_hge.sql +# loading sql script: 99_system.sql + +# 10:06:55 > +# 10:06:55 > "mclient" "-lmal" "-ftest" "-Eutf-8" "--host=/var/tmp/mtest-42962" "--port=36192" +# 10:06:55 > + +#--------------------------# +# h t # name +# void int # type +#--------------------------# +[ 0@0, 42 ] +#--------------------------# +# h t # name +# void str # type +#--------------------------# +[ 0@0, "a" ] +[ 1@0, "b" ] + +# 10:12:06 > +# 10:12:06 > "Done." +# 10:12:06 > + diff --git a/monetdb5/extras/rapi/converters.c.h b/monetdb5/extras/rapi/converters.c.h --- a/monetdb5/extras/rapi/converters.c.h +++ b/monetdb5/extras/rapi/converters.c.h @@ -1,3 +1,6 @@ +#define RSTR(somestr) mkCharCE(somestr, CE_UTF8) + + #define BAT_TO_SXP(bat,tpe,retsxp,newfun,ptrfun,ctype,naval,memcopy)\ do { \ tpe v; size_t j; \ @@ -115,7 +118,7 @@ static SEXP bat_to_sexp(BAT* b) { if (strcmp(t, str_nil) == 0) { sexp_ptrs[offset] = NA_STRING; } else { - sexp_ptrs[offset] = mkCharCE(t, CE_UTF8); + sexp_ptrs[offset] = RSTR(t); } } SET_STRING_ELT(varvalue, j++, sexp_ptrs[offset]); @@ -125,8 +128,8 @@ static SEXP bat_to_sexp(BAT* b) { else { if (b->T->nonil) { BATloop(b, p, q) { - SET_STRING_ELT(varvalue, j++, mkCharCE( - (const char *) BUNtail(li, p), CE_UTF8)); + SET_STRING_ELT(varvalue, j++, RSTR( + (const char *) BUNtail(li, p))); } } else { @@ -135,7 +138,7 @@ static SEXP bat_to_sexp(BAT* b) { if (strcmp(t, str_nil) == 0) { SET_STRING_ELT(varvalue, j++, NA_STRING); } else { - SET_STRING_ELT(varvalue, j++, mkCharCE(t, CE_UTF8)); + SET_STRING_ELT(varvalue, j++, RSTR(t)); } } } 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 @@ -54,5 +54,17 @@ rm(rewireFunc) loopback_query <- function(query) { dyn.load(file.path(MONETDB_BINDIR, "..", "lib", "monetdb5", "lib_rapi.so")) - .Call("RAPIloopback", query, package="lib_rapi") + res <- .Call("RAPIloopback", paste0(query, "\n;"), package="lib_rapi") + if (is.character(res)) { + stop(res) + } + if (is.logical(res)) { # no result set, but successful + return(data.frame()) + } + if (is.list(res)) { + attr(res, "row.names") <- c(NA_integer_, length(res[[1]])) + class(res) <- "data.frame" + names(res) <- gsub("\\", "", names(res), fixed=T) + return(res) + } } 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 @@ -18,6 +18,7 @@ #include "gdk.h" #include "mmath.h" #include "sql_catalog.h" +#include "sql_execute.h" #include "rapi.h" // R headers @@ -63,6 +64,8 @@ static char* rtypenames[] = { "NIL", "SY "INT", "REAL", "CPLX", "STR", "DOT", "ANY", "VEC", "EXPR", "BCODE", "EXTPTR", "WEAKREF", "RAW", "S4" }; +static Client rapiClient = NULL; + // helper function to translate R TYPEOF() return values to something readable char* rtypename(int rtypeid) { @@ -247,8 +250,7 @@ str RAPIeval(Client cntxt, MalBlkPtr mb, node * argnode; int seengrp = FALSE; - // we don't need no context, but the compiler needs us to touch it (...) - (void) cntxt; + rapiClient = cntxt; if (!RAPIEnabled()) { throw(MAL, "rapi.eval", @@ -445,8 +447,32 @@ str RAPIeval(Client cntxt, MalBlkPtr mb, } void* RAPIloopback(void *query) { - //FIXME actually do something - return (void*) ScalarString(mkCharCE((char*)CHAR(STRING_ELT((SEXP) query, 0)), CE_UTF8)); + res_table* output = NULL; + char* querystr = (char*)CHAR(STRING_ELT(query, 0)); + char* err = SQLstatementIntern(rapiClient, &querystr, "name", 1, 0, &output); + + if (err) { // there was an error + return ScalarString(RSTR(err)); + } + if (output && output->nr_cols > 0) { + int i, ncols = output->nr_cols; + SEXP retlist, names, varvalue = R_NilValue; + retlist = PROTECT(allocVector(VECSXP, ncols)); + names = PROTECT(NEW_STRING(ncols)); + for (i = 0; i < ncols; i++) { + if (!(varvalue = bat_to_sexp(BATdescriptor(output->cols[i].b)))) { + UNPROTECT(i + 3); + return ScalarString(RSTR("Conversion error")); + } + SET_STRING_ELT(names, i, RSTR(output->cols[i].name)); + SET_VECTOR_ELT(retlist, i, varvalue); + } + res_table_destroy(output); + SET_NAMES(retlist, names); + UNPROTECT(ncols + 2); + return retlist; + } + return ScalarLogical(1); } @@ -464,7 +490,7 @@ 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); + Rf_defineVar(Rf_install("MONETDB_BINDIR"), ScalarString(RSTR(BINDIR)), R_GlobalEnv); } MT_lock_unset(&rapiLock); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list