tests/testthat/test_sparkavro.R

library(sparklyr)

library(sparkavro)
library(dplyr)
if(!exists("sc")){
  spark_install()
  sc <- spark_connect(master="local")
}

test_that("read existing avro", {
  df <- spark_read_avro(sc, "twitter", system.file("extdata", "twitter.avro", package="sparkavro"), memory = FALSE)
  expect_equal(df %>% collect() %>% length(), 3)
})

test_that("write Spark DataFrame into avro", {
  df <- spark_read_avro(sc, "twitter", system.file("extdata", "twitter.avro", package="sparkavro"), memory = FALSE)
  df2 <- df %>% filter(username == "miguno")
  filename <- tempfile("test", fileext=".avro")
  spark_write_avro(df2, filename)
  expect_true(file.exists(filename))
})

Try the sparkavro package in your browser

Any scripts or data that you put into this service are public.

sparkavro documentation built on Jan. 10, 2020, 9:07 a.m.