Repository: zeppelin Updated Branches: refs/heads/master 0431fdb88 -> 214737574
[Bugfix] Wrong return value of HDFSFileInterpreter completion. ### What is this PR for? This PR fixes auto competion of HDFSFileInterpreter. ### What type of PR is it? Bug Fix ### How should this be tested? Please refer to test case. ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: astroshim <[email protected]> Closes #1141 from astroshim/bugfix/HDFSFileInterpreterCompletion and squashes the following commits: 81d4dee [astroshim] add space after , 9831e0b [astroshim] add testcase 7cc30c3 [astroshim] bugfix HDFSFileInterpreter completion Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/21473757 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/21473757 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/21473757 Branch: refs/heads/master Commit: 2147375745a59f3429d09e4ff3e424966f73e5c6 Parents: 0431fdb Author: astroshim <[email protected]> Authored: Thu Jul 7 14:08:53 2016 +0900 Committer: Alexander Bezzubov <[email protected]> Committed: Mon Jul 18 10:51:17 2016 +0900 ---------------------------------------------------------------------- .../apache/zeppelin/file/HDFSFileInterpreter.java | 16 ++++++++-------- .../zeppelin/file/HDFSFileInterpreterTest.java | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/21473757/file/src/main/java/org/apache/zeppelin/file/HDFSFileInterpreter.java ---------------------------------------------------------------------- diff --git a/file/src/main/java/org/apache/zeppelin/file/HDFSFileInterpreter.java b/file/src/main/java/org/apache/zeppelin/file/HDFSFileInterpreter.java index 480d96a..43dd048 100644 --- a/file/src/main/java/org/apache/zeppelin/file/HDFSFileInterpreter.java +++ b/file/src/main/java/org/apache/zeppelin/file/HDFSFileInterpreter.java @@ -262,19 +262,19 @@ public class HDFSFileInterpreter extends FileInterpreter { @Override public List<InterpreterCompletion> completion(String buf, int cursor) { logger.info("Completion request at position\t" + cursor + " in string " + buf); - final List suggestions = new ArrayList<>(); + final List<InterpreterCompletion> suggestions = new ArrayList<>(); if (StringUtils.isEmpty(buf)) { - suggestions.add("ls"); - suggestions.add("cd"); - suggestions.add("pwd"); + suggestions.add(new InterpreterCompletion("ls", "ls")); + suggestions.add(new InterpreterCompletion("cd", "cd")); + suggestions.add(new InterpreterCompletion("pwd", "pwd")); return suggestions; } //part of a command == no spaces if (buf.split(" ").length == 1){ - if ("cd".contains(buf)) suggestions.add("cd"); - if ("ls".contains(buf)) suggestions.add("ls"); - if ("pwd".contains(buf)) suggestions.add("pwd"); + if ("cd".contains(buf)) suggestions.add(new InterpreterCompletion("cd", "cd")); + if ("ls".contains(buf)) suggestions.add(new InterpreterCompletion("ls", "ls")); + if ("pwd".contains(buf)) suggestions.add(new InterpreterCompletion("pwd", "pwd")); return suggestions; } @@ -311,7 +311,7 @@ public class HDFSFileInterpreter extends FileInterpreter { String beforeLastPeriod = unfinished.substring(0, unfinished.lastIndexOf('.') + 1); //beforeLastPeriod should be the start of fs.pathSuffix, so take the end of it. String suggestedFinish = fs.pathSuffix.substring(beforeLastPeriod.length()); - suggestions.add(suggestedFinish); + suggestions.add(new InterpreterCompletion(suggestedFinish, suggestedFinish)); } } return suggestions; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/21473757/file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java ---------------------------------------------------------------------- diff --git a/file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java b/file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java index 3c87fa6..2c1a565 100644 --- a/file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java +++ b/file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java @@ -22,9 +22,13 @@ import com.google.gson.Gson; import junit.framework.TestCase; import static org.junit.Assert.*; import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.junit.Test; import org.slf4j.Logger; + +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Properties; import java.lang.Override; import java.lang.String; @@ -100,6 +104,17 @@ public class HDFSFileInterpreterTest extends TestCase { // we should be back to first result after all this navigation assertEquals(result1.message(), result11.message()); + // auto completion test + List expectedResultOne = Arrays.asList( + new InterpreterCompletion("ls", "ls")); + List expectedResultTwo = Arrays.asList( + new InterpreterCompletion("pwd", "pwd")); + List<InterpreterCompletion> resultOne = t.completion("l", 0); + List<InterpreterCompletion> resultTwo = t.completion("p", 0); + + assertEquals(expectedResultOne, resultOne); + assertEquals(expectedResultTwo, resultTwo); + t.close(); } }
