Github user NarineK commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9012#discussion_r42814122
  
    --- Diff: R/pkg/R/DataFrame.R ---
    @@ -1457,15 +1457,142 @@ setMethod("join",
                 dataFrame(sdf)
               })
     
    -#' @rdname merge
    +#'
     #' @name merge
     #' @aliases join
    +#' @title Merges two data frames
    +#' @param x the first data frame to be joined
    +#' @param y the second data frame to be joined
    +#' @param by a character vector specifying the join columns. If by is not
    +#'   specified, the common column names in \code{x} and \code{y} will be 
used.
    +#' @param by.x a character vector specifying the joining columns for x.
    +#' @param by.y a character vector specifying the joining columns for y.
    +#' @param all.x a boolean value indicating whether all the rows in x should
    +#'              be including in the join
    +#' @param all.y a boolean value indicating whether all the rows in y should
    +#'              be including in the join
    +#' @param sort a logical argument indicating whether the resulting columns 
should be sorted
    +#' @details  If all.x and all.y are set to FALSE, a natural join will be 
returned. If
    +#'   all.x is set to TRUE and all.y is set to FALSE, a left outer join will
    +#'   be returned. If all.x is set to FALSE and all.y is set to TRUE, a 
right
    +#'   outer join will be returned. If all.x and all.y are set to TRUE, a 
full
    +#'   outer join will be returned.
    +#' @rdname merge
    +#' @export
    +#' @examples
    +#'\dontrun{
    +#' sc <- sparkR.init()
    +#' sqlContext <- sparkRSQL.init(sc)
    +#' df1 <- jsonFile(sqlContext, path)
    +#' df2 <- jsonFile(sqlContext, path2)
    +#' merge(df1, df2) # Performs a Cartesian
    +#' merge(df1, df2, by = "col1") # Performs an inner join based on 
expression
    +#' merge(df1, df2, by.x = "col1", by.y = "col2", all.y = TRUE)
    +#' merge(df1, df2, by.x = "col1", by.y = "col2", all.x = TRUE)
    +#' merge(df1, df2, by.x = "col1", by.y = "col2", all.x = TRUE, all.y = 
TRUE)
    +#' merge(df1, df2, by.x = "col1", by.y = "col2", all = TRUE, sort = FALSE)
    +#' merge(df1, df2, by = "col1", all = TRUE, suffixes = c("-X", "-Y"))
    +#' }
     setMethod("merge",
               signature(x = "DataFrame", y = "DataFrame"),
    -          function(x, y, joinExpr = NULL, joinType = NULL, ...) {
    -            join(x, y, joinExpr, joinType)
    -          })
    +          function(x, y, by = intersect(names(x), names(y)), by.x = by, 
by.y = by,
    +                   all = FALSE, all.x = all, all.y = all,
    +                   sort = TRUE, suffixes = c("_x","_y"), ... ) {
    --- End diff --
    
    Hi @mattpollock, thank you for your comment.
    Well, I checked R's documentation again and it seems that R is adding 
suffixes only for the columns which are not in the by. If the columns are in 
the by and have the same names, only 1 of them is being considered. 
    I personally think that a quick fix with suffixes = c("", "_y") is not 
really nice.
    If we want to have it exactly like R then we can drop some columns after 
join and have suffixes only for columns not in 'by'. This will make the logic 
more complicated and most probably slow it down because of the drops... Let me 
know what do you think @shivaram @felixcheung @sun-rui 


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to