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

    https://github.com/apache/spark/pull/12836#discussion_r66712035
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala ---
    @@ -381,6 +385,50 @@ class RelationalGroupedDataset protected[sql](
       def pivot(pivotColumn: String, values: java.util.List[Any]): 
RelationalGroupedDataset = {
         pivot(pivotColumn, values.asScala)
       }
    +
    +  /**
    +   * Applies the given serialized R function `func` to each group of data. 
For each unique group,
    +   * the function will be passed the group key and an iterator that 
contains all of the elements in
    +   * the group. The function can return an iterator containing elements of 
an arbitrary type which
    +   * will be returned as a new [[DataFrame]].
    +   *
    +   * This function does not support partial aggregation, and as a result 
requires shuffling all
    +   * the data in the [[Dataset]]. If an application intends to perform an 
aggregation over each
    +   * key, it is best to use the reduce function or an
    +   * [[org.apache.spark.sql.expressions#Aggregator Aggregator]].
    +   *
    +   * Internally, the implementation will spill to disk if any given group 
is too large to fit into
    +   * memory.  However, users must take care to avoid materializing the 
whole iterator for a group
    +   * (for example, by calling `toList`) unless they are sure that this is 
possible given the memory
    +   * constraints of their cluster.
    +   *
    +   * @since 2.0.0
    +   */
    +  private[sql] def flatMapGroupsInR(
    +      f: Array[Byte],
    +      packageNames: Array[Byte],
    +      broadcastVars: Array[Object],
    +      outputSchema: StructType): DataFrame = {
    +      val broadcastVarObj = 
broadcastVars.map(_.asInstanceOf[Broadcast[Object]])
    +      val groupingNamedExpressions = groupingExprs.map(alias)
    +      val groupingCols = groupingNamedExpressions.map(Column(_))
    +      val groupingDataFrame = df.select(groupingCols : _*)
    +      val groupingAttributes = groupingNamedExpressions.map(_.toAttribute)
    +      val realOutputSchema = if (outputSchema == null) 
SERIALIZED_R_DATA_SCHEMA else outputSchema
    --- End diff --
    
    @liancheng , thank you for the review comments.
    
    Those are good suggestions, however for:
    
    case 1:  using Option[StructType] ...  -  I gave a try but since this 
method is being called from R side we need to somehow instantiate 
"scala.Option" class and this doesn't seem to be primitive to do in R. 
    From R side we will basically call the following method:
    `org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> flatMapGroupsInR 
(byte[] f, byte[] packageNames, java.lang.Object[] broadcastVars, 
scala.Option<org.apache.spark.sql.types.StructType> outputSchema)`
    
    Case 2: Similar to dapply, gapply forces schema by signature, the default 
value doesn't really work here.
    
    But I can make the changes if it is preferred.



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