aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests/test_sparkSQL.R
diff options
context:
space:
mode:
authorSun Rui <rui.sun@intel.com>2015-10-07 09:46:37 -0700
committerDavies Liu <davies.liu@gmail.com>2015-10-07 09:46:37 -0700
commitf57c63d4c30d092a320c72f8c7181f2fa711ec30 (patch)
tree6564d8b720e2b52241efe94593f22a59a3e2cd83 /R/pkg/inst/tests/test_sparkSQL.R
parent27cdde2ff87346fb54318532a476bf85f5837da7 (diff)
downloadspark-f57c63d4c30d092a320c72f8c7181f2fa711ec30.tar.gz
spark-f57c63d4c30d092a320c72f8c7181f2fa711ec30.tar.bz2
spark-f57c63d4c30d092a320c72f8c7181f2fa711ec30.zip
[SPARK-10752] [SPARKR] Implement corr() and cov in DataFrameStatFunctions.
Author: Sun Rui <rui.sun@intel.com> Closes #8869 from sun-rui/SPARK-10752.
Diffstat (limited to 'R/pkg/inst/tests/test_sparkSQL.R')
-rw-r--r--R/pkg/inst/tests/test_sparkSQL.R12
1 files changed, 12 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index faf42b7182..bcf52b8fa7 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -1329,6 +1329,18 @@ test_that("crosstab() on a DataFrame", {
expect_identical(expected, ordered)
})
+test_that("cov() and corr() on a DataFrame", {
+ l <- lapply(c(0:9), function(x) { list(x, x * 2.0) })
+ df <- createDataFrame(sqlContext, l, c("singles", "doubles"))
+ result <- cov(df, "singles", "doubles")
+ expect_true(abs(result - 55.0 / 3) < 1e-12)
+
+ result <- corr(df, "singles", "doubles")
+ expect_true(abs(result - 1.0) < 1e-12)
+ result <- corr(df, "singles", "doubles", "pearson")
+ expect_true(abs(result - 1.0) < 1e-12)
+})
+
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)