Skip to content
Closed
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
3 changes: 2 additions & 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 @@ -199,11 +199,12 @@ class Dataset[T] private[sql](
* @since 1.6.0
*/
def mapPartitions[U : Encoder](func: Iterator[T] => Iterator[U]): Dataset[U] = {
encoderFor[T].assertUnresolved()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't need this assert, encoderFor already did this.

new Dataset[U](
sqlContext,
MapPartitions[T, U](
func,
encoderFor[T],
resolvedTEncoder,
encoderFor[U],
encoderFor[U].schema.toAttributes,
logicalPlan))
Expand Down
11 changes: 11 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ class DatasetSuite extends QueryTest with SharedSQLContext {
("a", 2), ("b", 3), ("c", 4))
}

ignore("Dataset should set the resolved encoders internally for maps") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not write a test just for this bug? for example:

val ds = Seq(ClassData("one", 1), ClassData("two", 2)).toDS()
val mapped = ds.map(c => ClassData(c.a, c.b + 1))
checkAnswer(mapped, ClassData("one", 2), ClassData("two", 3))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it could get optimized away when we introduce local execution mode and better pipelining.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add some comment on why.

// TODO: Enable this once we fix SPARK-11793.
val ds: Dataset[(ClassData, Long)] = Seq(ClassData("one", 1), ClassData("two", 2)).toDS()
.map(c => ClassData(c.a, c.b + 1))
.groupBy(p => p).count()

checkAnswer(
ds,
(ClassData("one", 1), 1L), (ClassData("two", 2), 1L))
}

test("select") {
val ds = Seq(("a", 1) , ("b", 2), ("c", 3)).toDS()
checkAnswer(
Expand Down