Changeset: 9fecf38c363e for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9fecf38c363e Added Files: sql/backends/monet5/bam/Tests/mergetable.SQL.py sql/backends/monet5/bam/Tests/mergetable.stable.err sql/backends/monet5/bam/Tests/mergetable.stable.out sql/backends/monet5/bam/Tests/sql/mergetable.sql sql/test/mergetables/Tests/emptymergequery.stable.err sql/test/mergetables/Tests/emptymergequery.stable.out sql/test/mergetables/Tests/mergeloadidx.sql sql/test/mergetables/Tests/mergeloadidx.stable.err sql/test/mergetables/Tests/mergeloadidx.stable.out Removed Files: clients/R/MonetDB.R/src/Makevars.win clients/R/MonetDB.R/src/mapi.c Modified Files: clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/mapi.R clients/R/Tests/dbi.R clients/R/Tests/dbi.stable.out clients/R/Tests/dplyr.R clients/R/Tests/survey.R clients/Tests/MAL-signatures_all.stable.out clients/Tests/MAL-signatures_all.stable.out.int128 clients/Tests/MAL-signatures_fits_geom.stable.out clients/Tests/MAL-signatures_fits_geom.stable.out.int128 clients/Tests/MAL-signatures_geom.stable.out clients/Tests/MAL-signatures_geom.stable.out.int128 clients/Tests/MAL-signatures_none.stable.out clients/Tests/MAL-signatures_none.stable.out.int128 clients/Tests/exports.stable.out gdk/gdk_firstn.c monetdb5/modules/kernel/bat5.mal monetdb5/modules/mal/Tests/inspect05.stable.out monetdb5/modules/mal/Tests/pqueue.stable.out monetdb5/modules/mal/Tests/pqueue2.stable.out monetdb5/modules/mal/mdb.c monetdb5/modules/mal/mdb.h monetdb5/optimizer/opt_mergetable.c monetdb5/tests/gdkTests/Tests/firstn.stable.out sql/backends/monet5/bam/Tests/All sql/backends/monet5/bam/bam_db_interface.h sql/backends/monet5/sql.c sql/backends/monet5/sql_result.c sql/backends/monet5/sql_scenario.c sql/backends/monet5/sql_scenario.h sql/backends/monet5/sql_statistics.c sql/backends/monet5/vaults/fits.c sql/server/rel_planner.c sql/server/rel_schema.c sql/server/rel_select.c sql/storage/sql_storage.h sql/storage/store.c sql/storage/store_dependency.c sql/test/mergetables/Tests/All sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out sql/test/testdb-upgrade/Tests/upgrade.stable.out Branch: HTM Log Message:
Merge with default branch diffs (truncated from 3698 to 300 lines): 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.6 +- Fixed non-ASCII character handling (thanks, Roman!) +- Fully removed C-based socket code + 0.9.5 - Removed package date (Thanks, Dimitar) - Added sys. schema name to internal queries, so SET SCHEMA xx would not break things (Thanks again, Dimitar) diff --git a/clients/R/MonetDB.R/R/dbi.R b/clients/R/MonetDB.R/R/dbi.R --- a/clients/R/MonetDB.R/R/dbi.R +++ b/clients/R/MonetDB.R/R/dbi.R @@ -1,12 +1,6 @@ +# C library that contains our MAPI string splitting state machine C_LIBRARY <- "MonetDB.R" -.onLoad <- function(lib, pkg) { - if (getOption("monetdb.clib", FALSE)) { - library.dynam( C_LIBRARY, pkg, lib ) - .Call("mapiInit", PACKAGE=C_LIBRARY) - } -} - # Make S4 aware of S3 classes setOldClass(c("sockconn", "connection", "monetdb_mapi_conn")) @@ -234,6 +228,8 @@ setMethod("dbSendQuery", signature(conn= } conn@connenv$exception <- list() env <- NULL + # Auto-convert? + # statement <- enc2utf8(statement) if (getOption("monetdb.debug.query", F)) message("QQ: '", statement, "'") resp <- .mapiParseResponse(.mapiRequest(conn, paste0("s", statement, ";"), async=async)) @@ -539,8 +535,10 @@ setMethod("dbFetch", signature(res="Mone col <- ct[[j]] if (col == .CT_NUM) df[[j]] <- as.numeric(parts[[j]]) - if (col == .CT_CHRR) + if (col == .CT_CHRR) { df[[j]] <- parts[[j]] + Encoding(df[[j]]) <- "UTF-8" + } if (col == .CT_BOOL) df[[j]] <- parts[[j]]=="true" if (col == .CT_CHR) { diff --git a/clients/R/MonetDB.R/R/mapi.R b/clients/R/MonetDB.R/R/mapi.R --- a/clients/R/MonetDB.R/R/mapi.R +++ b/clients/R/MonetDB.R/R/mapi.R @@ -86,20 +86,11 @@ REPLY_SIZE <- 100 # Apparently, -1 me .mapiConnect <- function(host, port, timeout) { - if (getOption("monetdb.clib", FALSE)) { - return(.Call("mapiConnect", host, port, timeout, PACKAGE=C_LIBRARY)) - } else { - return(socketConnection(host = host, port = port, blocking = TRUE, open="r+b", timeout = timeout)) - } + socketConnection(host = host, port = port, blocking = TRUE, open="r+b", timeout = timeout) } .mapiDisconnect <- function(socket) { - if (getOption("monetdb.clib", FALSE)) { - .Call("mapiDisconnect", socket, PACKAGE=C_LIBRARY) - } else { - # close, don't care about the errors... - tryCatch(close(socket), error=function(e){}, warning=function(w){}) - } + tryCatch(close(socket), error=function(e){}, warning=function(w){}) } .mapiCleanup <- function(conObj) { @@ -110,69 +101,48 @@ REPLY_SIZE <- 100 # Apparently, -1 me } .mapiRead <- function(con) { - if (getOption("monetdb.clib", FALSE)) { - if (!identical(class(con)[[1]], "externalptr")) - stop("I can only be called with a MonetDB connection object as parameter.") - respstr <- .Call("mapiRead", con, PACKAGE=C_LIBRARY) - if (getOption("monetdb.debug.mapi", F)) { - dstr <- respstr - if (nchar(dstr) > 300) { - dstr <- paste0(substring(dstr, 1, 200), "...", substring(dstr, nchar(dstr)-100, nchar(dstr))) - } - message("RX: '", dstr, "'") + if (!identical(class(con)[[1]], "sockconn")) + stop("I can only be called with a MonetDB connection object as parameter.") + resp <- list() + repeat { + unpacked <- readBin(con, "integer", n=1, size=2, signed=FALSE, endian="little") + + if (length(unpacked) == 0) { + stop("Empty response from MonetDB server, probably a timeout. You can increase the time to wait for responses with the 'timeout' parameter to 'dbConnect()'.") } - return(respstr) - } else { - # R implementation - if (!identical(class(con)[[1]], "sockconn")) - stop("I can only be called with a MonetDB connection object as parameter.") - resp <- list() - repeat { - unpacked <- readBin(con,"integer",n=1,size=2,signed=FALSE,endian="little") - - if (length(unpacked) == 0) { - stop("Empty response from MonetDB server, probably a timeout. You can increase the time to wait for responses with the 'timeout' parameter to 'dbConnect()'.") - } - - length <- bitwShiftR(unpacked,1) - final <- bitwAnd(unpacked,1) - - if (length == 0) break - resp <- c(resp,readChar(con, length, useBytes = TRUE)) - if (final == 1) break - } - if (getOption("monetdb.debug.mapi", F)) cat(paste("RX: '",substring(paste0(resp,collapse=""),1,200),"'\n",sep="")) - return(paste0("",resp,collapse="")) + + length <- bitwShiftR(unpacked, 1) + final <- bitwAnd(unpacked, 1) + + if (length == 0) break + # no raw handling here (see .mapiWrite), since server tells us the length in bytes already + resp <- c(resp, readChar(con, length, useBytes = TRUE)) + if (final == 1) break } + if (getOption("monetdb.debug.mapi", F)) cat(paste("RX: '", substring(paste0(resp, collapse=""), 1, 200), "'\n", sep="")) + return(paste0("", resp, collapse="")) } .mapiWrite <- function(con, msg) { - if (getOption("monetdb.clib", FALSE)) { - # C implementation - if (!identical(class(con)[[1]], "externalptr")) - stop("I can only be called with a MonetDB connection object as parameter.") - - if (getOption("monetdb.debug.mapi", F)) message("TX: '", msg, "'") - .Call("mapiWrite", con, msg, PACKAGE=C_LIBRARY) - - } else { - # R implementation - if (!identical(class(con)[[1]], "sockconn")) - stop("I can only be called with a MonetDB connection object as parameter.") - final <- FALSE - pos <- 0 - if (getOption("monetdb.debug.mapi", F)) message("TX: '",msg,"'\n",sep="") - while (!final) { - req <- substring(msg,pos+1,min(MAX_PACKET_SIZE, nchar(msg))+pos) - bytes <- nchar(req) - pos <- pos + bytes - final <- max(nchar(msg) - pos,0) == 0 - header <- as.integer(bitwOr(bitwShiftL(bytes,1),as.numeric(final))) - writeBin(header, con, 2,endian="little") - writeChar(req,con,bytes,useBytes=TRUE,eos=NULL) - } - flush(con) + # R implementation + if (!identical(class(con)[[1]], "sockconn")) + stop("I can only be called with a MonetDB connection object as parameter.") + final <- FALSE + pos <- 0 + if (getOption("monetdb.debug.mapi", F)) message("TX: '", msg, "'\n", sep="") + # convert to raw byte array, otherwise multibyte characters are 'difficult' + msgr <- charToRaw(msg) + msglen <- length(msgr) + while (!final) { + bytes <- min(MAX_PACKET_SIZE, msglen - pos) + reqr <- msgr[(pos + 1) : (pos + bytes)] + pos <- pos + bytes + final <- max(msglen - pos, 0) == 0 + header <- as.integer(bitwOr(bitwShiftL(bytes, 1), as.numeric(final))) + writeBin(header, con, 2, endian="little") + writeBin(reqr, con, endian="little") } + flush(con) return(NULL) } diff --git a/clients/R/MonetDB.R/src/Makevars.win b/clients/R/MonetDB.R/src/Makevars.win deleted file mode 100644 --- a/clients/R/MonetDB.R/src/Makevars.win +++ /dev/null @@ -1,1 +0,0 @@ -PKG_LIBS= -lws2_32 \ No newline at end of file diff --git a/clients/R/MonetDB.R/src/mapi.c b/clients/R/MonetDB.R/src/mapi.c deleted file mode 100644 --- a/clients/R/MonetDB.R/src/mapi.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * The contents of this file are subject to the MonetDB Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.monetdb.org/Legal/MonetDBLicense - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is the MonetDB Database System. - * - * The Initial Developer of the Original Code is CWI. - * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. - * Copyright August 2008-2014 MonetDB B.V. - * All Rights Reserved. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#ifdef __WIN32__ -#include <winsock2.h> -#include <ws2tcpip.h> -#undef ERROR -#else -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#endif -#include <assert.h> -#include <fcntl.h> -#include <errno.h> - -#ifndef SOCKET_ERROR -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 -#endif - -// R headers -#include <R.h> -#include <Rdefines.h> - -#define BLOCKSIZE 8190 -#define BUFSIZE BLOCKSIZE+1 -#define SOCKET int -#define TRUE 1 -#define FALSE 0 -#define ALLOCSIZE 1048576 // 1 MB -#define DEBUG FALSE - -// reference tricks taken from http://homepage.stat.uiowa.edu/~luke/R/simpleref.html#NWarqU3-KrSQa-1 -static SEXP MAPI_type_tag; - -#define CHECK_MAPI_SOCK(s) do { \ - if (TYPEOF(s) != EXTPTRSXP || \ - R_ExternalPtrTag(s) != MAPI_type_tag || \ - EXTPTR_PTR(s) == NULL) \ - error("Socket was either not successfully connected or is already closed. Either way, it cannot be used."); \ -} while (0) - -SEXP mapiInit(void) { - MAPI_type_tag = install("MAPI_TYPE_TAG"); -#ifdef __WIN32__ - // I will not even TRY to understand why this is required - WSADATA wsaData; - int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (iResult != 0) { - error("WSAStartup failed: %d", iResult); - } -#endif - return R_NilValue; -} - -SEXP mapiDisconnect(SEXP conn) { - if (TYPEOF(conn) != EXTPTRSXP || R_ExternalPtrTag(conn) != MAPI_type_tag) { - warning("trying to disconnect from a non-socket."); - return R_NilValue; - } - SOCKET *sock = R_ExternalPtrAddr(conn); - if (sock != NULL) { - shutdown(*sock, 2); - R_ClearExternalPtr(conn); - free(sock); - } - return R_NilValue; -} - -SEXP mapiConnect(SEXP host, SEXP port, SEXP timeout) { - // be a bit paranoid about the parameters - assert(IS_CHARACTER(host)); - assert(GET_LENGTH(host) == 1); - assert(IS_INTEGER(port)); - assert(GET_LENGTH(port) == 1); - assert(IS_INTEGER(timeout)); - assert(GET_LENGTH(timeout) == 1); - - const char *hostval = CHAR(STRING_ELT(host, 0)); - const int portval = INTEGER_POINTER(AS_INTEGER(port))[0]; - const int timeoutval = INTEGER_POINTER(AS_INTEGER(port))[0]; - - assert(strlen(hostval) > 0); - assert(portval > 0 && portval < 65535); - assert(timeoutval > 0); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list