Changeset: 8fdfe3539408 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8fdfe3539408 Modified Files: clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/dplyr.R clients/R/MonetDB.R/man/monetdb.read.csv.Rd Branch: embedded Log Message:
various fixes to r client diffs (124 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 @@ -8,16 +8,17 @@ 1.0.0 - Fix for case when query only returns a prompt (CALL ..., Thanks, Roman) - Fix for empty result set on dbGetQuery(), no longer returning NULL (Thanks, Fabian) - Fix for dbConnect(), it ignored the url parameter somehow, which broke some sqlsurvey -- Added col.names argument to monet.read.csv() - Added lower.case.names argument to monet.read.csv() in case users want to avoid quoting (a bit) - Fix for dbConnect() that should be more robust to invalid connections - Cleaned up quoting behavior in dbListTables(), dbRemoveTable() etc. - Now re-establishing connection if interrupt (CMD-C or ESC) occurs - Fixed a bug in monetdb.read.csv for multiple CSV files without headers +- Added transactions to monetdb.read.csv so no empty tables are left over +- Removed nrows parameter to monetdb.read.csv +- Added col.names argument to monetdb.read.csv - dplyr src_monetdb now has a con parameter to pass an existing DBI connection - Fixed a bug when running in a non-UTF8 locale (Thanks, Marcis) - Fixed a bug when dbWriteTable would not adhere to transactional semantics -- Added transactions to monetdb.read.csv so no empty tables are left over - Fixed != comparisions in dplyr (Thanks, David) - New "mclient" function to get a shell-like DB interface - Support for running MonetDB in embedded mode (MonetDBLite) 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 @@ -392,13 +392,31 @@ setMethod("dbSendQuery", signature(conn= }) +reserved_monetdb_keywords <- c(.SQL92Keywords, +"ADMIN", "AFTER", "AGGREGATE", "ALWAYS", "ASYMMETRIC", "ATOMIC", +"AUTO_INCREMENT", "BEFORE", "BEST", "BIGINT", "BIGSERIAL", "BINARY", +"BLOB", "CALL", "CHAIN", "CLOB", "COMMITTED", "COPY", "CROSS", +"CURRENT_ROLE", "CURRENT_TIME", "CURRENT_USER", "DELIMITERS", +"DO", "EACH", "EFFORT", "ELSEIF", "ENCRYPTED", "EXCLUDE", "FOLLOWING", +"FUNCTION", "GENERATED", "HUGEINT", "IF", "ILIKE", "LIMIT", "LOCALTIME", +"LOCALTIMESTAMP", "LOCKED", "MERGE", "NATURAL", "NEW", "NOCYCLE", +"NOMAXVALUE", "NOMINVALUE", "OFFSET", "OLD", "ON", "OTHERS", +"OVER", "PARTITION", "PRECEDING", "RANGE", "RECORDS", "REFERENCING", +"REMOTE", "RENAME", "REPEATABLE", "REPLICA", "RESTART", "RETURN", +"RETURNS", "SAMPLE", "SAVEPOINT", "SEQUENCE", "SERIAL", "SERIALIZABLE", +"SESSION_USER", "SIMPLE", "SPLIT_PART", "STDIN", "STDOUT", "STREAM", +"SYMMETRIC", "TIES", "TINYINT", "TRIGGER", "UNBOUNDED", "UNCOMMITTED", +"UNENCRYPTED", "WHILE", "XMLAGG", "XMLATTRIBUTES", "XMLCOMMENT", +"XMLCONCAT", "XMLDOCUMENT", "XMLELEMENT", "XMLFOREST", "XMLNAMESPACES", +"XMLPARSE", "XMLPI", "XMLQUERY", "XMLSCHEMA", "XMLTEXT", "XMLVALIDATE") + # quoting quoteIfNeeded <- function(conn, x, warn=T, ...) { chars <- !grepl("^[a-z_][a-z0-9_]*$", x, perl=T) & !grepl("^\"[^\"]*\"$", x, perl=T) if (any(chars) && warn) { message("Identifier(s) ", paste("\"", x[chars],"\"", collapse=", ", sep=""), " contain uppercase or reserved SQL characters and need(s) to be quoted in queries.") } - reserved <- toupper(x) %in% .SQL92Keywords + reserved <- toupper(x) %in% reserved_monetdb_keywords if (any(reserved) && warn) { message("Identifier(s) ", paste("\"", x[reserved],"\"", collapse=", ", sep=""), " are reserved SQL keywords and need(s) to be quoted in queries.") } @@ -801,18 +819,14 @@ setMethod("dbGetInfo", "MonetDBResult", }, valueClass="list") # adapted from RMonetDB, no java-specific things in here... -monet.read.csv <- monetdb.read.csv <- function(conn, files, tablename, nrows=NA, header=TRUE, - locked=FALSE, na.strings="", nrow.check=500, +monet.read.csv <- monetdb.read.csv <- function(conn, files, tablename, header=TRUE, + locked=FALSE, best.effort=FALSE, na.strings="", nrow.check=500, delim=",", newline="\\n", quote="\"", create=TRUE, col.names=NULL, lower.case.names=FALSE, ...){ if (length(na.strings)>1) stop("na.strings must be of length 1") headers <- lapply(files, utils::read.csv, sep=delim, na.strings=na.strings, quote=quote, nrows=nrow.check, header=header, ...) - if (!missing(nrows)) { - warning("monetdb.read.csv(): nrows parameter is not neccessary any more and deprecated.") - } - if (length(files)>1){ nn <- sapply(headers, ncol) if (!all(nn==nn[1])) stop("Files have different numbers of columns") @@ -846,7 +860,7 @@ monet.read.csv <- monetdb.read.csv <- fu thefile <- normalizePath(files[i]) dbSendUpdate(conn, paste("COPY", if(header) "OFFSET 2", "INTO", tablename, "FROM", paste("'", thefile, "'", sep=""), delimspec, "NULL as", paste("'", - na.strings[1], "'", sep=""), if(locked) "LOCKED")) + na.strings[1], "'", sep=""), if(locked) "LOCKED", if(best.effort) "BEST EFFORT")) } dbGetQuery(conn, paste("SELECT COUNT(*) FROM", tablename))[[1]] dbCommit(conn) diff --git a/clients/R/MonetDB.R/R/dplyr.R b/clients/R/MonetDB.R/R/dplyr.R --- a/clients/R/MonetDB.R/R/dplyr.R +++ b/clients/R/MonetDB.R/R/dplyr.R @@ -1,4 +1,4 @@ -src_monetdb <- function(dbname, host = "localhost", port = 50000L, user = "monetdb", +src_monetdb <- function(dbname="demo", host = "localhost", port = 50000L, user = "monetdb", password = "monetdb", con = FALSE, ...) { if (!inherits(con, "MonetDBConnection") || !dbIsValid(con)) { con <- dbConnect(MonetDB.R(), dbname = dbname , host = host, port = port, diff --git a/clients/R/MonetDB.R/man/monetdb.read.csv.Rd b/clients/R/MonetDB.R/man/monetdb.read.csv.Rd --- a/clients/R/MonetDB.R/man/monetdb.read.csv.Rd +++ b/clients/R/MonetDB.R/man/monetdb.read.csv.Rd @@ -9,8 +9,8 @@ Instruct MonetDB to read a CSV file, optionally also create the table for it. } \usage{ - monetdb.read.csv (conn, files, tablename, nrows=NA, header=TRUE, - locked=FALSE, na.strings="", nrow.check=500, delim=",", + monetdb.read.csv (conn, files, tablename, header=TRUE, + locked=FALSE, best.effort=FALSE, na.strings="", nrow.check=500, delim=",", newline = "\\\\n", quote = "\"", create=TRUE, col.names=NULL, lower.case.names=FALSE, ...) } \arguments{ @@ -18,10 +18,10 @@ \code{\link[MonetDB.R]{MonetDB.R}} database driver.} \item{files}{A single string or a vector of strings containing the absolute file names of the CSV files to be imported.} \item{tablename}{Name of the database table the CSV files should be imported in. Created if necessary.} - \item{nrows}{Total number of rows to import (deprecated).} \item{header}{Whether or not the CSV files contain a header line.} \item{locked}{Whether or not to disable transactions for import. Setting this to TRUE can greatly improve the import performance.} + \item{best.effort}{Use best effort flag when reading csv files and continue importing even if parsing of fields/lines fails.} \item{na.strings}{Which string value to interpret as \code{NA} value.} \item{...}{Additional parameters. Currently not in use.} \item{nrow.check}{Amount of rows that should be read from the CSV when the _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list