-
Notifications
You must be signed in to change notification settings - Fork 261
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
Arrow IPC serializers and parsers #968
Open
JosiahParry
wants to merge
5
commits into
rstudio:main
Choose a base branch
from
JosiahParry:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−13
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
context("Arrow IPC serializer") | ||
|
||
test_that("Arrow IPC serializes properly", { | ||
skip_if_not_installed("arrow") | ||
|
||
d <- data.frame(a=1, b=2, c="hi") | ||
val <- serializer_arrow_ipc()(d, data.frame(), PlumberResponse$new(), stop) | ||
expect_equal(val$status, 200L) | ||
expect_equal(val$headers$`Content-Type`, "application/vnd.apache.arrow.stream") | ||
|
||
# can test by doing a full round trip if we believe the parser works via `test-parse-body.R` | ||
parsed <- parse_body(val$body, "application/vnd.apache.arrow.stream", make_parser("arrow_ipc")) | ||
# convert from feather tibble to data.frame | ||
parsed <- as.data.frame(parsed, stringsAsFactors = FALSE) | ||
attr(parsed, "spec") <- NULL | ||
|
||
expect_equal(parsed, d) | ||
}) | ||
|
||
test_that("Errors call error handler", { | ||
skip_if_not_installed("arrow") | ||
|
||
errors <- 0 | ||
errHandler <- function(req, res, err){ | ||
errors <<- errors + 1 | ||
} | ||
|
||
expect_equal(errors, 0) | ||
serializer_feather()(parse(text="hi"), data.frame(), PlumberResponse$new("csv"), errorHandler = errHandler) | ||
expect_equal(errors, 1) | ||
}) | ||
|
||
test_that("Errors are rendered correctly with debug TRUE", { | ||
skip_if_not_installed("arrow") | ||
|
||
pr <- pr() %>% pr_get("/", function() stop("myerror"), serializer = serializer_feather()) %>% pr_set_debug(TRUE) | ||
capture.output(res <- pr$serve(make_req(pr = pr), PlumberResponse$new("csv"))) | ||
|
||
expect_match(res$body, "Error in (function () : myerror", fixed = TRUE) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this should be named
parser_arrow_ipc_stream()
or something similar? From Read Arrow IPC stream format — read_ipc_stream • Arrow R Package it seems that there are two IPC formats, "stream" and "file":Since the "file" format is synonymous with "feather" (which already has
parse_feather()
), my take-away is thatstream
is an important aspect we should include in the name. I also like trying to match the naming of the underlying function (arrow::{read,write}_ipc_stream()
) while staying within plumber's naming patterns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gocha! That's a good point. I believe though that Feather specifically refers to the V1 format. Then V2 is the IPC file—though I think it is a bit of a vagary there.
So, to be crystal clear before merge:
parser_arrow_ipc()
toparser_arrow_ipc_stream()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it sounds like there some room for confusion around which variant of IPC this is that would be cleared up by
parser_arrow_ipc_stream()
, so I'm in favor of making that change before merging. Otherwise the PR looks great, thanks @JosiahParry!