-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11636][SQL] Support classes defined in the REPL with Encoders #9825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,9 @@ class ReplSuite extends SparkFunSuite { | |
| |import sqlContext.implicits._ | ||
| |case class TestCaseClass(value: Int) | ||
| |sc.parallelize(1 to 10).map(x => TestCaseClass(x)).toDF().collect() | ||
| | | ||
| |// Test Dataset Serialization in the REPL | ||
| |Seq(TestCaseClass(1)).toDS().collect() | ||
| """.stripMargin) | ||
| assertDoesNotContain("error:", output) | ||
| assertDoesNotContain("Exception", output) | ||
|
|
@@ -278,6 +281,27 @@ class ReplSuite extends SparkFunSuite { | |
| assertDoesNotContain("java.lang.ClassNotFoundException", output) | ||
| } | ||
|
|
||
| test("Datasets and encoders") { | ||
| val output = runInterpreter("local", | ||
| """ | ||
| |import org.apache.spark.sql.functions._ | ||
| |import org.apache.spark.sql.Encoder | ||
| |import org.apache.spark.sql.expressions.Aggregator | ||
| |import org.apache.spark.sql.TypedColumn | ||
| |val simpleSum = new Aggregator[Int, Int, Int] with Serializable { | ||
| | def zero: Int = 0 // The initial value. | ||
| | def reduce(b: Int, a: Int) = b + a // Add an element to the running total | ||
| | def merge(b1: Int, b2: Int) = b1 + b2 // Merge intermediate values. | ||
| | def finish(b: Int) = b // Return the final result. | ||
| |}.toColumn | ||
| | | ||
| |val ds = Seq(1, 2, 3, 4).toDS() | ||
| |ds.select(simpleSum).collect | ||
| """.stripMargin) | ||
| assertDoesNotContain("error:", output) | ||
| assertDoesNotContain("Exception", output) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not get this test to fail without this patch.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can see it failing now both in scala 2.10 and 2.11. I will spend more time to understand, if it is possible to fix it in some other way. |
||
| } | ||
|
|
||
| test("SPARK-2632 importing a method from non serializable class and not using it.") { | ||
| val output = runInterpreter("local", | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marmbrus Can you explain more about this change. This change will be difficult to port to 2.11, I can take a stab.
I just wanted to understand if there is an alternate way to solve this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a handle to any outer class that defines an inner class that is going to used in a Spark Dataset so that we can construct new instances on the executors. It might be helpful to also look at the changes in #9602.
@dragos was saying maybe we don't have this problem in 2.11, but I have not investigated at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The REPL in 2.11 is pretty much the Scala standard REPL:
https://github.com/apache/spark/tree/master/repl/scala-2.11/src/main/scala/org/apache/spark/repl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @dragos, that is why I am concerned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in 2.11 you probably don't have this problem, do you? All enclosing entities are objects, and they don't need an outer pointer.