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

    https://github.com/apache/spark/pull/9222#discussion_r42733892
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/api/r/SQLUtils.scala 
---
    @@ -130,16 +130,17 @@ private[r] object SQLUtils {
       }
     
       def dfToCols(df: DataFrame): Array[Array[Any]] = {
    -    // localDF is Array[Row]
    -    val localDF = df.collect()
    +    val localDF: Array[Row] = df.collect()
         val numCols = df.columns.length
    +    val numRows = localDF.length
     
    -    // result is Array[Array[Any]]
    -    (0 until numCols).map { colIdx =>
    -      localDF.map { row =>
    -        row(colIdx)
    -      }
    -    }.toArray
    +    val colArray = new Array[Array[Any]](numCols)
    +    for (colNo <- 0 to (numCols - 1)) colArray.update(colNo, new 
Array[Any](numRows))
    --- End diff --
    
    What about the following code:
        for (colIdx <- 0 until numCols) {
          colArray(colIdx) = new Array[Any](numRows)
        }
        for (rowIdx <- 0 until numRows; colIdx <- 0 until numCols) {
          colArray(colIdx)(rowIdx) = localDF(rowIdx)(colIdx)
        }


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