From cfc9e02d6724455b6b77c13279c42807bc67f2a1 Mon Sep 17 00:00:00 2001 From: Joshi Date: Fri, 8 May 2015 14:30:33 -0700 Subject: [PATCH] Spark-7435[R]: updated patch for review comments --- R/pkg/R/DataFrame.R | 19 ++++++++++--------- R/pkg/inst/tests/test_sparkSQL.R | 5 +++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index a64d1e6b3ea5b..bc0b400bfc2a0 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -147,14 +147,14 @@ setMethod("isLocal", callJMethod(x@sdf, "isLocal") }) -#' show +#' showDF #' #' Print the first numRows rows of a DataFrame #' #' @param x A SparkSQL DataFrame #' @param numRows The number of rows to print. Defaults to 20. #' -#' @rdname show +#' @rdname showDF #' @export #' @examples #'\dontrun{ @@ -162,21 +162,22 @@ setMethod("isLocal", #' sqlCtx <- sparkRSQL.init(sc) #' path <- "path/to/file.json" #' df <- jsonFile(sqlCtx, path) -#' show(df) +#' showDF(df) #'} -setMethod("show", +setMethod("showDF", signature(x = "DataFrame"), function(x, numRows = 20) { - callJMethod(x@sdf, "showString", numToInt(numRows)) + s <- callJMethod(x@sdf, "showString", numToInt(numRows)) + cat(s) }) -#' showDF +#' show #' #' Print the DataFrame column names and types #' #' @param x A SparkSQL DataFrame #' -#' @rdname showDF +#' @rdname show #' @export #' @examples #'\dontrun{ @@ -184,9 +185,9 @@ setMethod("show", #' sqlCtx <- sparkRSQL.init(sc) #' path <- "path/to/file.json" #' df <- jsonFile(sqlCtx, path) -#' showDF +#' show #'} -setMethod("showDF", "DataFrame", +setMethod("show", "DataFrame", function(object) { cols <- lapply(dtypes(object), function(l) { paste(l, collapse = ":") diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R index a8f79bdadc2b5..bd0b7373c4322 100644 --- a/R/pkg/inst/tests/test_sparkSQL.R +++ b/R/pkg/inst/tests/test_sparkSQL.R @@ -639,9 +639,10 @@ test_that("toJSON() returns an RDD of the correct values", { expect_equal(collect(testRDD)[[1]], mockLines[1]) }) -test_that("show()", { +test_that("showDF()", { df <- jsonFile(sqlCtx, jsonPath) - expect_output(show(df), "+----+-------+\n| age| name|\n+----+-------+\n|null|Michael|\n| 30| Andy|\n| 19| Justin|\n+----+-------+\n") + s <- capture.output(showDF(df)) + expect_output(s , "+----+-------+\n| age| name|\n+----+-------+\n|null|Michael|\n| 30| Andy|\n| 19| Justin|\n+----+-------+\n") }) test_that("isLocal()", {