Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ class Dataset[T] private[sql](
* @since 3.0.0
*/
@scala.annotation.varargs
def groupByRelationKey(
def groupByKey(
col1: String,
cols: String*): KeyValueGroupedDataset[Row, T] = {
val colNames: Seq[String] = col1 +: cols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2204,14 +2204,14 @@ class DataFrameSuite extends QueryTest with SharedSparkSession {
}
}

test("groupByRelationKey") {
test("groupByKey relational") {
val df1 = Seq((1, 2, 3), (2, 3, 4)).toDF("a", "b", "c")
.repartition($"a", $"b").sortWithinPartitions("a", "b")
val df2 = Seq((1, 2, 4), (2, 3, 5)).toDF("a", "b", "c")
.repartition($"a", $"b").sortWithinPartitions("a", "b")

val df3 = df1.groupByRelationKey("a", "b")
.cogroup(df2.groupByRelationKey("a", "b")) { case (key, data1, data2) =>
val df3 = df1.groupByKey("a", "b")
.cogroup(df2.groupByKey("a", "b")) { case (key, data1, data2) =>
data1.zip(data2).map { p =>
p._1.getInt(2) + p._2.getInt(2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,14 +1861,14 @@ class DatasetSuite extends QueryTest with SharedSparkSession {
}
}

test("groupByRelationKey") {
test("groupByKey relational") {
val df1 = Seq(DoubleData(1, "one"), DoubleData(2, "two"), DoubleData( 3, "three")).toDS()
.repartition($"id").sortWithinPartitions("id")
val df2 = Seq(DoubleData(5, "one"), DoubleData(1, "two"), DoubleData( 3, "three")).toDS()
.repartition($"id").sortWithinPartitions("id")

val df3 = df1.groupByRelationKey("id").keyAs[Int]
.cogroup(df2.groupByRelationKey("id").keyAs[Int]) { case (key, data1, data2) =>
val df3 = df1.groupByKey("id").keyAs[Int]
.cogroup(df2.groupByKey("id").keyAs[Int]) { case (key, data1, data2) =>
if (key == 1) {
Iterator(DoubleData(key, (data1 ++ data2).foldLeft("")((cur, next) => cur + next.val1)))
} else Iterator.empty
Expand Down