Github user sun-rui commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8920#discussion_r41112944
  
    --- Diff: R/pkg/R/DataFrame.R ---
    @@ -1304,24 +1306,62 @@ setClassUnion("characterOrColumn", c("character", 
"Column"))
     #' path <- "path/to/file.json"
     #' df <- jsonFile(sqlContext, path)
     #' arrange(df, df$col1)
    -#' arrange(df, "col1")
     #' arrange(df, asc(df$col1), desc(abs(df$col2)))
    +#' arrange(df, "col1")
    +#' arrange(df, "col2", FALSE)
    +#' arrange(df, "col1", decreasing=TRUE)
    +#' arrange(df, "col1", "col2", c(TRUE, FALSE))
     #' }
     setMethod("arrange",
    -          signature(x = "DataFrame", col = "characterOrColumn"),
    +          signature(x = "DataFrame", col="Column"),
               function(x, col, ...) {
    -            if (class(col) == "character") {
    -              sdf <- callJMethod(x@sdf, "sort", col, list(...))
    -            } else if (class(col) == "Column") {
                   jcols <- lapply(list(col, ...), function(c) {
                     c@jc
                   })
    -              sdf <- callJMethod(x@sdf, "sort", jcols)
    -            }
    +
    +            sdf <- callJMethod(x@sdf, "sort", jcols)
                 dataFrame(sdf)
               })
     
     #' @rdname arrange
    +#' @export
    +setMethod("arrange",
    +          signature(x = "DataFrame", col="character"),
    +          function(x, col, ..., decreasing=FALSE) {
    +
    +            # all sorting columns
    +            by <- list(col, ...)
    +
    +            # extracting the last element and uses it as decreasing if it 
is boolean
    +            lastElement <- tail(by,1)[[1]]
    +            if (is.logical(lastElement)) {
    +              length(by) <- length(by) - 1
    +              decreasing <- lastElement
    +            }
    +
    +            if (length(decreasing) == 1) {
    +              # in case only 1 boolean argument - decreasing value is 
specified,
    +              # it will be used for all columns
    +              decreasing <- rep(decreasing,length(by))
    --- End diff --
    
    coding style: decreasing, length(by)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to