Skip to content

Commit

Permalink
Spark-7435[R]: updated patch for review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rekhajoshm committed May 8, 2015
1 parent 62becc1 commit cfc9e02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,46 +147,47 @@ 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{
#' sc <- sparkR.init()
#' 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{
#' sc <- sparkR.init()
#' 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 = ":")
Expand Down
5 changes: 3 additions & 2 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()", {
Expand Down

0 comments on commit cfc9e02

Please sign in to comment.