title: Using KeyValueGroupedDataset cogroup for more than two datasets
body: <p>In Spark's old RDD-based API, it was possible to "cogroup" up to 3 RDDs with your original RDD in a single <code>cogroup</code> call, assuming they were all pair RDDs with the same key.</p>
  
  <p>In the new Dataset API, it seems that I have to call <code>groupByKey</code> twice and <code>cogroup</code> once for each dataset I want to group with. </p>
  
  <p>For example, imagine I have a dataset with recent activity data and two 'metadata' datasets that I use to provide context for the activity, and I want to cogroup them (the history and profile can be large structures, and if I join them with the activity the joined dataset will be unreasonably large). Here's what I do today:</p>
  
  <pre><code>// These data types all have an "id" field for correlation
  val activityData: Dataset[Activity] = getActivity()
  val locationHistory: Dataset[LocationHistory] = getLocationHistory()
  val profiles: Dataset[Profile] = getProfiles()
  
  // This first cogroup aligns activity with location history
  val partialGroup = activityData.groupByKey(_.id)
      .cogroup(locationHistory.groupByKey(_.id)) {
          case (id, activity, location) if activity.nonEmpty =&gt;
              (id, activity, location)
  
          case _ =&gt; None
      }
  
  // This second cogroup adds the profile to complete the grouping
  val fullGroup = partialGroup.groupByKey(_._1)
      .cogroup(profiles.groupByKey(_.id)) {
          case (id, activityAndLocation, profile) =&gt;
              activityAndLocation.map { case(_, activity, location) =&gt;
                  (id, activity, location, profile)
              }
      }
  </code></pre>
  
  <p>It seems a bit long for what would be essentially a one-liner in the RDD API. Is there another way to accomplish this in the Dataset API that doesn't require as much repetition?           </p>