Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUBDEV-7896 - do not discard Keys in h2o.removeAll() command #5137

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions h2o-r/h2o-package/R/kvstore.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ h2o.ls <- function() {
#' Remove All Objects on the H2O Cluster
#'
#' Removes the data from the h2o cluster, but does not remove the local references.
#' Retains frames and vectors specified in retained_elements argument.
#' Retained keys must be keys of models and frames only. For models retained, training and validation frames are retained as well.
#' Retains models, frames and vectors specified in retained_elements argument.
#' Retained elements must be instances/ids of models and frames only. For models retained, training and validation frames are retained as well.
#' Cross validation models of a retained model are NOT retained automatically, those must be specified explicitely.
#'
#' @param timeout_secs Timeout in seconds. Default is no timeout.
#' @param retained_elements Frames and vectors to be retained. Other keys provided are ignored.
#' @param retained_elements Instances or ids of models and frames to be retained. Combination of instances and ids in the same list is also a valid input.
#' @seealso \code{\link{h2o.rm}}
#' @examples
#' \dontrun{
Expand All @@ -76,6 +76,10 @@ h2o.removeAll <- function(timeout_secs=0, retained_elements = c()) {
retained_keys <- append(retained_keys, element@model_id)
} else if (is.H2OFrame(element)) {
retained_keys <- append(retained_keys, h2o.getId(element))
} else if( is.character(element) ) {
retained_keys <- append(retained_keys, element)
} else {
stop("The 'retained_elements' variable must be either an instance of H2OModel/H2OFrame or an id of H2OModel/H2OFrame.")
}
}

Expand Down Expand Up @@ -122,7 +126,7 @@ h2o.rm <- function(ids, cascade=TRUE) {
} else if( is.character(xi) ) {
.h2o.__remoteSend(paste0(.h2o.__DKV, "/",xi), method = "DELETE", .params=list(cascade=cascade))
} else {
stop("input to h2o.rm must be a Keyed instance (e.g. H2OFrame, H2OModel) or character")
stop("Input to h2o.rm must be either an instance of H2OModel/H2OFrame or a character")
}
}

Expand Down
12 changes: 10 additions & 2 deletions h2o-r/tests/testdir_misc/runit_retain.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ test.h2o.retain <- function() {
h2o.removeAll(retained_elements = c(data, model))
expect_false(is.null(h2o.getFrame(h2o.getId(data))))
expect_false(is.null(h2o.getModel(model@model_id)))


h2o.removeAll(retained_elements = c(h2o.getId(data), model@model_id))
expect_false(is.null(h2o.getFrame(h2o.getId(data))))
expect_false(is.null(h2o.getModel(model@model_id)))

h2o.removeAll(retained_elements = c(data, model@model_id))
expect_false(is.null(h2o.getFrame(h2o.getId(data))))
expect_false(is.null(h2o.getModel(model@model_id)))

h2o.removeAll()

expect_equal(length(h2o.ls()$key), 0)
}

doTest("Test h2o.retain", test.h2o.retain)
Expand Down