You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2017/01/10 18:37:46 UTC

zeppelin git commit: [ZEPPELIN-1914] Preserve spaces, newlines in text output (BUG)

Repository: zeppelin
Updated Branches:
  refs/heads/master 31085cc03 -> 835b82faf


[ZEPPELIN-1914] Preserve spaces, newlines in text output (BUG)

### What is this PR for?

Fixed to preserve spaces, newlines in text output.

![image](https://cloud.githubusercontent.com/assets/4968473/21754393/5cbad382-d642-11e6-833d-c97018ccc8e9.png)

### What type of PR is it?
[Bug Fix]

### Todos
* [x] - Refactored `result.controll.js`
* [x] - Removed the unused html file `result-results.html`
* [x] - Preserved spaces, newlines

### What is the Jira issue?

[ZEPPELIN-1914](https://issues.apache.org/jira/browse/ZEPPELIN-1914)

### How should this be tested?

1. Build Zeppelin with Spark 2.0, SparkR
2. Run Zeppelin with Spark 2.0+
3. Make sure that your `spark` interpreter can use `spark.r`
4. Execute this paragraph

(**Of course, you can use other paragraph results which include consequent spaces, newlines instead of**)

```
%sparkrr

mtcarsDF <- createDataFrame(mtcars)
model <- glm(vs ~ mpg + disp + hp + wt , data = mtcarsDF, family = "binomial")
summary(model)
```

### Screenshots (if appropriate)

![image](https://cloud.githubusercontent.com/assets/4968473/21754397/6ecdaeb4-d642-11e6-9e5e-63630a45aa92.png)

### Questions:
* Does the licenses files need update? - NO
* Is there breaking changes for older versions? - NO
* Does this needs documentation? - NO

Author: 1ambda <1a...@gmail.com>

Closes #1874 from 1ambda/ZEPPELIN-1914/respect-spaces-in-TEXT-output and squashes the following commits:

4c2aa12 [1ambda] fix: Respect whitespaces in TEXT result
8a3c051 [1ambda] chore: Remove unused file
a9db952 [1ambda] refactor: Use 1 funcs to get textElem
a9d9409 [1ambda] style: Remove useless newlines in R related files


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/835b82fa
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/835b82fa
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/835b82fa

Branch: refs/heads/master
Commit: 835b82faf7c82b088236909aa021a0b34202b96a
Parents: 31085cc
Author: 1ambda <1a...@gmail.com>
Authored: Mon Jan 9 07:58:51 2017 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Tue Jan 10 10:37:43 2017 -0800

----------------------------------------------------------------------
 .../zeppelin/spark/SparkRInterpreter.java       |  1 -
 .../org/apache/zeppelin/spark/ZeppelinR.java    | 14 -----
 .../zeppelin/spark/ZeppelinRDisplay.scala       |  4 --
 .../src/app/notebook/paragraph/paragraph.css    |  4 ++
 .../src/app/notebook/paragraph/paragraph.html   |  3 +-
 .../paragraph/result/result-results.html        | 62 --------------------
 .../paragraph/result/result.controller.js       | 14 +++--
 .../app/notebook/paragraph/result/result.html   |  5 +-
 8 files changed, 16 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/spark/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
----------------------------------------------------------------------
diff --git a/spark/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java b/spark/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
index ef8e9fc..8f3e93c 100644
--- a/spark/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
+++ b/spark/src/main/java/org/apache/zeppelin/spark/SparkRInterpreter.java
@@ -230,5 +230,4 @@ public class SparkRInterpreter extends Interpreter {
       return false;
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinR.java
----------------------------------------------------------------------
diff --git a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinR.java b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinR.java
index 95bc587..b46001a 100644
--- a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinR.java
+++ b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinR.java
@@ -57,7 +57,6 @@ public class ZeppelinR implements ExecuteResultHandler {
   boolean rScriptInitialized = false;
   Integer rScriptInitializeNotifier = new Integer(0);
 
-
   /**
    * Request to R repl
    */
@@ -103,8 +102,6 @@ public class ZeppelinR implements ExecuteResultHandler {
   boolean rResponseError = false;
   Integer rResponseNotifier = new Integer(0);
 
-
-
   /**
    * Create ZeppelinR instance
    * @param rCmdPath R repl commandline path
@@ -216,7 +213,6 @@ public class ZeppelinR implements ExecuteResultHandler {
     }
   }
 
-
   /**
    * Send request to r repl and return response
    * @return responseValue
@@ -257,7 +253,6 @@ public class ZeppelinR implements ExecuteResultHandler {
     }
   }
 
-
   /**
    * Wait until src/main/resources/R/zeppelin_sparkr.R is initialized
    * and call onScriptInitialized()
@@ -286,14 +281,11 @@ public class ZeppelinR implements ExecuteResultHandler {
       e.printStackTrace();
     }
 
-
     if (rScriptInitialized == false) {
       throw new InterpreterException("sparkr is not responding " + errorMessage);
     }
   }
 
-
-
   /**
    * invoked by src/main/resources/R/zeppelin_sparkr.R
    * @return
@@ -337,7 +329,6 @@ public class ZeppelinR implements ExecuteResultHandler {
     }
   }
 
-
   /**
    * Create R script in tmp dir
    */
@@ -381,7 +372,6 @@ public class ZeppelinR implements ExecuteResultHandler {
     return zeppelinR.get(hashcode);
   }
 
-
   /**
    * Pass InterpreterOutput to capture the repl output
    * @param out
@@ -390,8 +380,6 @@ public class ZeppelinR implements ExecuteResultHandler {
     outputStream.setInterpreterOutput(out);
   }
 
-
-
   @Override
   public void onProcessComplete(int i) {
     logger.info("process complete {}", i);
@@ -403,6 +391,4 @@ public class ZeppelinR implements ExecuteResultHandler {
     logger.error(e.getMessage(), e);
     rScriptRunning = false;
   }
-
-
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/spark/src/main/scala/org/apache/zeppelin/spark/ZeppelinRDisplay.scala
----------------------------------------------------------------------
diff --git a/spark/src/main/scala/org/apache/zeppelin/spark/ZeppelinRDisplay.scala b/spark/src/main/scala/org/apache/zeppelin/spark/ZeppelinRDisplay.scala
index fe4072d..a9014c2 100644
--- a/spark/src/main/scala/org/apache/zeppelin/spark/ZeppelinRDisplay.scala
+++ b/spark/src/main/scala/org/apache/zeppelin/spark/ZeppelinRDisplay.scala
@@ -88,7 +88,6 @@ object ZeppelinRDisplay {
   }
 
   private def htmlDisplay(body: Element, imageWidth: String): RDisplay = {
-
     var div = new String()
 
     for (element <- body.children) {
@@ -101,7 +100,6 @@ object ZeppelinRDisplay {
       val r = (pattern findFirstIn eHtml).getOrElse("")
 
       div = div + eOuterHtml.replace(r, "")
-
     }
 
     val content =  div
@@ -115,7 +113,5 @@ object ZeppelinRDisplay {
     }
 
     RDisplay(body.html, HTML, SUCCESS)
-
   }
-
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/zeppelin-web/src/app/notebook/paragraph/paragraph.css
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.css b/zeppelin-web/src/app/notebook/paragraph/paragraph.css
index b2a9045..961a5f0 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.css
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.css
@@ -72,6 +72,10 @@ table.dataTable.table-condensed .sorting_desc:after {
   font-size: 12px !important;
 }
 
+.plainTextContent{
+  white-space:pre-wrap; /** to preserve white-space and newlines of result */
+}
+
 .graphContainer {
   position: relative;
   margin-bottom: 5px;

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/zeppelin-web/src/app/notebook/paragraph/paragraph.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.html b/zeppelin-web/src/app/notebook/paragraph/paragraph.html
index fac7aed..95ad9eb 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.html
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.html
@@ -56,8 +56,7 @@ limitations under the License.
          ng-controller="ResultCtrl"
          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'"
-         >
+         ng-include src="'app/notebook/paragraph/result/result.html'">
     </div>
     <div id="{{paragraph.id}}_error"
          class="error text"

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/zeppelin-web/src/app/notebook/paragraph/result/result-results.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/result/result-results.html b/zeppelin-web/src/app/notebook/paragraph/result/result-results.html
deleted file mode 100644
index 13f050f..0000000
--- a/zeppelin-web/src/app/notebook/paragraph/result/result-results.html
+++ /dev/null
@@ -1,62 +0,0 @@
-<!--
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
--->
-<div
-  id="p{{id}}_resize"
-  ng-if="!config.helium.activeApp"
-  style="padding-bottom: 5px;"
-  resize='{"allowresize": "{{!asIframe && !viewOnly}}", "graphType": "{{type}}"}'
-     resizable on-resize="resize(width, height);">
-  <div ng-include src="'app/notebook/paragraph/result/result-graph.html'"></div>
-
-  <div id="{{id}}_comment"
-       class="text"
-       ng-if="type == 'TABLE' && tableDataComment"
-       ng-bind-html="tableDataComment">
-  </div>
-
-  <div id="p{{id}}_text"
-       ng-if="type == 'TEXT'">
-    <div class="fa fa-level-down scroll-paragraph-down"
-         ng-show="showScrollDownIcon(id)"
-         ng-click="scrollParagraphDown(id)"
-         tooltip="Follow Output"></div>
-    <div id="p{{id}}_text"
-         style="max-height: {{config.graph.height}}px; overflow: auto"
-         class="text"></div>
-    <div class="fa fa-chevron-up scroll-paragraph-up"
-         ng-show="showScrollUpIcon(id)"
-         ng-click="scrollParagraphUp(id)"
-         tooltip="Scroll Top"></div>
-  </div>
-
-  <div id="p{{id}}_html"
-       class="resultContained"
-       ng-if="type == 'HTML'">
-  </div>
-
-  <div id="p{{id}}_angular"
-       class="resultContained"
-       ng-if="type == 'ANGULAR'">
-  </div>
-
-  <img id="{{id}}_img"
-       ng-if="type == 'IMG'"
-       ng-src="{{getBase64ImageSrc(result.data)}}" />
-</div>
-
-<div ng-repeat="app in apps">
-  <div id="p{{app.id}}"
-       ng-show="config.helium.activeApp == app.id">
-  </div>
-</div>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/zeppelin-web/src/app/notebook/paragraph/result/result.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/result/result.controller.js b/zeppelin-web/src/app/notebook/paragraph/result/result.controller.js
index fb1a96e..f494029 100644
--- a/zeppelin-web/src/app/notebook/paragraph/result/result.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/result/result.controller.js
@@ -299,10 +299,14 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
       $timeout(retryRenderer);
     };
 
+    var getTextEl = function (paragraphId) {
+      return angular.element('#p' + $scope.id + '_text');
+    }
+
     var textRendererInitialized = false;
     var renderText = function() {
       var retryRenderer = function() {
-        var textEl = angular.element('#p' + $scope.id + '_text');
+        var textEl = getTextEl($scope.id);
         if (textEl.length) {
           // clear all lines before render
           clearTextOutput();
@@ -314,7 +318,7 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
             flushAppendQueue();
           }
 
-          angular.element('#p' + $scope.id + '_text').bind('mousewheel', function(e) {
+          getTextEl($scope.id).bind('mousewheel', function(e) {
             $scope.keepScrollDown = false;
           });
         } else {
@@ -325,7 +329,7 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
     };
 
     var clearTextOutput = function() {
-      var textEl = angular.element('#p' + $scope.id + '_text');
+      var textEl = getTextEl($scope.id);
       if (textEl.length) {
         textEl.children().remove();
       }
@@ -344,7 +348,7 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
         textAppendQueueBeforeInitialize.push(msg);
       } else {
         flushAppendQueue();
-        var textEl = angular.element('#p' + $scope.id + '_text');
+        var textEl = getTextEl($scope.id);
         if (textEl.length) {
           var lines = msg.split('\n');
           for (var i = 0; i < lines.length; i++) {
@@ -352,7 +356,7 @@ import ScatterchartVisualization from '../../../visualization/builtins/visualiza
           }
         }
         if ($scope.keepScrollDown) {
-          var doc = angular.element('#p' + $scope.id + '_text');
+          var doc = getTextEl($scope.id);
           doc[0].scrollTop = doc[0].scrollHeight;
         }
       }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/835b82fa/zeppelin-web/src/app/notebook/paragraph/result/result.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/result/result.html b/zeppelin-web/src/app/notebook/paragraph/result/result.html
index 7480a7c..298fd0b 100644
--- a/zeppelin-web/src/app/notebook/paragraph/result/result.html
+++ b/zeppelin-web/src/app/notebook/paragraph/result/result.html
@@ -51,8 +51,7 @@ limitations under the License.
          ng-bind-html="tableDataComment">
     </div>
 
-    <div id="p{{id}}_text"
-         ng-if="type == 'TEXT'"
+    <div ng-if="type == 'TEXT'"
          class="plainTextContainer">
       <div class="fa fa-level-down scroll-paragraph-down"
            ng-show="showScrollDownIcon()"
@@ -60,7 +59,7 @@ limitations under the License.
            tooltip="Follow Output"></div>
       <div id="p{{id}}_text"
            style="max-height: {{config.graph.height}}px; overflow: auto"
-           class="text"></div>
+           class="text plainTextContent"></div>
       <div class="fa fa-chevron-up scroll-paragraph-up"
            ng-show="showScrollUpIcon()"
            ng-click="scrollParagraphUp()"