Skip to content

Commit

Permalink
[SEDONA-324] R fix tests (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregleleu committed Jul 19, 2023
1 parent d1f8b0e commit b9b26cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 44 deletions.
1 change: 1 addition & 0 deletions R/.Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
^LICENSE$
^pkgdown$
^vignettes/articles$
^demo
66 changes: 22 additions & 44 deletions R/tests/testthat/test-dbplyr-integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ sc <- testthat_spark_connection()

test_that("ST_Point() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(pt = ST_Point(-40, 40)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())
dplyr::mutate(pt = ST_Point(-40, 40))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("id", "pt"))
expect_equal(
Expand All @@ -42,7 +39,7 @@ test_that("ST_PolygonFromEnvelope() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(rectangle = ST_PolygonFromEnvelope(-40, -30, 40, 30))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("id", "rectangle"))
expect_equal(
Expand All @@ -60,11 +57,9 @@ test_that("ST_PolygonFromEnvelope() works as expected", {
test_that("ST_Buffer() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(pt = ST_Point(-40, 40)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string()) %>%
dplyr::compute()

# dplyr::compute() ## fixed in dev version of sparklyr (compute caches, sdf_register does not)
sdf_register()

expect_equal(
sdf %>%
dplyr::mutate(pt = ST_Buffer(pt, 3L)) %>%
Expand All @@ -80,13 +75,10 @@ test_that("ST_Buffer() works as expected", {
test_that("ST_ReducePrecision() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(rectangle = ST_PolygonFromEnvelope(-40.12345678, -30.12345678, 40.11111111, 30.11111111)) %>%
dplyr::mutate(rectangle = ST_ReducePrecision(rectangle, 2)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())

dplyr::mutate(rectangle = ST_ReducePrecision(rectangle, 2))

df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("id", "rectangle"))
expect_equal(
Expand All @@ -104,11 +96,9 @@ test_that("ST_ReducePrecision() works as expected", {
test_that("ST_SimplifyPreserveTopology() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(pt = ST_Point(-40, 40)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string()) %>%
dplyr::compute()

# dplyr::compute() ## fixed in dev version of sparklyr (compute caches, sdf_register does not)
sdf_register()

expect_equal(
sdf %>%
dplyr::mutate(pt = ST_SimplifyPreserveTopology(pt, 1L)) %>%
Expand All @@ -124,12 +114,9 @@ test_that("ST_SimplifyPreserveTopology() works as expected", {
test_that("ST_GeometryN() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(pts = ST_GeomFromText("MULTIPOINT((1 2), (3 4), (5 6), (8 9))")) %>%
dplyr::transmute(pt = ST_GeometryN(pts, 2)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())
dplyr::transmute(pt = ST_GeometryN(pts, 2))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("pt"))
expect_equal(
Expand All @@ -144,12 +131,9 @@ test_that("ST_GeometryN() works as expected", {
test_that("ST_InteriorRingN() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(polygon = ST_GeomFromText("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1), (1 3, 2 3, 2 4, 1 4, 1 3), (3 3, 4 3, 4 4, 3 4, 3 3))")) %>%
dplyr::transmute(interior_ring = ST_InteriorRingN(polygon, 0)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())
dplyr::transmute(interior_ring = ST_InteriorRingN(polygon, 0))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("interior_ring"))
expect_equal(
Expand All @@ -166,12 +150,9 @@ test_that("ST_InteriorRingN() works as expected", {
test_that("ST_AddPoint() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(linestring = ST_GeomFromText("LINESTRING(0 0, 1 1, 1 0)")) %>%
dplyr::transmute(linestring = ST_AddPoint(linestring, ST_GeomFromText("Point(21 52)"), 1)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())
dplyr::transmute(linestring = ST_AddPoint(linestring, ST_GeomFromText("Point(21 52)"), 1))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("linestring"))
expect_equal(
Expand All @@ -183,12 +164,12 @@ test_that("ST_AddPoint() works as expected", {
df$linestring[[1]],
list(c(0, 0), c(21, 52), c(1, 1), c(1, 0))
)

sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(linestring = ST_GeomFromText("LINESTRING(0 0, 1 1, 1 0)")) %>%
dplyr::transmute(linestring = ST_AddPoint(linestring, ST_GeomFromText("Point(21 52)")))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("linestring"))
expect_equal(
Expand All @@ -205,12 +186,9 @@ test_that("ST_AddPoint() works as expected", {
test_that("ST_RemovePoint() works as expected", {
sdf <- sdf_len(sc, 1) %>%
dplyr::mutate(linestring = ST_GeomFromText("LINESTRING(0 0, 21 52, 1 1, 1 0)")) %>%
dplyr::transmute(linestring = ST_RemovePoint(linestring, 1)) %>%
# NOTE: the extra `sdf_register()` call is a workaround until SPARK-37202 is
# fixed
sdf_register(name = random_string())
dplyr::transmute(linestring = ST_RemovePoint(linestring, 1))
df <- sdf %>% collect()

expect_equal(nrow(df), 1)
expect_equal(colnames(df), c("linestring"))
expect_equal(
Expand Down

0 comments on commit b9b26cc

Please sign in to comment.