You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by bz...@apache.org on 2016/09/02 07:47:37 UTC
zeppelin git commit: [ZEPPELIN-1069]Ignore implicit interpreter when
user enter wrong interpreter name
Repository: zeppelin
Updated Branches:
refs/heads/master 922364f36 -> b89e35e01
[ZEPPELIN-1069]Ignore implicit interpreter when user enter wrong interpreter name
### What is this PR for?
Ignore implicit interpreter when user enter wrong interpreter name
linked to https://github.com/apache/zeppelin/pull/806#issuecomment-227041293
This PR is related to #1113
ZEPPELIN-1069 branch was force push, so couldn't reopen that PR.
### What type of PR is it?
Improvement
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1069
### How should this be tested?
Unit test
Run-time checking
### Screenshots (if appropriate)
![zeppelin-1069-gif](https://cloud.githubusercontent.com/assets/10624086/17268431/d6d9370c-5664-11e6-9274-d0244d60a8c9.gif)
### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no
Author: Minwoo Kang <mi...@outlook.com>
Closes #1248 from mwkang/ZEPPELIN-1069 and squashes the following commits:
3976a96 [Minwoo Kang] Remove wild card import
fa7a194 [Minwoo Kang] Fix CI failed
f0eedeb [Minwoo Kang] Remove unnecessary method.
6e91dfe [Minwoo Kang] Remove unnecessary method.
dd60d72 [Minwoo Kang] Fixed CI
046f5f4 [Minwoo Kang] Modify static import position.
6082e28 [Minwoo Kang] Modify that StringUtils is static import
02a1c2a [Minwoo Kang] Refactor method name
4912c5c [Minwoo Kang] Add test cases
b6520be [Minwoo Kang] Add function that is replName is binding.
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/b89e35e0
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/b89e35e0
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/b89e35e0
Branch: refs/heads/master
Commit: b89e35e01f627a7f47f0dce23d78e2558e7db7ae
Parents: 922364f
Author: Minwoo Kang <mi...@outlook.com>
Authored: Wed Aug 17 13:42:36 2016 +0900
Committer: Alexander Bezzubov <bz...@apache.org>
Committed: Fri Sep 2 16:47:31 2016 +0900
----------------------------------------------------------------------
.../java/org/apache/zeppelin/notebook/Note.java | 20 ++++++++++++++------
.../org/apache/zeppelin/notebook/NoteTest.java | 19 +++++++++++++++++++
2 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/b89e35e0/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
----------------------------------------------------------------------
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 5f0f7c1..1d75d10 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
@@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import com.google.gson.Gson;
-import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,6 +57,11 @@ import org.apache.zeppelin.search.SearchService;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.apache.zeppelin.user.Credentials;
+import static org.apache.commons.lang.StringUtils.EMPTY;
+import static org.apache.commons.lang.StringUtils.isEmpty;
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
+import static org.apache.commons.lang.StringUtils.isBlank;
+
/**
* Binded interpreters for a note
*/
@@ -78,7 +82,7 @@ public class Note implements Serializable, ParagraphJobListener {
private String name = "";
private String id;
- private AtomicReference<String> lastReplName = new AtomicReference<>(StringUtils.EMPTY);
+ private AtomicReference<String> lastReplName = new AtomicReference<>(EMPTY);
private transient ZeppelinConfiguration conf = ZeppelinConfiguration.create();
private Map<String, List<AngularObject>> angularObjects = new HashMap<>();
@@ -124,7 +128,7 @@ public class Note implements Serializable, ParagraphJobListener {
private String getDefaultInterpreterName() {
InterpreterSetting setting = factory.getDefaultInterpreterSetting(getId());
- return null != setting ? setting.getName() : StringUtils.EMPTY;
+ return null != setting ? setting.getName() : EMPTY;
}
void putDefaultReplName() {
@@ -295,13 +299,17 @@ public class Note implements Serializable, ParagraphJobListener {
*/
private void addLastReplNameIfEmptyText(Paragraph p) {
String replName = lastReplName.get();
- if (StringUtils.isEmpty(p.getText()) && StringUtils.isNotEmpty(replName)) {
+ if (isEmpty(p.getText()) && isNotEmpty(replName) && isBinding(replName)) {
p.setText(getInterpreterName(replName) + " ");
}
}
+ public boolean isBinding(String replName) {
+ return factory.getInterpreter(this.getId(), replName) != null;
+ }
+
private String getInterpreterName(String replName) {
- return StringUtils.isBlank(replName) ? StringUtils.EMPTY : "%" + replName;
+ return isBlank(replName) ? EMPTY : "%" + replName;
}
/**
@@ -600,7 +608,7 @@ public class Note implements Serializable, ParagraphJobListener {
}
private void setLastReplName(Paragraph lastParagraphStarted) {
- if (StringUtils.isNotEmpty(lastParagraphStarted.getRequiredReplName())) {
+ if (isNotEmpty(lastParagraphStarted.getRequiredReplName())) {
lastReplName.set(lastParagraphStarted.getRequiredReplName());
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/b89e35e0/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java
index 255e609..4917ac4 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
import org.apache.zeppelin.notebook.repo.NotebookRepo;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.search.SearchService;
@@ -117,6 +118,7 @@ public class NoteTest {
Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName(); //set lastReplName
+ when(interpreterFactory.getInterpreter(note.getId(), "spark")).thenReturn(new MockInterpreter2(null));
Paragraph p = note.addParagraph();
@@ -132,6 +134,7 @@ public class NoteTest {
Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName(); //set lastReplName
+ when(interpreterFactory.getInterpreter(note.getId(), "spark")).thenReturn(new MockInterpreter2(null));
Paragraph p = note.insertParagraph(note.getParagraphs().size());
@@ -150,4 +153,20 @@ public class NoteTest {
assertEquals("spark", note.getLastReplName());
}
+
+ @Test
+ public void isBindingTest() {
+ Note note = spy(new Note());
+ when(note.getId()).thenReturn("test1");
+ InterpreterFactory mockInterpreterFactory = mock(InterpreterFactory.class);
+ note.setInterpreterFactory(mockInterpreterFactory);
+
+ //when is not binding
+ assertFalse(note.isBinding("spark"));
+
+ //when is binding
+ when(mockInterpreterFactory.getInterpreter("test1", "spark")).
+ thenReturn(new MockInterpreter2(null));
+ assertTrue(note.isBinding("spark"));
+ }
}