You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/10/11 11:04:24 UTC

[GitHub] [spark] hagerf commented on a change in pull request #26087: [SPARK-29427][SQL] Create KeyValueGroupedDataset from existing columns in DataFrame

hagerf commented on a change in pull request #26087: [SPARK-29427][SQL] Create KeyValueGroupedDataset from existing columns in DataFrame
URL: https://github.com/apache/spark/pull/26087#discussion_r333936540
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
 ##########
 @@ -1725,6 +1725,30 @@ class Dataset[T] private[sql](
       withGroupingKey.newColumns)
   }
 
+  /**
+   * Returns a [[KeyValueGroupedDataset]] where the data is grouped by a row of given
+   * columns.
+   *
+   * @group typedrel
+   * @since 3.0.0
+   */
+  @scala.annotation.varargs
+  def groupByRelationKey(
+      col1: String,
+      cols: String*): KeyValueGroupedDataset[Row, Row] = {
+    val colNames: Seq[String] = col1 +: cols
+    val keyAttrs = colNames.map(colName => resolve(colName).toAttribute)
+    val keySchema = StructType.fromAttributes(keyAttrs)
+    val keyEncoder = RowEncoder(keySchema)
+    val valEncoder = RowEncoder(schema)
 
 Review comment:
   I don't see why we couldn't keep the encoder that is already present in the Dataset. With this approach we lose that type information. I'd prefer doing this:
   ```
   def groupByRelationKey(
         col1: String,
         cols: String*): KeyValueGroupedDataset[Row, T] = {
       val colNames: Seq[String] = col1 +: cols
       val keyAttrs = colNames.map(colName => resolve(colName).toAttribute)
       val keySchema = StructType.fromAttributes(keyAttrs)
       val keyEncoder = RowEncoder(keySchema)
       new KeyValueGroupedDataset(
         keyEncoder,
         encoder,
         queryExecution,
         logicalPlan.output,
         keyAttrs)
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org