You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "nbenn (via GitHub)" <gi...@apache.org> on 2023/02/02 19:10:27 UTC

[GitHub] [arrow-adbc] nbenn commented on a diff in pull request #365: feat(r): Add R Driver Manager

nbenn commented on code in PR #365:
URL: https://github.com/apache/arrow-adbc/pull/365#discussion_r1094962791


##########
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:
   I'm with @krlmlr on this one. Of course there's nothing wrong with using the R C API directly and you're probably right in saying
   
   >  I don't think using either of them (cpp11 or Rcpp) would result in any earth-shattering maintainability improvements
   
   still, I found that when using cpp11 for the duckdb R client, it did allow for more concise and idiomatic code. All of this is a matter of taste though.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org