Changeset: 6a1e7f79e1f5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6a1e7f79e1f5
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_scenario.c
        sql/storage/bat/res_table.c
        tools/embedded/embedded.c
        tools/embedded/embedded.h
        tools/reverserapi/NAMESPACE
        tools/reverserapi/R/monetdb.R
        tools/reverserapi/configure
Branch: embedded
Log Message:

No output to stdout/stderr if all goes well and scalar value support 
(Auto-BAT-Boxing)


diffs (239 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3143,11 +3143,15 @@ mvc_scalar_value_wrap(Client cntxt, MalB
        if ((msg = checkSQLContext(cntxt)) != NULL)
                return msg;
        b = cntxt->sqlcontext;
+       if (ATOMextern(mtype))
+               p = *(ptr *) p;
+
+       // scalar values are single-column result sets
+       mvc_result_table(b->mvc, 1, 1, NULL);
+       mvc_result_value(b->mvc, *tn, *cn, *type, *digits, *scale, p, mtype);
        if (b->output_format == OFMT_NONE) {
                return MAL_SUCCEED;
        }
-       if (ATOMextern(mtype))
-               p = *(ptr *) p;
        if (b->out == NULL || mvc_export_value(b, b->out, 1, *tn, *cn, *type, 
*digits, *scale, *eclass, p, mtype, "", "NULL") != SQL_OK)
                throw(SQL, "sql.exportValue", "failed");
        return MAL_SUCCEED;
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -178,8 +178,8 @@ SQLprelude(void *ret)
        tmp = SQLinit();
        if (tmp != MAL_SUCCEED)
                return (tmp);
-       fprintf(stdout, "# MonetDB/SQL module loaded\n");
-       fflush(stdout);         /* make merovingian see this *now* */
+       mnstr_printf(GDKout, "# MonetDB/SQL module loaded\n");
+       mnstr_flush(GDKout);    /* make merovingian see this *now* */
 
        /* only register availability of scenarios AFTER we are inited! */
        s->name = "sql";
@@ -481,7 +481,7 @@ SQLinitClient(Client c)
                if (fullname) {
                        str filename = fullname;
                        str p, n;
-                       fprintf(stdout, "# SQL catalog created, loading sql 
scripts once\n");
+                       mnstr_printf(GDKout, "# SQL catalog created, loading 
sql scripts once\n");
                        do {
                                p = strchr(filename, PATH_SEP);
                                if (p)
@@ -491,7 +491,7 @@ SQLinitClient(Client c)
                                } else {
                                        n++;
                                }
-                               fprintf(stdout, "# loading sql script: %s\n", 
n);
+                               mnstr_printf(GDKout, "# loading sql script: 
%s\n", n);
                                fd = open_rastream(filename);
                                if (p)
                                        filename = p + 1;
diff --git a/sql/storage/bat/res_table.c b/sql/storage/bat/res_table.c
--- a/sql/storage/bat/res_table.c
+++ b/sql/storage/bat/res_table.c
@@ -52,6 +52,7 @@ res_col *
 res_col_create(sql_trans *tr, res_table *t, const char *tn, const char *name, 
const char *typename, int digits, int scale, int mtype, void *val)
 {
        res_col *c = t->cols + t->cur_col;
+       BAT *b;
 
        if (!sql_find_subtype(&c->type, typename, digits, scale)) 
                sql_init_subtype(&c->type, sql_trans_bind_type(tr, NULL, 
typename), digits, scale);
@@ -61,13 +62,17 @@ res_col_create(sql_trans *tr, res_table 
        c->p = NULL;
        c->mtype = mtype;
        if (mtype == TYPE_bat) {
-               BAT *b = (BAT*)val;
-
-               c->b = b->batCacheid;
-               bat_incref(c->b);
-       } else {
-               c->p = ATOMdup(mtype, val);
+               b = (BAT*)val;
+       } else { // wrap scalar values in BATs for result consistency
+               b = BATnew(TYPE_void, mtype, 0, TRANSIENT);
+               assert (b != NULL);
+               BUNappend(b, val, FALSE);
+               BATsetcount(b, 1);
+               BATseqbase(b, 0);
+               BATsettrivprop(b);
        }
+       c->b = b->batCacheid;
+       bat_incref(c->b);
        t->cur_col++;
        assert(t->cur_col <= t->nr_cols);
        return c;
diff --git a/tools/embedded/embedded.c b/tools/embedded/embedded.c
--- a/tools/embedded/embedded.c
+++ b/tools/embedded/embedded.c
@@ -40,7 +40,7 @@ SQLstatementIntern_ptr_tpe SQLstatementI
 typedef void (*res_table_destroy_ptr_tpe)(res_table *t);
 res_table_destroy_ptr_tpe res_table_destroy_ptr = NULL;
 
-bit monetdb_embedded_initialized = 0;
+static bit monetdb_embedded_initialized = 0;
 static MT_Lock monetdb_embedded_lock;
 
 static void* lookup_function(char* lib, char* func) {
@@ -54,7 +54,7 @@ static void* lookup_function(char* lib, 
        return fun;
 }
 
-int monetdb_startup(char* dir) {
+int monetdb_startup(char* dir, char silent) {
        opt *set = NULL;
        int setlen = 0;
        int retval = -1;
@@ -66,25 +66,27 @@ int monetdb_startup(char* dir) {
 
        setlen = mo_builtin_settings(&set);
        setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_dbpath", dir);
-       if (GDKinit(set, setlen) == 0) goto cleanup;
+       if (GDKinit(set, setlen) == 0)  goto cleanup;
 
        snprintf(mod_path, 1000, "%s/../lib/monetdb5", BINDIR);
        GDKsetenv("monet_mod_path", mod_path);
        GDKsetenv("mapi_disable", "true");
        GDKsetenv("max_clients", "0");
 
+       if (silent) {
+               THRdata[0] = stream_blackhole_create();
+       }
        msab_dbpathinit(GDKgetenv("gdk_dbpath"));
+
        if (mal_init() != 0) goto cleanup;
-
-       // hide output on client out
-       mal_clients[0].fdout = stream_blackhole_create();
-
+       if (silent) {
+               mal_clients[0].fdout = THRdata[0];
+       }
        // This dynamically looks up functions, because the library containing 
them is loaded at runtime.
        SQLstatementIntern_ptr = (SQLstatementIntern_ptr_tpe) 
lookup_function("lib_sql",  "SQLstatementIntern");
        res_table_destroy_ptr  = (res_table_destroy_ptr_tpe)  
lookup_function("libstore", "res_table_destroy");
        if (SQLstatementIntern_ptr == NULL || res_table_destroy_ptr == NULL) 
goto cleanup;
 
-
        monetdb_embedded_initialized = true;
        // sanity check, run a SQL query
        if (monetdb_query("SELECT * FROM tables;") == NULL) {
@@ -104,7 +106,7 @@ void* monetdb_query(char* query) {
        res_table* output = NULL;
        Client c = &mal_clients[0];
        if (!monetdb_embedded_initialized) {
-               fprintf(stderr, "! Embedded MonetDB is not initialized. Call 
monetdb_startup() first.\n");
+               fprintf(stderr, "Embedded MonetDB is not started.\n");
                return NULL;
        }
 
@@ -214,11 +216,12 @@ SEXP monetdb_query_R(SEXP query) {
 
 }
 
-SEXP monetdb_startup_R(SEXP dirsexp) {
+SEXP monetdb_startup_R(SEXP dirsexp, SEXP silentsexp) {
+       if (!IS_CHARACTER(dirsexp) || !IS_LOGICAL(silentsexp)) {
+               return ScalarInteger(-1);
+       }
        const char* dir = CHAR(STRING_ELT(dirsexp, 0));
-       int res = monetdb_startup((char*) dir);
-       SEXP retsxp = PROTECT(NEW_INTEGER(1));
-       INTEGER_POINTER(retsxp)[0] = res;
-       UNPROTECT(1);
-       return retsxp;
+       char silent = LOGICAL(silentsexp)[0];
+       int res = monetdb_startup((char*) dir, silent);
+       return ScalarInteger(res);
 }
diff --git a/tools/embedded/embedded.h b/tools/embedded/embedded.h
--- a/tools/embedded/embedded.h
+++ b/tools/embedded/embedded.h
@@ -15,10 +15,10 @@
 
 #include <Rdefines.h>
 
-int monetdb_startup(char* dir);
+int monetdb_startup(char* dir, char silent);
 void* monetdb_query(char* query);
 void monetdb_cleanup_result(void* output);
-SEXP monetdb_query_R(SEXP query);
-SEXP monetdb_startup_R(SEXP dir);
+SEXP monetdb_query_R(SEXP querysexp);
+SEXP monetdb_startup_R(SEXP dirsexp, SEXP silentsexp);
 
 #endif
diff --git a/tools/reverserapi/NAMESPACE b/tools/reverserapi/NAMESPACE
--- a/tools/reverserapi/NAMESPACE
+++ b/tools/reverserapi/NAMESPACE
@@ -1,3 +1,3 @@
 useDynLib(MonetDB)
-export(monetdb_startup)
-export(monetdb_query)
+export(monetdb_embedded_startup)
+export(monetdb_embedded_query)
diff --git a/tools/reverserapi/R/monetdb.R b/tools/reverserapi/R/monetdb.R
--- a/tools/reverserapi/R/monetdb.R
+++ b/tools/reverserapi/R/monetdb.R
@@ -2,8 +2,9 @@
        dyn.load(file.path(libname, pkgname, "libs", "MonetDB.so"), local=F, 
now=F)
 }
 
-monetdb_startup <- function(dir=tempdir()) {
+monetdb_embedded_startup <- function(dir=tempdir(), quiet=T) {
        dir <- as.character(dir)
+       quiet <- as.logical(quiet)
        if (length(dir) != 1) {
                stop("Need a single directory name as parameter.")
        }
@@ -13,10 +14,14 @@ monetdb_startup <- function(dir=tempdir(
        if (file.access(dir, mode=2) < 0) {
                stop("Cannot write to ", dir)
        }
-       invisible(.Call("monetdb_startup_R", dir))
+       res <- .Call("monetdb_startup_R", dir, quiet)
+       if (res < 0) {
+               stop("Failed to initialize embedded MonetDB.")
+       }
+       invisible(TRUE)
 }
 
-monetdb_query <- function(query) {
+monetdb_embedded_query <- function(query) {
        query <- as.character(query)
        if (length(query) != 1) {
                stop("Need a single query as parameter.")
diff --git a/tools/reverserapi/configure b/tools/reverserapi/configure
--- a/tools/reverserapi/configure
+++ b/tools/reverserapi/configure
@@ -8,6 +8,7 @@ CFLAGS="-I$R_INCLUDE_DIR" ./configure --
 --without-samtools --without-sphinxclient --without-geos --without-samtools 
--without-readline \
 --enable-optimize --enable-silent-rules
 
+
 # Dirty hack, normally R would call make, but we need to also do a make 
install to get the libs in place. 
 # So we do it ourselves instead and then render the MonetDB makefile inert.
 make -j clean install
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to