Let old version import note without error

This commit is contained in:
Lee moon soo 2016-11-24 14:19:29 -08:00
parent d09e03fcb9
commit 3ba37b7739
7 changed files with 76 additions and 39 deletions

View file

@ -163,14 +163,18 @@ public class InterpreterOutput extends OutputStream {
synchronized (resultMessageOutputs) {
if (startOfTheNewLine) {
startOfTheNewLine = false;
if (b == '%') {
startOfTheNewLine = false;
firstCharIsPercentSign = true;
buffer.write(b);
previousChar = b;
return;
} else if (b != NEW_LINE_CHAR) {
startOfTheNewLine = false;
}
} else if (b == NEW_LINE_CHAR) {
}
if (b == NEW_LINE_CHAR) {
currentOut = getCurrentOutput();
if (currentOut != null && currentOut.getType() == InterpreterResult.Type.TABLE) {
if (previousChar == NEW_LINE_CHAR) {

View file

@ -72,7 +72,14 @@ public abstract class Job {
private String jobName;
String id;
// since zeppelin-0.7.0, zeppelin stores multiple results of the paragraph
// see ZEPPELIN-212
Object results;
// For backward compatibility of note.json format after ZEPPELIN-212
Object result;
Date dateCreated;
Date dateStarted;
Date dateFinished;
@ -173,7 +180,7 @@ public abstract class Job {
progressUpdator = new JobProgressPoller(this, progressUpdateIntervalMs);
progressUpdator.start();
dateStarted = new Date();
result = jobRun();
results = jobRun();
this.exception = null;
errorMessage = null;
dateFinished = new Date();
@ -182,14 +189,14 @@ public abstract class Job {
LOGGER.error("Job failed", e);
progressUpdator.terminate();
this.exception = e;
result = e.getMessage();
results = e.getMessage();
errorMessage = getStack(e);
dateFinished = new Date();
} catch (Throwable e) {
LOGGER.error("Job failed", e);
progressUpdator.terminate();
this.exception = e;
result = e.getMessage();
results = e.getMessage();
errorMessage = getStack(e);
dateFinished = new Date();
} finally {
@ -215,10 +222,14 @@ public abstract class Job {
errorMessage = getStack(t);
}
public Object getReturn() {
public Object getPreviousResultFormat() {
return result;
}
public Object getReturn() {
return results;
}
public String getJobName() {
return jobName;
}
@ -255,7 +266,7 @@ public abstract class Job {
return dateFinished;
}
public void setResult(Object result) {
this.result = result;
public void setResult(Object results) {
this.results = results;
}
}

View file

@ -117,6 +117,23 @@ public class InterpreterOutputTest implements InterpreterOutputListener {
assertEquals(InterpreterResult.Type.HTML, out.getOutputAt(0).getType());
}
@Test
public void testChangeTypeWithMultipleNewline() throws IOException {
out.write("%html\n");
assertEquals(InterpreterResult.Type.HTML, out.getOutputAt(0).getType());
out.write("%text\n");
assertEquals(InterpreterResult.Type.TEXT, out.getOutputAt(1).getType());
out.write("\n%html\n");
assertEquals(InterpreterResult.Type.HTML, out.getOutputAt(2).getType());
out.write("\n\n%text\n");
assertEquals(InterpreterResult.Type.TEXT, out.getOutputAt(3).getType());
out.write("\n\n\n%html\n");
assertEquals(InterpreterResult.Type.HTML, out.getOutputAt(4).getType());
}
@Test
public void testChangeTypeWithoutData() throws IOException {

View file

@ -132,23 +132,23 @@
config.enabled = true;
}
if (!config.result) {
config.result = {};
if (!config.results) {
config.results = {};
}
};
$scope.$on('updateParagraphOutput', function(event, data) {
if ($scope.paragraph.id === data.paragraphId) {
if (!$scope.paragraph.result) {
$scope.paragraph.result = {};
if (!$scope.paragraph.results) {
$scope.paragraph.results = {};
}
if (!$scope.paragraph.result.msg) {
$scope.paragraph.result.msg = [];
if (!$scope.paragraph.results.msg) {
$scope.paragraph.results.msg = [];
}
var update = ($scope.paragraph.result.msg[data.index]) ? true : false;
var update = ($scope.paragraph.results.msg[data.index]) ? true : false;
$scope.paragraph.result.msg[data.index] = {
$scope.paragraph.results.msg[data.index] = {
data: data.data,
type: data.type
};
@ -156,8 +156,8 @@
if (update) {
$rootScope.$broadcast(
'updateResult',
$scope.paragraph.result.msg[data.index],
$scope.paragraph.config.result[data.index],
$scope.paragraph.results.msg[data.index],
$scope.paragraph.config.results[data.index],
$scope.paragraph,
data.index);
}
@ -785,8 +785,8 @@
$scope.getResultType = function(paragraph) {
var pdata = (paragraph) ? paragraph : $scope.paragraph;
if (pdata.result && pdata.result.type) {
return pdata.result.type;
if (pdata.results && pdata.results.type) {
return pdata.results.type;
} else {
return 'TEXT';
}
@ -957,14 +957,14 @@
data.paragraph.status !== $scope.paragraph.status ||
data.paragraph.jobName !== $scope.paragraph.jobName ||
data.paragraph.title !== $scope.paragraph.title ||
isEmpty(data.paragraph.result) !== isEmpty($scope.paragraph.result) ||
isEmpty(data.paragraph.results) !== isEmpty($scope.paragraph.results) ||
data.paragraph.errorMessage !== $scope.paragraph.errorMessage ||
!angular.equals(data.paragraph.settings, $scope.paragraph.settings) ||
!angular.equals(data.paragraph.config, $scope.paragraph.config))
) {
var statusChanged = (data.paragraph.status !== $scope.paragraph.status);
var resultRefreshed = (data.paragraph.dateFinished !== $scope.paragraph.dateFinished) ||
isEmpty(data.paragraph.result) !== isEmpty($scope.paragraph.result) ||
isEmpty(data.paragraph.results) !== isEmpty($scope.paragraph.results) ||
data.paragraph.status === 'ERROR' || (data.paragraph.status === 'FINISHED' && statusChanged);
if ($scope.paragraph.text !== data.paragraph.text) {
@ -983,13 +983,13 @@
}
/** broadcast update to result controller **/
if (data.paragraph.result && data.paragraph.result.msg) {
for (var i in data.paragraph.result.msg) {
var newResult = data.paragraph.result.msg ? data.paragraph.result.msg[i] : {};
var oldResult = ($scope.paragraph.result && $scope.paragraph.result.msg) ?
$scope.paragraph.result.msg[i] : {};
var newConfig = data.paragraph.config.result ? data.paragraph.config.result[i] : {};
var oldConfig = $scope.paragraph.config.result ? $scope.paragraph.config.result[i] : {};
if (data.paragraph.results && data.paragraph.results.msg) {
for (var i in data.paragraph.results.msg) {
var newResult = data.paragraph.results.msg ? data.paragraph.results.msg[i] : {};
var oldResult = ($scope.paragraph.results && $scope.paragraph.results.msg) ?
$scope.paragraph.results.msg[i] : {};
var newConfig = data.paragraph.config.results ? data.paragraph.config.results[i] : {};
var oldConfig = $scope.paragraph.config.results ? $scope.paragraph.config.results[i] : {};
if (!angular.equals(newResult, oldResult) ||
!angular.equals(newConfig, oldConfig)) {
$rootScope.$broadcast('updateResult', newResult, newConfig, data.paragraph, parseInt(i));
@ -1014,7 +1014,7 @@
$scope.paragraph.title = data.paragraph.title;
$scope.paragraph.lineNumbers = data.paragraph.lineNumbers;
$scope.paragraph.status = data.paragraph.status;
$scope.paragraph.result = data.paragraph.result;
$scope.paragraph.results = data.paragraph.results;
$scope.paragraph.settings = data.paragraph.settings;
$scope.editor.setReadOnly($scope.isRunning());

View file

@ -55,8 +55,8 @@ limitations under the License.
<div class="tableDisplay"
ng-show="!paragraph.config.tableHide"
ng-controller="ResultCtrl"
ng-repeat="result in paragraph.result.msg track by $index"
ng-init="init(result, paragraph.config.result[$index], paragraph, $index)"
ng-repeat="result in paragraph.results.msg track by $index"
ng-init="init(result, paragraph.config.results[$index], paragraph, $index)"
ng-include src="'app/notebook/paragraph/result/result.html'"
>
</div>

View file

@ -139,6 +139,9 @@
// graphMode
$scope.graphMode;
// image data
$scope.imageData;
$scope.init = function(result, config, paragraph, index) {
console.log('result controller init %o %o %o', result, config, index);
updateData(result, config, paragraph, index);
@ -225,8 +228,7 @@
$scope.config = angular.copy(config);
// enable only when it is last result
enableHelium = (index === paragraphRef.result.msg.length - 1);
console.log('enable helium %o %o %o', enableHelium, index, paragraphRef.result.msg.length);
enableHelium = (index === paragraphRef.results.msg.length - 1);
if ($scope.type === 'TABLE') {
var TableData = zeppelin.TableData;
@ -236,6 +238,8 @@
$scope.tableDataComment = tableData.comment;
selectDefaultColsForGraphOption();
} else if ($scope.type === 'IMG') {
$scope.imageData = data;
}
};
@ -453,8 +457,8 @@
var commitParagraphResult = function(title, text, config, params) {
var newParagraphConfig = angular.copy(paragraph.config);
newParagraphConfig.result = newParagraphConfig.result || [];
newParagraphConfig.result[resultIndex] = config;
newParagraphConfig.results = newParagraphConfig.results || [];
newParagraphConfig.results[resultIndex] = config;
websocketMsgSrv.commitParagraph(paragraph.id, title, text, newParagraphConfig, params);
};

View file

@ -209,6 +209,7 @@ public class Notebook implements NoteEventListener {
Note newNote;
try {
Note oldNote = gson.fromJson(reader, Note.class);
convertFromSingleResultToMultipleResultsFormat(oldNote);
newNote = createNote(subject);
if (noteName != null)
newNote.setName(noteName);
@ -383,9 +384,9 @@ public class Notebook implements NoteEventListener {
public void convertFromSingleResultToMultipleResultsFormat(Note note) {
for (Paragraph p : note.paragraphs) {
Object ret = p.getReturn();
Object ret = p.getPreviousResultFormat();
try {
if (ret instanceof Map) {
if (ret != null && ret instanceof Map) {
Map r = ((Map) ret);
if (r.containsKey("code") &&
r.containsKey("msg") &&
@ -419,7 +420,7 @@ public class Notebook implements NoteEventListener {
results.add(new HashMap<>());
}
}
config.put("result", results);
config.put("results", results);
}
}
} catch (Exception e) {