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

    https://github.com/apache/spark/pull/8276#discussion_r37465795
  
    --- Diff: R/pkg/R/DataFrame.R ---
    @@ -628,18 +628,49 @@ setMethod("dim",
     setMethod("collect",
               signature(x = "DataFrame"),
               function(x, stringsAsFactors = FALSE) {
    -            # listCols is a list of raw vectors, one per column
    -            listCols <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", 
"dfToCols", x@sdf)
    -            cols <- lapply(listCols, function(col) {
    -              objRaw <- rawConnection(col)
    -              numRows <- readInt(objRaw)
    -              col <- readCol(objRaw, numRows)
    -              close(objRaw)
    -              col
    -            })
    -            names(cols) <- columns(x)
    -            do.call(cbind.data.frame, list(cols, stringsAsFactors = 
stringsAsFactors))
    -          })
    +            names <- columns(x)
    +            ncol <- length(names)
    +            if (ncol <= 0) {
    +              # empty data.frame with 0 columns and 0 rows
    +              data.frame()
    +            } else {
    +              # listCols is a list of columns
    +              listCols <- 
callJStatic("org.apache.spark.sql.api.r.SQLUtils", "dfToCols", x@sdf)
    +              stopifnot(length(listCols) == ncol)
    +              
    +              # An empty data.frame with 0 columns and number of rows as 
collected
    +              nrow <- length(listCols[[1]])
    +              if (nrow <= 0) {
    +                df <- data.frame()
    +              } else {
    +                df <- data.frame(row.names = c(1 : nrow))                
    +              }
    +              
    +              # Append columns one by one
    +              for (colIndex in 1 : ncol) {
    +                # Note: appending a column of list type into a data.frame 
so that
    +                # data of complex type can be held. But getting a cell 
from a column
    +                # of list type returns a list instead of a vector. So for 
columns of
    +                # non-complex type, append them as vector.
    +                col <- listCols[[colIndex]]
    +                if (length(col) <= 0) {
    +                  df[[names[colIndex]]] <- col
    --- End diff --
    
    this is just to handle empty columns ? Can't we just return from line 644 
if one of the columns is empty ? Or do we want to handle cases where some 
columns are empty and some are not etc. 


---
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