nealrichardson commented on code in PR #13706:
URL: https://github.com/apache/arrow/pull/13706#discussion_r959821430


##########
r/tests/testthat/test-query-engine.R:
##########
@@ -17,6 +17,76 @@
 
 library(dplyr, warn.conflicts = FALSE)
 
+test_that("ExecPlanReader does not start evaluating a query", {
+  rbr <- as_record_batch_reader(
+    function(x) stop("This query will error if started"),
+    schema = schema(a = int32())
+  )
+
+  reader <- as_record_batch_reader(as_adq(rbr))
+  expect_identical(reader$PlanStatus(), "PLAN_NOT_STARTED")
+  expect_error(reader$read_table(), "This query will error if started")
+  expect_identical(reader$PlanStatus(), "PLAN_FINISHED")
+})
+
+test_that("ExecPlanReader evaluates nested exec plans lazily", {
+  reader <- as_record_batch_reader(as_adq(arrow_table(a = 1:10)))
+  expect_identical(reader$PlanStatus(), "PLAN_NOT_STARTED")
+
+  head_reader <- head(reader, 4)
+  expect_identical(reader$PlanStatus(), "PLAN_NOT_STARTED")
+
+  expect_equal(
+    head_reader$read_table(),
+    arrow_table(a = 1:4)
+  )
+
+  expect_identical(reader$PlanStatus(), "PLAN_FINISHED")
+})
+
+test_that("ExecPlanReader evaluates head() lazily", {
+  reader <- as_record_batch_reader(as_adq(arrow_table(a = 1:10)))
+  expect_identical(reader$PlanStatus(), "PLAN_NOT_STARTED")
+
+  head_reader <- head(reader, 4)
+  expect_identical(reader$PlanStatus(), "PLAN_NOT_STARTED")
+
+  expect_equal(
+    head_reader$read_table(),
+    arrow_table(a = 1:4)
+  )
+
+  expect_identical(reader$PlanStatus(), "PLAN_FINISHED")
+})
+
+test_that("ExecPlanReader evaluates head() lazily", {
+  # make a 500-row RecordBatchReader
+  reader <- RecordBatchReader$create(
+    batches = rep(
+      list(
+        record_batch(
+          line = c(
+            "this is the RecordBatchReader that never ends",

Review Comment:
   😹 



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