aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests/test_sparkSQL.R
diff options
context:
space:
mode:
authorSun Rui <rui.sun@intel.com>2015-10-13 22:31:23 -0700
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2015-10-13 22:31:23 -0700
commit390b22fad69a33eb6daee25b6b858a2e768670a5 (patch)
tree34a5ada11ef2823c4b082b604b3a9d903647e325 /R/pkg/inst/tests/test_sparkSQL.R
parent8b32885704502ab2a715cf5142d7517181074428 (diff)
downloadspark-390b22fad69a33eb6daee25b6b858a2e768670a5.tar.gz
spark-390b22fad69a33eb6daee25b6b858a2e768670a5.tar.bz2
spark-390b22fad69a33eb6daee25b6b858a2e768670a5.zip
[SPARK-10996] [SPARKR] Implement sampleBy() in DataFrameStatFunctions.
Author: Sun Rui <rui.sun@intel.com> Closes #9023 from sun-rui/SPARK-10996.
Diffstat (limited to 'R/pkg/inst/tests/test_sparkSQL.R')
-rw-r--r--R/pkg/inst/tests/test_sparkSQL.R10
1 files changed, 10 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index 46cab7646d..e1b42b0804 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -1416,6 +1416,16 @@ test_that("freqItems() on a DataFrame", {
expect_identical(result[[2]], list(list(-1, -99)))
})
+test_that("sampleBy() on a DataFrame", {
+ l <- lapply(c(0:99), function(i) { as.character(i %% 3) })
+ df <- createDataFrame(sqlContext, l, "key")
+ fractions <- list("0" = 0.1, "1" = 0.2)
+ sample <- sampleBy(df, "key", fractions, 0)
+ result <- collect(orderBy(count(groupBy(sample, "key")), "key"))
+ expect_identical(as.list(result[1, ]), list(key = "0", count = 2))
+ expect_identical(as.list(result[2, ]), list(key = "1", count = 10))
+})
+
test_that("SQL error message is returned from JVM", {
retError <- tryCatch(sql(sqlContext, "select * from blah"), error = function(e) e)
expect_equal(grepl("Table Not Found: blah", retError), TRUE)