Skip to content

Commit f523b4a

Browse files
committed
Migrated to RCpp
1 parent dbd2d7e commit f523b4a

25 files changed

Lines changed: 653 additions & 503 deletions

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Depends:
1313
DBI (>= 0.3.1)
1414
Imports:
1515
methods,
16-
assertthat
16+
assertthat,
17+
Rcpp
1718
Description: The EXASOL R Package offers interface functionality such as
1819
connecting to, querying and writing into an EXASOL Database (version 7.1
1920
onwards) via a native WebSocket protocol. It is optimised for massively
@@ -33,11 +34,12 @@ Suggests:
3334
testthat,
3435
DBItest,
3536
xml2
36-
LinkingTo: testthat
37+
LinkingTo: testthat, Rcpp
3738
SystemRequirements: OpenSSL >= 1.0.1, EXASOL DB v7.1 onwards
3839
RoxygenNote: 7.1.2
3940
Encoding: UTF-8
4041
Collate:
42+
'RcppExports.R'
4143
'EXADBI-object.R'
4244
'EXADBI-driver.R'
4345
'EXADBI-connection.R'

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ importFrom(utils,packageName)
7171
importFrom(utils,packageVersion)
7272
importFrom(utils,read.csv)
7373
importFrom(utils,write.table)
74-
useDynLib(exasol, .registration = TRUE, .fixes = "C_")
74+
importFrom(Rcpp, evalCpp)
75+
useDynLib(exasol, .registration = TRUE)

R/EXADBI-connection.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ setMethod(
140140
#' @export
141141
dbCurrentSchema <- function(con, setSchema=NULL) {
142142
if(!missing(setSchema)) {
143-
.Call(C_exaWsExecute, con@ws_handle, paste("open schema", processIDs(setSchema)))
143+
exaWsExecute(con@ws_handle, paste("open schema", processIDs(setSchema)))
144144
con@current_schema <- setSchema
145145
} else {
146-
res <- .Call(C_exaWsExecute, con@ws_handle, "select current_schema")
146+
res <- exaWsExecute(con@ws_handle, "select current_schema")
147147
if (!is.null(res$data) && length(res$data) > 0 && length(res$data[[1]]) > 0) {
148148
con@current_schema <- as.character(res$data[[1]][1])
149149
}
@@ -171,16 +171,16 @@ dbCurrentSchema <- function(con, setSchema=NULL) {
171171

172172
useTls <- (encryption == "Y")
173173

174-
result <- .Call(C_exaWsConnect, host, port, useTls, uid, pwd, 3L)
174+
result <- exaWsConnect(host, port, useTls, uid, pwd, 3L)
175175

176176
if (!is.na(schema) && nchar(schema) > 0 && schema != "SYS") {
177-
.Call(C_exaWsExecute, result$handle, paste("OPEN SCHEMA", processIDs(schema)))
177+
exaWsExecute(result$handle, paste("OPEN SCHEMA", processIDs(schema)))
178178
}
179179

180180
autocommit_json <- ifelse(autocommit == "Y",
181181
'{"autocommit":true}',
182182
'{"autocommit":false}')
183-
.Call(C_exaWsSetAttributes, result$handle, autocommit_json)
183+
exaWsSetAttributes(result$handle, autocommit_json)
184184

185185
res <- new("EXAConnection",
186186
ws_handle = result$handle,
@@ -241,7 +241,7 @@ setMethod(
241241
}, error = function(e) {
242242
warning(paste0("Error closing connection pane:\n'", conditionMessage(e), "'"))
243243
})
244-
.Call(C_exaWsDisconnect, conn@ws_handle)
244+
exaWsDisconnect(conn@ws_handle)
245245
invisible(TRUE)
246246
}
247247
)

R/EXADBI-query.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NULL
77
## On error, raises an R error (if errors=TRUE) or returns -1 (if errors=FALSE).
88
.wsExecuteQuery <- function(con, sql, errors = TRUE) {
99
tryCatch({
10-
.Call(C_exaWsExecute, con@ws_handle, sql)
10+
exaWsExecute(con@ws_handle, sql)
1111
}, error = function(e) {
1212
if (errors) stop(e)
1313
return(-1)

R/EXADBI-transaction.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NULL
1717
#' @export
1818
setMethod("dbCommit", signature("EXAConnection"),
1919
function(conn, silent = FALSE) {
20-
.Call(C_exaWsExecute, conn@ws_handle, "COMMIT")
20+
exaWsExecute(conn@ws_handle, "COMMIT")
2121
if (!silent) message("Transaction committed.")
2222
return(TRUE)
2323
})
@@ -36,7 +36,7 @@ setMethod("dbCommit", signature("EXAConnection"),
3636
#' @export
3737
setMethod("dbRollback", signature("EXAConnection"),
3838
function(conn) {
39-
.Call(C_exaWsExecute, conn@ws_handle, "ROLLBACK")
39+
exaWsExecute(conn@ws_handle, "ROLLBACK")
4040
message("Transaction rolled back.")
4141
return(TRUE)
4242
})
@@ -54,7 +54,7 @@ setMethod("dbRollback", signature("EXAConnection"),
5454
#' @export
5555
setMethod("dbBegin", signature("EXAConnection"),
5656
function(conn) {
57-
.Call(C_exaWsSetAttributes, conn@ws_handle, '{"autocommit":false}')
57+
exaWsSetAttributes(conn@ws_handle, '{"autocommit":false}')
5858
return(TRUE)
5959
})
6060

@@ -94,6 +94,6 @@ setMethod("dbEnd", signature("EXAConnection"),
9494
autocommit_json <- ifelse(conn@autocom_default,
9595
'{"autocommit":true}',
9696
'{"autocommit":false}')
97-
.Call(C_exaWsSetAttributes, conn@ws_handle, autocommit_json)
97+
exaWsSetAttributes(conn@ws_handle, autocommit_json)
9898
return(TRUE)
9999
})

R/RcppExports.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
exaWsConnect <- function(host, port, useTls, username, password, protocolVersion) {
5+
.Call(`_exasol_exaWsConnect`, host, port, useTls, username, password, protocolVersion)
6+
}
7+
8+
exaWsExecute <- function(connPtr, sql) {
9+
.Call(`_exasol_exaWsExecute`, connPtr, sql)
10+
}
11+
12+
exaWsFetch <- function(connPtr, resultSetHandle, startPosition, numBytes) {
13+
.Call(`_exasol_exaWsFetch`, connPtr, resultSetHandle, startPosition, numBytes)
14+
}
15+
16+
exaWsCloseResultSet <- function(connPtr, resultSetHandle) {
17+
.Call(`_exasol_exaWsCloseResultSet`, connPtr, resultSetHandle)
18+
}
19+
20+
exaWsDisconnect <- function(connPtr) {
21+
.Call(`_exasol_exaWsDisconnect`, connPtr)
22+
}
23+
24+
exaWsSetAttributes <- function(connPtr, attrJson) {
25+
.Call(`_exasol_exaWsSetAttributes`, connPtr, attrJson)
26+
}
27+
28+
exaWsGetAttributes <- function(connPtr) {
29+
.Call(`_exasol_exaWsGetAttributes`, connPtr)
30+
}
31+
32+
exaWsIsConnected <- function(connPtr) {
33+
.Call(`_exasol_exaWsIsConnected`, connPtr)
34+
}
35+
36+
asyncRODBCIOStart <- function(host, port, protocol) {
37+
.Call(`_exasol_asyncRODBCIOStart`, host, port, protocol)
38+
}
39+
40+
asyncRODBCProxyHost <- function() {
41+
.Call(`_exasol_asyncRODBCProxyHost`)
42+
}
43+
44+
asyncRODBCProxyPort <- function() {
45+
.Call(`_exasol_asyncRODBCProxyPort`)
46+
}
47+
48+
asyncRODBCQueryStart <- function(chan, query, protocol, writer) {
49+
.Call(`_exasol_asyncRODBCQueryStart`, chan, query, protocol, writer)
50+
}
51+
52+
asyncRODBCQueryFinish <- function(checkWasDone) {
53+
.Call(`_exasol_asyncRODBCQueryFinish`, checkWasDone)
54+
}
55+
56+
asyncEnableTracing <- function(tracefile) {
57+
.Call(`_exasol_asyncEnableTracing`, tracefile)
58+
}
59+

R/Viewer.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
schema_list <- paste0("'", schema, "'", collapse = ", ")
66
sql <- paste0(sql, " AND TABLE_SCHEMA IN (", schema_list, ")")
77
}
8-
res <- .Call(C_exaWsExecute, connection@ws_handle, sql)
8+
res <- exaWsExecute(connection@ws_handle, sql)
99
if (is.null(res$data) || length(res$data) == 0) {
1010
return(data.frame(TABLE_SCHEMA = character(0), TABLE_NAME = character(0), TABLE_TYPE = character(0), stringsAsFactors = FALSE))
1111
}
@@ -134,7 +134,7 @@
134134

135135
sql <- paste0("SELECT COLUMN_NAME, COLUMN_TYPE FROM SYS.EXA_ALL_COLUMNS WHERE COLUMN_SCHEMA = '",
136136
schema, "' AND COLUMN_TABLE = '", name, "' ORDER BY COLUMN_ORDINAL_POSITION")
137-
ws_res <- .Call(C_exaWsExecute, connection@ws_handle, sql)
137+
ws_res <- exaWsExecute(connection@ws_handle, sql)
138138
if (is.null(ws_res$data) || length(ws_res$data) == 0) {
139139
return(data.frame(name = character(0), type = character(0), stringsAsFactors = FALSE))
140140
}

R/exa.log.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ EXATrace <- function (tracefile) {
2727
if (tracefileAsString == "") {
2828
warning("Tracefile is empty.")
2929
} else {
30-
.Call(C_asyncEnableTracing, tracefile)
30+
asyncEnableTracing(tracefile)
3131
}
3232
}

R/exa.readData.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exa.readData <- function(channel, query, encoding = 'UTF-8',
5151
server = NA,...) {
5252
query <- as.character(query)
5353

54-
try(.Call(C_asyncRODBCQueryFinish, 0))
54+
try(asyncRODBCQueryFinish(0))
5555

5656
protocol <- ifelse(channel@encrypted, "https", "http")
5757

@@ -64,20 +64,19 @@ exa.readData <- function(channel, query, encoding = 'UTF-8',
6464
serverHost <- as.character(serverAddress[[1]])
6565
serverPort <- as.integer(serverAddress[[2]])
6666

67-
.Call(C_asyncRODBCIOStart,serverHost, serverPort, protocol)
67+
asyncRODBCIOStart(serverHost, serverPort, protocol)
6868

69-
proxyHost <- .Call(C_asyncRODBCProxyHost)
70-
proxyPort <- .Call(C_asyncRODBCProxyPort)
69+
proxyHost <- asyncRODBCProxyHost()
70+
proxyPort <- asyncRODBCProxyPort()
7171
query <- paste0("EXPORT (", query, ") INTO CSV AT '", protocol, "://", proxyHost, ":",
7272
proxyPort, "' FILE 'executeSQL.csv' ENCODING = '",encoding,"' BOOLEAN = 'TRUE/FALSE' WITH COLUMN NAMES IGNORE CERTIFICATE")
7373

74-
on.exit(.Call(C_asyncRODBCQueryFinish, 0))
74+
on.exit(asyncRODBCQueryFinish(0))
7575

76-
fd <- .Call(C_asyncRODBCQueryStart,
77-
channel@ws_handle, query, protocol, 0)
76+
fd <- asyncRODBCQueryStart(channel@ws_handle, query, protocol, 0)
7877

7978
res <- reader(fd,...)
8079
on.exit(NULL)
81-
.Call(C_asyncRODBCQueryFinish, 1)
80+
asyncRODBCQueryFinish(1)
8281
res
8382
}

R/exa.writeData.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ exa.writeData <- function(channel, data, tableName, tableColumns = NA,
5959

6060
protocol <- ifelse(channel@encrypted, "https", "http")
6161

62-
try(.Call(C_asyncRODBCQueryFinish, 0))
62+
try(asyncRODBCQueryFinish(0))
6363

6464
if (missing(server)) {
6565
server <- paste0(channel@db_host, ":", as.integer(channel@db_port))
@@ -70,9 +70,9 @@ exa.writeData <- function(channel, data, tableName, tableColumns = NA,
7070
serverHost <- as.character(serverAddress[[1]])
7171
serverPort <- as.integer(serverAddress[[2]])
7272

73-
.Call(C_asyncRODBCIOStart, serverHost, serverPort, protocol)
74-
proxyHost <- .Call(C_asyncRODBCProxyHost)
75-
proxyPort <- .Call(C_asyncRODBCProxyPort)
73+
asyncRODBCIOStart(serverHost, serverPort, protocol)
74+
proxyHost <- asyncRODBCProxyHost()
75+
proxyPort <- asyncRODBCProxyPort()
7676

7777
columns <- ""
7878
if (length(tableColumns) > 1 || (length(tableColumns) == 1 && !is.na(tableColumns))) {
@@ -83,13 +83,12 @@ exa.writeData <- function(channel, data, tableName, tableColumns = NA,
8383
columns,
8484
" FROM CSV AT '" , protocol, "://", proxyHost, ":",
8585
proxyPort, "' FILE 'importData.csv' ENCODING = '", encoding, "' IGNORE CERTIFICATE")
86-
on.exit(.Call(C_asyncRODBCQueryFinish, 0))
86+
on.exit(asyncRODBCQueryFinish(0))
8787

88-
fd <- .Call(C_asyncRODBCQueryStart, channel@ws_handle,
89-
query, protocol, 1)
88+
fd <- asyncRODBCQueryStart(channel@ws_handle, query, protocol, 1)
9089

9190
res <- writer(data, fd)
9291
flush(fd)
93-
.Call(C_asyncRODBCQueryFinish, 1)
92+
asyncRODBCQueryFinish(1)
9493
ifelse(is.null(res), return(TRUE), return(res))
9594
}

0 commit comments

Comments
 (0)