Skip to content
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
1 change: 1 addition & 0 deletions r/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ S3method(dimnames,ArrowTabular)
S3method(head,ArrowDatum)
S3method(head,ArrowTabular)
S3method(head,Dataset)
S3method(head,ExecPlanReader)
S3method(head,RecordBatchReader)
S3method(head,Scanner)
S3method(head,arrow_dplyr_query)
Expand Down
8 changes: 8 additions & 0 deletions r/R/query-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ ExecPlanReader <- R6Class("ExecPlanReader",
)
)

#' @export
head.ExecPlanReader <- function(x, n = 6L, ...) {
# We need to make sure that the head() of an ExecPlanReader
# is also an ExecPlanReader so that the evaluation takes place
# in a way that supports calls into R.
as_record_batch_reader(as_adq(RecordBatchReader__Head(x, n)))
}

do_exec_plan_substrait <- function(substrait_plan) {
if (is.string(substrait_plan)) {
substrait_plan <- substrait__internal__SubstraitFromJSON(substrait_plan)
Expand Down
11 changes: 11 additions & 0 deletions r/tests/testthat/test-query-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ test_that("ExecPlanReader evaluates head() lazily", {
# evaluate to TRUE (i.e., the reader may or may not be completely drained).
})

test_that("head() of an ExecPlanReader is an ExecPlanReader", {
reader <- as_record_batch_reader(as_adq(arrow_table(x = 1:10)))
expect_r6_class(reader, "ExecPlanReader")
reader_head <- head(reader, 6)
expect_r6_class(reader_head, "ExecPlanReader")
expect_equal(
as_arrow_table(reader_head),
arrow_table(x = 1:6)
)
})

test_that("do_exec_plan_substrait can evaluate a simple plan", {
skip_if_not_available("substrait")

Expand Down