krlmlr commented on code in PR #365:
URL: https://github.com/apache/arrow-adbc/pull/365#discussion_r1094930038
##########
r/adbcdrivermanager/DESCRIPTION:
##########
@@ -0,0 +1,27 @@
+Package: adbcdrivermanager
+Title: 'Arrow' Database Connectivity ('ADBC') Driver Manager
Review Comment:
There is a trick to get rid of the quotes. @maelle: Can you please help?
##########
r/adbcdrivermanager/R/adbc.R:
##########
@@ -0,0 +1,440 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#' Databases
+#'
+#' @param driver An [adbc_driver()].
+#' @param database An [adbc_database][adbc_database_init].
+#' @param ... Driver-specific options. For the default method, these are
+#' named values that are converted to strings.
+#' @param options A named `character()` or `list()` whose values are converted
+#' to strings.
+#' @param subclass An extended class for an object so that drivers can specify
+#' finer-grained control over behaviour at the R level.
+#'
+#' @return An object of class adbc_database
+#' @export
+#'
+#' @examples
+#' adbc_database_init(adbc_driver_void())
+#'
+adbc_database_init <- function(driver, ...) {
Review Comment:
What's the motivation for making this a generic?
##########
r/adbcdrivermanager/R/utils.R:
##########
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+key_value_options <- function(options) {
+ if (!is.character(options)) {
+ options <- vapply(options, as.character, character(1))
+ }
+
+ keys <- names(options)
+ if (length(options) == 0) {
+ names(options) <- character()
+ } else if (is.null(keys) || all(keys == "")) {
+ stop("key/value options must be named")
+ }
+
+ options
+}
+
+xptr_add_option <- function(xptr, key, value) {
+ if (is.null(xptr$options)) {
+ xptr$options <- new.env(parent = emptyenv())
+ }
+
+ xptr$options[[key]] <- unname(value)
+}
+
+new_env <- function() {
+ new.env(parent = emptyenv())
+}
+
+xptr_env <- function(xptr) {
+ .Call(RAdbcXptrEnv, xptr)
+}
+
+#' @export
+length.adbc_xptr <- function(x) {
+ length(xptr_env(x))
+}
+
+#' @export
+names.adbc_xptr <- function(x) {
+ names(xptr_env(x))
+}
+
+
+#' @export
+`[[.adbc_xptr` <- function(x, i) {
+ xptr_env(x)[[i]]
+}
+
+#' @export
+`[[<-.adbc_xptr` <- function(x, i, value) {
+ env <- xptr_env(x)
+ env[[i]] <- value
+ x
Review Comment:
Perhaps:
```suggestion
`invisible(value)`
```
?
##########
r/adbcdrivermanager/configure:
##########
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# If we are building from within the ADBC repo, we copy the files we
+# need to ensure commit-level consistency
+if [ -f "../../adbc.h" ]; then
+ echo "Copying files from local ADBC"
+ rm -f src/adbc.h src/adbc_driver_manager.h src/adbc_driver_manager.cc
+ cp ../../adbc.h \
+ ../../c/driver_manager/adbc_driver_manager.h \
+ ../../c/driver_manager/adbc_driver_manager.cc \
+ src
+fi
+
+if [ -f "src/adbc.h" ] && [ -f "src/adbc_driver_manager.h" ] && [ -f
"src/adbc_driver_manager.cc" ]; then
+ echo "Found vendored ADBC"
+ exit 0
+fi
+
+# We have a situation where the package has been built via R CMD build
+# but there is no vendored adbc.h or driver manager. This occurs with
+# remotes::install_github() with the default arguments. In this case, pull
+# the latest files from GitHub. To ensure commit-level consistency,
+# use remotes::install_github(build = FALSE)
+curl -L https://github.com/apache/arrow-adbc/raw/main/adbc.h \
Review Comment:
Nice trick!
##########
r/adbcdrivermanager/src/radbc.cc:
##########
@@ -0,0 +1,427 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define R_NO_REMAP
+#include <R.h>
+#include <Rinternals.h>
+
+#include <adbc.h>
+#include "adbc_driver_manager.h"
+
+#include "radbc.h"
+
+static const char* adbc_error_message(AdbcError* error) {
+ if (error->message == nullptr) {
+ return "";
+ } else {
+ return error->message;
+ }
+}
+
+static void adbc_error_warn(int code, AdbcError* error, const char* context) {
+ if (code != ADBC_STATUS_OK) {
+ Rf_warning("<%s> %s", context, adbc_error_message(error));
+ }
+}
+
+static void adbc_error_stop(int code, AdbcError* error, const char* context) {
+ if (code != ADBC_STATUS_OK) {
+ Rf_error("<%s> %s", context, adbc_error_message(error));
+ }
+}
+
+static void finalize_database_xptr(SEXP database_xptr) {
+ auto database =
reinterpret_cast<AdbcDatabase*>(R_ExternalPtrAddr(database_xptr));
+ if (database == nullptr) {
+ return;
+ }
+
+ if (database->private_data != nullptr) {
+ AdbcError error;
+ int status = AdbcDatabaseRelease(database, &error);
+ adbc_error_warn(status, &error, "finalize_database_xptr()");
+ }
+
+ adbc_xptr_default_finalize<AdbcDatabase>(database_xptr);
+}
+
+extern "C" SEXP RAdbcLoadDriver(SEXP driver_name_sexp, SEXP entrypoint_sexp) {
Review Comment:
Is there a specific reason for avoiding the cpp11 package in this project?
##########
r/adbcdrivermanager/R/utils.R:
##########
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+key_value_options <- function(options) {
+ if (!is.character(options)) {
+ options <- vapply(options, as.character, character(1))
+ }
+
+ keys <- names(options)
+ if (length(options) == 0) {
+ names(options) <- character()
+ } else if (is.null(keys) || all(keys == "")) {
+ stop("key/value options must be named")
+ }
+
+ options
+}
+
+xptr_add_option <- function(xptr, key, value) {
+ if (is.null(xptr$options)) {
+ xptr$options <- new.env(parent = emptyenv())
+ }
+
+ xptr$options[[key]] <- unname(value)
+}
+
+new_env <- function() {
+ new.env(parent = emptyenv())
+}
+
+xptr_env <- function(xptr) {
+ .Call(RAdbcXptrEnv, xptr)
+}
+
+#' @export
+length.adbc_xptr <- function(x) {
+ length(xptr_env(x))
+}
+
+#' @export
+names.adbc_xptr <- function(x) {
+ names(xptr_env(x))
+}
+
+
+#' @export
+`[[.adbc_xptr` <- function(x, i) {
+ xptr_env(x)[[i]]
+}
+
+#' @export
+`[[<-.adbc_xptr` <- function(x, i, value) {
+ env <- xptr_env(x)
+ env[[i]] <- value
+ x
+}
+
+#' @export
+`$.adbc_xptr` <- function(x, name) {
+ xptr_env(x)[[name]]
+}
+
+#' @export
+`$<-.adbc_xptr` <- function(x, name, value) {
+ env <- xptr_env(x)
+ env[[name]] <- value
+ x
Review Comment:
Here, too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]