Repository: zeppelin Updated Branches: refs/heads/master 80d910049 -> 73f1e4859
[ZEPPELIN-1228] Make z.show() work with Dataset ### What is this PR for? z.show() does not work in spark 2.0 ### What type of PR is it? Bug Fix ### Todos * [x] - Make z.show() work with dataset * [x] - add a unittest ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1228 ### How should this be tested? ``` case class Data(n:Int) val data = sc.parallelize(1 to 10).map(i=>Data(i)).toDF data.registerTempTable("data") z.show(spark.sql("select * from data")) ``` ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Lee moon soo <[email protected]> Closes #1224 from Leemoonsoo/ZEPPELIN-1228 and squashes the following commits: 486e00a [Lee moon soo] Make z.show() work with Dataset Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/73f1e485 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/73f1e485 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/73f1e485 Branch: refs/heads/master Commit: 73f1e485936918817386e344adebc9a721eaa5fa Parents: 80d9100 Author: Lee moon soo <[email protected]> Authored: Mon Jul 25 08:02:03 2016 +0900 Committer: Lee moon soo <[email protected]> Committed: Wed Jul 27 08:06:39 2016 +0900 ---------------------------------------------------------------------- .../java/org/apache/zeppelin/spark/ZeppelinContext.java | 11 +++++++++-- .../org/apache/zeppelin/spark/SparkInterpreterTest.java | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/73f1e485/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java ---------------------------------------------------------------------- diff --git a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java index bfd2b46..7bccbac 100644 --- a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java +++ b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java @@ -163,19 +163,26 @@ public class ZeppelinContext { public void show(Object o, int maxResult) { Class cls = null; try { - cls = this.getClass().forName("org.apache.spark.sql.DataFrame"); + cls = this.getClass().forName("org.apache.spark.sql.Dataset"); } catch (ClassNotFoundException e) { } if (cls == null) { try { + cls = this.getClass().forName("org.apache.spark.sql.DataFrame"); + } catch (ClassNotFoundException e) { + } + } + + if (cls == null) { + try { cls = this.getClass().forName("org.apache.spark.sql.SchemaRDD"); } catch (ClassNotFoundException e) { } } if (cls == null) { - throw new InterpreterException("Can not road DataFrame/SchemaRDD class"); + throw new InterpreterException("Can not road Dataset/DataFrame/SchemaRDD class"); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/73f1e485/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java ---------------------------------------------------------------------- diff --git a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java index 88208ab..badc4e2 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java @@ -189,6 +189,13 @@ public class SparkInterpreterTest { } @Test + public void testZShow() { + repl.interpret("case class Person(name:String, age:Int)\n", context); + repl.interpret("val people = sc.parallelize(Seq(Person(\"moon\", 33), Person(\"jobs\", 51), Person(\"gates\", 51), Person(\"park\", 34)))\n", context); + assertEquals(Code.SUCCESS, repl.interpret("z.show(people.toDF)", context).code()); + } + + @Test public void testSparkSql(){ repl.interpret("case class Person(name:String, age:Int)\n", context); repl.interpret("val people = sc.parallelize(Seq(Person(\"moon\", 33), Person(\"jobs\", 51), Person(\"gates\", 51), Person(\"park\", 34)))\n", context);
