Skip to content

Commit

Permalink
apacheGH-40702: [R] Avoid undocumented dbplyr internals in duckdb tes…
Browse files Browse the repository at this point in the history
…ts (apache#40710)

### Rationale for this change

Most R CI is failing because of a dbplyr update that updated the internals of the intermediate representation. This was also a problem the last time dbplyr was updated where I believe it was me that hacked the fix of just using the *new* internal structure.

### What changes are included in this PR?

This fix eliminates the use of the dbplyr internals for that test, instead scraping the SQL query for the table name.

### Are these changes tested?

Covered by existing tests

### Are there any user-facing changes?

No
* GitHub Issue: apache#40702

Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Nic Crane <thisisnic@gmail.com>
  • Loading branch information
paleolimbot authored Mar 21, 2024
1 parent cc9d52c commit 1ab25b8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions r/tests/testthat/test-duckdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ test_that("to_duckdb with a table", {
})

test_that("to_duckdb passing a connection", {
skip_if_not_installed("stringr")

ds <- InMemoryDataset$create(example_data)

con_separate <- dbConnect(duckdb::duckdb())
Expand All @@ -278,13 +280,10 @@ test_that("to_duckdb passing a connection", {
select(int, lgl, dbl) %>%
to_duckdb(con = con_separate, auto_disconnect = FALSE)

# dbplyr 2.3.0 renamed this internal attribute to lazy_query;
# and 2.4.0 reserved $... for internal use + changed the identifier class
if (packageVersion("dbplyr") < "2.4.0") {
table_four_name <- unclass(table_four)$lazy_query$x
} else {
table_four_name <- unclass(unclass(table_four)$lazy_query$x)$table
}
# Generates a query like SELECT * FROM arrow_xxx
table_four_query <- paste(show_query(table_four), collapse = "\n")
table_four_name <- stringr::str_extract(table_four_query, "arrow_[0-9]{3}")
expect_false(is.na(table_four_name))

result <- DBI::dbGetQuery(
con_separate,
Expand Down

0 comments on commit 1ab25b8

Please sign in to comment.