krlmlr commented on code in PR #1334:
URL: https://github.com/apache/arrow-adbc/pull/1334#discussion_r1434188732


##########
r/adbcdrivermanager/R/helpers.R:
##########
@@ -244,53 +239,69 @@ local_adbc <- function(x, .local_envir = parent.frame()) {
 #'
 adbc_connection_join <- function(connection, database) {
   assert_adbc(connection, "adbc_connection")
-  assert_adbc(database, "adbc_database")
+
+  stopifnot(
+    identical(database, connection$database),
+    identical(database$.child_count, 1L)
+  )
 
   connection$.release_database <- TRUE
-  connection$database <- adbc_xptr_move(database)
+  connection$database <- adbc_xptr_move(database, check_child_count = FALSE)
+  xptr_set_protected(connection, connection$database)
   invisible(connection)
 }
 
 #' @rdname adbc_connection_join
 #' @export
 adbc_statement_join <- function(statement, connection) {
   assert_adbc(statement, "adbc_statement")
-  assert_adbc(connection, "adbc_connection")
+
+  stopifnot(
+    identical(connection, statement$connection),
+    identical(connection$.child_count, 1L)
+  )
 
   statement$.release_connection <- TRUE
-  statement$connection <- adbc_xptr_move(connection)
+  statement$connection <- adbc_xptr_move(connection, check_child_count = FALSE)
+  xptr_set_protected(statement, statement$connection)
   invisible(statement)
 }
 
-#' @rdname adbc_connection_join
-#' @export
-adbc_stream_join <- function(stream, x) {
-  if (utils::packageVersion("nanoarrow") < "0.1.0.9000") {
-    stop("adbc_stream_join_statement() requires nanoarrow >= 0.2.0")
-  }
-
-  assert_adbc(stream, "nanoarrow_array_stream")
-  assert_adbc(x)
+adbc_child_stream <- function(parent, stream, release_parent = FALSE) {
+  assert_adbc(parent)
 
+  # This finalizer will run immediately on release (if released explicitly
+  # on the main R thread) or on garbage collection otherwise.
   self_contained_finalizer <- function() {
-    try(adbc_release_non_null(x))
+    try({
+      parent$.child_count <- parent$.child_count - 1L

Review Comment:
   Should this and other code be using `adbc_update_parent_child_count()` or a 
variant under the hood?



-- 
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]

Reply via email to