Repository: zeppelin Updated Branches: refs/heads/master 60186d8bb -> df8c36def
[ZEPPELIN-1102] ElasticSearch interpreter auto completion doesn't work. ### What is this PR for? This PR fixes bug of elasticsearch auto completion. ### What type of PR is it? Bug Fix ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1102 ### How should this be tested? Test auto completion code like as http://zeppelin.apache.org/docs/0.6.0-SNAPSHOT/interpreter/elasticsearch.html. ### Screenshots (if appropriate) - before  - after  ### 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 #1120 from astroshim/ZEPPELIN-1102 and squashes the following commits: a74df8e [astroshim] Merge branch 'master' into ZEPPELIN-1102 b77e0ee [astroshim] fixes elasticsearch auto completion code and add testcase. Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/df8c36de Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/df8c36de Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/df8c36de Branch: refs/heads/master Commit: df8c36defdc85a2c618c5b654e72edd8e4b6ee3b Parents: 60186d8 Author: astroshim <[email protected]> Authored: Thu Jul 7 12:18:45 2016 +0900 Committer: Alexander Bezzubov <[email protected]> Committed: Mon Jul 11 11:30:17 2016 +0900 ---------------------------------------------------------------------- .../elasticsearch/ElasticsearchInterpreter.java | 14 +++-------- .../ElasticsearchInterpreterTest.java | 26 +++++++++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/df8c36de/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java ---------------------------------------------------------------------- diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java index dfd27e5..e0feece 100644 --- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java +++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreter.java @@ -92,7 +92,7 @@ public class ElasticsearchInterpreter extends Interpreter { + " - index /ndex/type/id <json-formatted document>\n" + " . the id can be omitted, elasticsearch will generate one"; - private static final List<String> COMMANDS = Arrays.asList( + protected static final List<String> COMMANDS = Arrays.asList( "count", "delete", "get", "help", "index", "search"); private static final Pattern FIELD_NAME_PATTERN = Pattern.compile("\\[\\\\\"(.+)\\\\\"\\](.*)"); @@ -248,17 +248,11 @@ public class ElasticsearchInterpreter extends Interpreter { public List<InterpreterCompletion> completion(String s, int i) { final List suggestions = new ArrayList<>(); - if (StringUtils.isEmpty(s)) { - suggestions.addAll(COMMANDS); - } - else { - for (String cmd : COMMANDS) { - if (cmd.toLowerCase().contains(s)) { - suggestions.add(cmd); - } + for (String cmd : COMMANDS) { + if (cmd.toLowerCase().contains(s)) { + suggestions.add(new InterpreterCompletion(cmd, cmd)); } } - return suggestions; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/df8c36de/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java ---------------------------------------------------------------------- diff --git a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java index 35f683f..e23cbb6 100644 --- a/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java +++ b/elasticsearch/src/test/java/org/apache/zeppelin/elasticsearch/ElasticsearchInterpreterTest.java @@ -21,20 +21,19 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.junit.Assert.assertEquals; import java.io.IOException; -import java.util.Arrays; -import java.util.Date; -import java.util.Properties; -import java.util.UUID; +import java.util.*; import org.apache.commons.lang.math.RandomUtils; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Code; +import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -211,4 +210,23 @@ public class ElasticsearchInterpreterTest { assertEquals(Code.SUCCESS, res.code()); } + @Test + public void testCompletion() { + List expectedResultOne = Arrays.asList(new InterpreterCompletion("count", "count")); + List expectedResultTwo = Arrays.asList(new InterpreterCompletion("help", "help")); + + List<InterpreterCompletion> resultOne = interpreter.completion("co", 0); + List<InterpreterCompletion> resultTwo = interpreter.completion("he", 0); + List<InterpreterCompletion> resultAll = interpreter.completion("", 0); + + Assert.assertEquals(expectedResultOne, resultOne); + Assert.assertEquals(expectedResultTwo, resultTwo); + + List allCompletionList = new ArrayList<>(); + for (InterpreterCompletion ic : resultAll) { + allCompletionList.add(ic.getName()); + } + Assert.assertEquals(interpreter.COMMANDS, allCompletionList); + } + }
