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

Custom key mangling #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Custom key mangling #89

wants to merge 2 commits into from

Conversation

wlandau
Copy link
Contributor

@wlandau wlandau commented Nov 4, 2018

To follow up on #88 (comment), this PR proposes custom mangle_key_encode and mangle_key_decode functions for the RDS driver constructor. It is not quite working yet (I find it difficult to interact with test-driver.R) but does demonstrate what I am proposing.

Copy link
Owner

@richfitz richfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested a fairly substantial change in one of the comments - would you mind having a go at that?

R/utils.R Outdated
@@ -103,6 +103,11 @@ assert_raw <- function(x, name = deparse(substitute(x))) {
}
}

assert_function <- function(x, name = deparse(substitute(x))) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already exists on line 53 😁

@@ -76,6 +76,16 @@
##'
##' @param default_namespace Default namespace (see
##' \code{\link{storr}}).
##'
##' @param mangle_key_encode Optional function for mangling keys.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking about the interface here and I think that we should offer a single argument here; the existing mangle_key which can take string arguments

  • none - equivalent to the current FALSE
  • base64 - equivalent to the current TRUE
  • xxxx - a key for a "registered" mangler

Then we need a new function:

register_mangler <- function(name, encode, decode, overwrite = FALSE) {...}

which adds a new mangling strategy. Then drake would call as part of initialisation (.onLoad), storr::register_mangler("drake::lazy_base64", drake::lazy_base64_encode, drake::lazy_base64_decode)

We'll save the functions into the class much as you have here.

My thinking here is that storr archives need to be openable by previous and future versions of storr, and that the options should be saved into the archive itself to avoid corrupting them (there's some fairly nasty logic going on already for that).

Copy link
Contributor Author

@wlandau wlandau Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea the best so far. Implementation and back compatibility are much easier this way. I will start a new branch and PR tomorrow.

@@ -157,6 +175,14 @@ R6_driver_rds <- R6::R6Class(
write_if_missing("TRUE", driver_rds_config_file(path, "mangle_key_pad"))
write_if_missing("TRUE", driver_rds_config_file(path, "compress"))
write_if_missing("md5", driver_rds_config_file(path, "hash_algorithm"))
write_if_missing(
deparse(mangle_key_encode),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside of this approach is that the deparse route is not going to result in something that can be parsed back out as a usable function later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants