diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index a73aad95a8f..1deb3f88299 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -175,17 +175,23 @@ public void addCloneParagraph(Paragraph srcParagraph) { Map config = new HashMap<>(srcParagraph.getConfig()); Map param = new HashMap<>(srcParagraph.settings.getParams()); Map form = new HashMap<>(srcParagraph.settings.getForms()); - Gson gson = new Gson(); - InterpreterResult result = gson.fromJson( - gson.toJson(srcParagraph.getReturn()), - InterpreterResult.class); newParagraph.setConfig(config); newParagraph.settings.setParams(param); newParagraph.settings.setForms(form); newParagraph.setText(srcParagraph.getText()); newParagraph.setTitle(srcParagraph.getTitle()); - newParagraph.setReturn(result, null); + + try { + Gson gson = new Gson(); + String resultJson = gson.toJson(srcParagraph.getReturn()); + InterpreterResult result = gson.fromJson(resultJson, InterpreterResult.class); + newParagraph.setReturn(result, null); + } catch (Exception e) { + // 'result' part of Note consists of exception, instead of actual interpreter results + logger.warn("Paragraph " + srcParagraph.getId() + " has a result with exception. " + + e.getMessage()); + } synchronized (paragraphs) { paragraphs.add(newParagraph); diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index 23a4b1b40b8..457a9c790cd 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -308,6 +308,31 @@ public void testAutoRestartInterpreterAfterSchedule() throws InterruptedExceptio notebook.refreshCron(note.id()); } + @Test + public void testExportAndImportNote() throws IOException, CloneNotSupportedException, + InterruptedException { + Note note = notebook.createNote(); + note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); + + final Paragraph p = note.addParagraph(); + String simpleText = "hello world"; + p.setText(simpleText); + + note.runAll(); + while(p.isTerminated()==false || p.getResult()==null) Thread.yield(); + + String exportedNoteJson = notebook.exportNote(note.getId()); + + Note importedNote = notebook.importNote(exportedNoteJson, "Title"); + + Paragraph p2 = importedNote.getParagraphs().get(0); + + // Test + assertEquals(p.getId(), p2.getId()); + assertEquals(p.text, p2.text); + assertEquals(p.getResult().message(), p2.getResult().message()); + } + @Test public void testCloneNote() throws IOException, CloneNotSupportedException, InterruptedException {