Changeset: 12a873bfba25 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=12a873bfba25
Added Files:
        clients/R/MonetDB.R/src/mapisplit-r.c
        clients/R/MonetDB.R/src/mapisplit.h
        clients/R/MonetDB.R/src/profiler.h
Modified Files:
        clients/R/MonetDB.R/src/mapisplit.c
        clients/R/MonetDB.R/src/profiler.c
Branch: default
Log Message:

R Connector: more splitting for mclient's benefit


diffs (211 lines):

diff --git a/clients/R/MonetDB.R/src/mapisplit-r.c 
b/clients/R/MonetDB.R/src/mapisplit-r.c
new file mode 100644
--- /dev/null
+++ b/clients/R/MonetDB.R/src/mapisplit-r.c
@@ -0,0 +1,54 @@
+#include <assert.h>
+
+#include <R.h>
+#include <Rdefines.h>
+
+void mapi_line_split(char* line, char** out, size_t ncols);
+
+char nullstr[] = "NULL";
+SEXP mapi_split(SEXP mapiLinesVector, SEXP numCols) {
+       assert(TYPEOF(mapiLinesVector) == CHARSXP);
+
+       int cols = INTEGER_POINTER(AS_INTEGER(numCols))[0];
+       int rows = LENGTH(mapiLinesVector);
+
+       assert(rows > 0);
+       assert(cols > 0);
+
+       SEXP colVec;
+       PROTECT(colVec = NEW_LIST(cols));
+
+       int col;
+       for (col = 0; col < cols; col++) {
+               SEXP colV = PROTECT(NEW_STRING(rows));
+               assert(TYPEOF(colV) == STRSXP);
+               SET_ELEMENT(colVec, col, colV);
+               UNPROTECT(1);
+       }
+
+       int cRow;
+       int cCol;
+       char* elems[cols];
+
+       for (cRow = 0; cRow < rows; cRow++) {
+               const char *rval = CHAR(STRING_ELT(mapiLinesVector, cRow));
+               char *val = strdup(rval);
+               cCol = 0;
+               mapi_line_split(val, elems, cols);
+
+               for (cCol = 0; cCol < cols; cCol++) {
+                       SEXP colV = VECTOR_ELT(colVec, cCol);
+                       size_t tokenLen = strlen(elems[cCol]);
+                       if (tokenLen < 1 || strcmp(elems[cCol], nullstr) == 0) {
+                               SET_STRING_ELT(colV, cRow, NA_STRING);
+                       }
+                       else {
+                               SET_STRING_ELT(colV, cRow, 
mkCharLen(elems[cCol], tokenLen));
+                       }
+               }
+               free(val);
+       }
+
+       UNPROTECT(1);
+       return colVec;
+}
diff --git a/clients/R/MonetDB.R/src/mapisplit.c 
b/clients/R/MonetDB.R/src/mapisplit.c
--- a/clients/R/MonetDB.R/src/mapisplit.c
+++ b/clients/R/MonetDB.R/src/mapisplit.c
@@ -1,6 +1,7 @@
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
+#include "mapisplit.h"
 
 typedef enum {
        INQUOTES, ESCAPED, INTOKEN, INCRAP
@@ -22,7 +23,7 @@ void mapi_unescape(char* in, char* out) 
 }
 
 void mapi_line_split(char* line, char** out, size_t ncols) {
-       int cCol = 0;
+       size_t cCol = 0;
        int tokenStart = 2;
        int endQuote = 0;
        int curPos;
diff --git a/clients/R/MonetDB.R/src/mapisplit.h 
b/clients/R/MonetDB.R/src/mapisplit.h
new file mode 100644
--- /dev/null
+++ b/clients/R/MonetDB.R/src/mapisplit.h
@@ -0,0 +1,2 @@
+void mapi_unescape(char* in, char* out);
+void mapi_line_split(char* line, char** out, size_t ncols);
diff --git a/clients/R/MonetDB.R/src/profiler.c 
b/clients/R/MonetDB.R/src/profiler.c
--- a/clients/R/MonetDB.R/src/profiler.c
+++ b/clients/R/MonetDB.R/src/profiler.c
@@ -22,6 +22,9 @@
 #include <netinet/in.h>
 #endif
 
+#include "mapisplit.h"
+#include "profiler.h"
+
 // trace output format and columns
 #define TRACE_NCOLS 14
 #define TRACE_COL_QUERYID 2
@@ -42,25 +45,14 @@ static char* profiler_symb_trans = "V";
 static char* profiler_symb_bfree = "_";
 static char* profiler_symb_bfull = "#";
 
-int strupp(char *s) {
-    int i;
+static int profiler_strupp(char *s) {
+    size_t i;
     for (i = 0; i < strlen(s); i++)
         s[i] = toupper(s[i]);
     return i;
 }
 
 /* standalone MAL function call parser */
-typedef enum {
-       ASSIGNMENT, FUNCTION, PARAM, QUOTED, ESCAPED
-} mal_statement_state;
-
-typedef struct {
-       char* assignment;
-       char* function;
-       unsigned short nparams;
-       char** params;
-} mal_statement;
-
 void mal_statement_split(char* stmt, mal_statement *out, size_t maxparams) {
        #define TRIM(str) \
        while (str[0] == ' ' || str[0] == '"') str++; endPos = curPos - 1; \
@@ -117,23 +109,19 @@ void mal_statement_split(char* stmt, mal
                                break;
                        }
                        if (chr == '\\') {
-                               state = ESCAPED;
+                               state = ESCAPEDP;
                                break;
                        }
                        break;
 
-               case ESCAPED:
+               case ESCAPEDP:
                        state = QUOTED;
                        break;
                }
        }
 }
 
-// from mapisplit.c, the trace tuple format is similar(*) to the mapi tuple 
format
-void mapi_line_split(char* line, char** out, size_t ncols);
-void mapi_unescape(char* in, char* out);
-
-unsigned long profiler_tsms() {
+static unsigned long profiler_tsms() {
        unsigned long ret = 0;
        struct timeval tv;
        gettimeofday(&tv, NULL);
@@ -167,7 +155,8 @@ void profiler_renderbar(size_t state, si
        fflush(stdout);
 }
 
-void *profiler_thread() {
+static void* profiler_thread(void* params) {
+       params = (void*) params;
        char buf[BUFSIZ];
        char* elems[TRACE_NCOLS];
        // query ids are unlikely to be longer than BUFSIZ
@@ -231,7 +220,6 @@ void *profiler_thread() {
                }
                }
        }
-       return NULL;
 }
 
 void profiler_renderbar_dl(int* state, int* total) {
@@ -265,7 +253,7 @@ int profiler_start() {
 
        // some nicer characters for UTF-enabled terminals
        char* ctype = getenv("LC_CTYPE");
-       strupp(ctype);
+       profiler_strupp(ctype);
        if (strstr(ctype, "UTF-8") != NULL) {
                profiler_symb_query = "\u27F2";
                profiler_symb_trans = "\u2193";
@@ -274,6 +262,6 @@ int profiler_start() {
        }
 
        // start backgroud listening thread
-       pthread_create(&profiler_pthread, NULL, profiler_thread, NULL);
+       pthread_create(&profiler_pthread, NULL, &profiler_thread, NULL);
        return ntohs(serv_addr.sin_port);
 }
diff --git a/clients/R/MonetDB.R/src/profiler.h 
b/clients/R/MonetDB.R/src/profiler.h
new file mode 100644
--- /dev/null
+++ b/clients/R/MonetDB.R/src/profiler.h
@@ -0,0 +1,17 @@
+typedef enum {
+       ASSIGNMENT, FUNCTION, PARAM, QUOTED, ESCAPEDP
+} mal_statement_state;
+
+typedef struct {
+       char* assignment;
+       char* function;
+       unsigned short nparams;
+       char** params;
+} mal_statement;
+
+void mal_statement_split(char* stmt, mal_statement *out, size_t maxparams);
+void profiler_clearbar(void);
+void profiler_renderbar_dl(int* state, int* total);
+void profiler_arm(void);
+int profiler_start(void);
+void profiler_renderbar(size_t state, size_t total, char *symbol);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to