[ 
https://issues.apache.org/jira/browse/SPARK-12922?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15351311#comment-15351311
 ] 

Timothy Hunter commented on SPARK-12922:
----------------------------------------

[~Narine] while working on a similar function for python [1], we found it 
easier to have the following changes:
 - the keys are appended by default to the spark dataframe being returned
 - the output schema that the users provides is the schema of the R data frame 
and does not include the keys

Here were our reasons to depart from the R implementation of gapply:
 - in most cases, users will want to know the key associated with a result -> 
appending the key is the sensible default
 - most functions in the SQL interface and in MLlib append columns, and gapply 
departs from this philosophy
 - for the cases when they do not need it, adding the key is a fraction of the 
computation time and of the output size
 - from a formal perspective, it makes calling gapply fully transparent to the 
type of the key: it is easier to build a function with gapply because it does 
not need to know anything about the key

I think it would make sense to make this change to the R's gapply 
implementation. Let me know what you think about it.

[1] 
https://github.com/databricks/spark-sklearn/blob/master/python/spark_sklearn/group_apply.py

> Implement gapply() on DataFrame in SparkR
> -----------------------------------------
>
>                 Key: SPARK-12922
>                 URL: https://issues.apache.org/jira/browse/SPARK-12922
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SparkR
>    Affects Versions: 1.6.0
>            Reporter: Sun Rui
>            Assignee: Narine Kokhlikyan
>             Fix For: 2.0.0
>
>
> gapply() applies an R function on groups grouped by one or more columns of a 
> DataFrame, and returns a DataFrame. It is like GroupedDataSet.flatMapGroups() 
> in the Dataset API.
> Two API styles are supported:
> 1.
> {code}
> gd <- groupBy(df, col1, ...)
> gapply(gd, function(grouping_key, group) {}, schema)
> {code}
> 2.
> {code}
> gapply(df, grouping_columns, function(grouping_key, group) {}, schema) 
> {code}
> R function input: grouping keys value, a local data.frame of this grouped 
> data 
> R function output: local data.frame
> Schema specifies the Row format of the output of the R function. It must 
> match the R function's output.
> Note that map-side combination (partial aggregation) is not supported, user 
> could do map-side combination via dapply().



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to