From 823518c2b5259c8a954431467639198c808c9198 Mon Sep 17 00:00:00 2001 From: Felix Cheung Date: Tue, 28 Jun 2016 17:08:28 -0700 Subject: [SPARKR] add csv tests ## What changes were proposed in this pull request? Add unit tests for csv data for SPARKR ## How was this patch tested? unit tests Author: Felix Cheung Closes #13904 from felixcheung/rcsv. --- R/pkg/inst/tests/testthat/test_sparkSQL.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'R/pkg/inst/tests') diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 7562fa95e3..d4662ad4e3 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -208,6 +208,24 @@ test_that("create DataFrame from RDD", { unsetHiveContext() }) +test_that("read csv as DataFrame", { + csvPath <- tempfile(pattern = "sparkr-test", fileext = ".csv") + mockLinesCsv <- c("year,make,model,comment,blank", + "\"2012\",\"Tesla\",\"S\",\"No comment\",", + "1997,Ford,E350,\"Go get one now they are going fast\",", + "2015,Chevy,Volt") + writeLines(mockLinesCsv, csvPath) + + # default "header" is false + df <- read.df(csvPath, "csv", header = "true") + expect_equal(count(df), 3) + expect_equal(columns(df), c("year", "make", "model", "comment", "blank")) + expect_equal(sort(unlist(collect(where(df, df$year == "2015")))), + sort(unlist(list(year = "2015", make = "Chevy", model = "Volt")))) + + unlink(csvPath) +}) + test_that("convert NAs to null type in DataFrames", { rdd <- parallelize(sc, list(list(1L, 2L), list(NA, 4L))) df <- createDataFrame(rdd, list("a", "b")) -- cgit v1.2.3