Search in sources :

Example 6 with InterpreterCompletion

use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.

the class JDBCInterpreterTest method testAutoCompletion.

@Test
public void testAutoCompletion() throws SQLException, IOException {
    Properties properties = new Properties();
    properties.setProperty("common.max_count", "1000");
    properties.setProperty("common.max_retry", "3");
    properties.setProperty("default.driver", "org.h2.Driver");
    properties.setProperty("default.url", getJdbcConnection());
    properties.setProperty("default.user", "");
    properties.setProperty("default.password", "");
    JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
    jdbcInterpreter.open();
    jdbcInterpreter.interpret("", interpreterContext);
    List<InterpreterCompletion> completionList = jdbcInterpreter.completion("sel", 1);
    InterpreterCompletion correctCompletionKeyword = new InterpreterCompletion("select ", "select ");
    assertEquals(1, completionList.size());
    assertEquals(true, completionList.contains(correctCompletionKeyword));
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with InterpreterCompletion

use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.

the class Paragraph method getInterpreterCompletion.

public List<InterpreterCompletion> getInterpreterCompletion() {
    List<InterpreterCompletion> completion = new LinkedList();
    for (InterpreterSetting intp : interpreterSettingManager.getInterpreterSettings(note.getId())) {
        List<InterpreterInfo> intInfo = intp.getInterpreterInfos();
        if (intInfo.size() > 1) {
            for (InterpreterInfo info : intInfo) {
                String name = intp.getName() + "." + info.getName();
                completion.add(new InterpreterCompletion(name, name));
            }
        } else {
            completion.add(new InterpreterCompletion(intp.getName(), intp.getName()));
        }
    }
    return completion;
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)

Example 8 with InterpreterCompletion

use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testCompletion.

@Theory
public void testCompletion(ElasticsearchInterpreter interpreter) {
    final List<InterpreterCompletion> expectedResultOne = Arrays.asList(new InterpreterCompletion("count", "count"));
    final List<InterpreterCompletion> expectedResultTwo = Arrays.asList(new InterpreterCompletion("help", "help"));
    final List<InterpreterCompletion> resultOne = interpreter.completion("co", 0);
    final List<InterpreterCompletion> resultTwo = interpreter.completion("he", 0);
    final List<InterpreterCompletion> resultAll = interpreter.completion("", 0);
    Assert.assertEquals(expectedResultOne, resultOne);
    Assert.assertEquals(expectedResultTwo, resultTwo);
    final List<String> allCompletionList = new ArrayList<>();
    for (final InterpreterCompletion ic : resultAll) {
        allCompletionList.add(ic.getName());
    }
    Assert.assertEquals(ElasticsearchInterpreter.COMMANDS, allCompletionList);
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) ArrayList(java.util.ArrayList) Theory(org.junit.experimental.theories.Theory)

Example 9 with InterpreterCompletion

use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.

the class MockHDFSFileInterpreter method test.

@Test
public void test() {
    HDFSFileInterpreter t = new MockHDFSFileInterpreter(new Properties());
    t.open();
    // We have info for /, /user, /tmp, /mr-history/done
    // Ensure
    // 1. ls -l works
    // 2. paths (. and ..) are correctly handled
    // 3. flags and arguments to commands are correctly handled
    InterpreterResult result1 = t.interpret("ls -l /", null);
    assertEquals(result1.message().get(0).getType(), InterpreterResult.Type.TEXT);
    InterpreterResult result2 = t.interpret("ls -l /./user/..", null);
    assertEquals(result2.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result1.message().get(0).getData(), result2.message().get(0).getData());
    // Ensure you can do cd and after that the ls uses current directory correctly
    InterpreterResult result3 = t.interpret("cd user", null);
    assertEquals(result3.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result3.message().get(0).getData(), "OK");
    InterpreterResult result4 = t.interpret("ls", null);
    assertEquals(result4.message().get(0).getType(), InterpreterResult.Type.TEXT);
    InterpreterResult result5 = t.interpret("ls /user", null);
    assertEquals(result5.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result4.message().get(0).getData(), result5.message().get(0).getData());
    // Ensure pwd works correctly
    InterpreterResult result6 = t.interpret("pwd", null);
    assertEquals(result6.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result6.message().get(0).getData(), "/user");
    // Move a couple of levels and check we're in the right place
    InterpreterResult result7 = t.interpret("cd ../mr-history/done", null);
    assertEquals(result7.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result7.message().get(0).getData(), "OK");
    InterpreterResult result8 = t.interpret("ls -l ", null);
    assertEquals(result8.message().get(0).getType(), InterpreterResult.Type.TEXT);
    InterpreterResult result9 = t.interpret("ls -l /mr-history/done", null);
    assertEquals(result9.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result8.message().get(0).getData(), result9.message().get(0).getData());
    InterpreterResult result10 = t.interpret("cd ../..", null);
    assertEquals(result10.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals(result7.message().get(0).getData(), "OK");
    InterpreterResult result11 = t.interpret("ls -l ", null);
    assertEquals(result11.message().get(0).getType(), InterpreterResult.Type.TEXT);
    // we should be back to first result after all this navigation
    assertEquals(result1.message().get(0).getData(), result11.message().get(0).getData());
    // 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();
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) List(java.util.List) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with InterpreterCompletion

use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.

the class NotebookServer method completion.

private void completion(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    String paragraphId = (String) fromMessage.get("id");
    String buffer = (String) fromMessage.get("buf");
    int cursor = (int) Double.parseDouble(fromMessage.get("cursor").toString());
    Message resp = new Message(OP.COMPLETION_LIST).put("id", paragraphId);
    if (paragraphId == null) {
        conn.send(serializeMessage(resp));
        return;
    }
    final Note note = notebook.getNote(getOpenNoteId(conn));
    List<InterpreterCompletion> candidates = note.completion(paragraphId, buffer, cursor);
    resp.put("completions", candidates);
    conn.send(serializeMessage(resp));
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) Note(org.apache.zeppelin.notebook.Note)

Aggregations

InterpreterCompletion (org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)11 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 Candidates (scala.tools.nsc.interpreter.Completion.Candidates)2 ScalaCompleter (scala.tools.nsc.interpreter.Completion.ScalaCompleter)2 Gson (com.google.gson.Gson)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)1 Note (org.apache.zeppelin.notebook.Note)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)1 Theory (org.junit.experimental.theories.Theory)1