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));
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project metron by apache.
the class StellarInterpreterTest method testAutoCompletion.
/**
* The interpreter should support auto-completion.
*/
@Test
public void testAutoCompletion() {
// the user's input that needs auto-completed
final String buffer = "TO_";
// the cursor is at the end of the buffer
int cursor = buffer.length();
List<InterpreterCompletion> completions = interpreter.completion(buffer, cursor);
// expect some completions to be offered
assertTrue(completions.size() > 0);
for (InterpreterCompletion iCompletion : completions) {
String completion = iCompletion.getValue();
// the auto-complete should include an open paren
assertEquals("(", completion.substring(completion.length() - 1));
// the candidate should be a valid, defined function
String function = completion.substring(0, completion.length() - 1);
Iterable<String> allFunctions = interpreter.getExecutor().getFunctionResolver().getFunctions();
String definedFunction = Iterables.find(allFunctions, (fn) -> StringUtils.equals(fn, function));
assertEquals(function, definedFunction);
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.
the class PythonInterpreter method completion.
@Override
public List<InterpreterCompletion> completion(String buf, int cursor, InterpreterContext interpreterContext) throws InterpreterException {
if (iPythonInterpreter != null) {
return iPythonInterpreter.completion(buf, cursor, interpreterContext);
}
if (buf.length() < cursor) {
cursor = buf.length();
}
String completionString = getCompletionTargetString(buf, cursor);
String completionCommand = "__zeppelin_completion__.getCompletion('" + completionString + "')";
LOGGER.debug("completionCommand: {}", completionCommand);
pythonInterpretRequest = new PythonInterpretRequest(completionCommand, true);
statementOutput = null;
synchronized (statementSetNotifier) {
statementSetNotifier.notify();
}
String[] completionList = null;
synchronized (statementFinishedNotifier) {
long startTime = System.currentTimeMillis();
while (statementOutput == null && pythonProcessLauncher.isRunning()) {
try {
if (System.currentTimeMillis() - startTime > MAX_TIMEOUT_SEC * 1000) {
LOGGER.error("Python completion didn't have response for {}sec.", MAX_TIMEOUT_SEC);
break;
}
statementFinishedNotifier.wait(1000);
} catch (InterruptedException e) {
// not working
LOGGER.info("wait drop");
return new LinkedList<>();
}
}
if (statementError) {
return new LinkedList<>();
}
Gson gson = new Gson();
completionList = gson.fromJson(statementOutput, String[].class);
}
// end code for completion
if (completionList == null) {
return new LinkedList<>();
}
List<InterpreterCompletion> results = new LinkedList<>();
for (String name : completionList) {
results.add(new InterpreterCompletion(name, name, StringUtils.EMPTY));
}
return results;
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterCompletion in project zeppelin by apache.
the class AlluxioInterpreter method completion.
@Override
public List<InterpreterCompletion> completion(String buf, int cursor, InterpreterContext interpreterContext) {
String[] words = splitAndRemoveEmpty(splitAndRemoveEmpty(buf, "\n"), " ");
String lastWord = "";
if (words.length > 0) {
lastWord = words[words.length - 1];
}
List<InterpreterCompletion> voices = new LinkedList<>();
for (String command : keywords) {
if (command.startsWith(lastWord)) {
voices.add(new InterpreterCompletion(command, command, CompletionType.command.name()));
}
}
return voices;
}
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", CompletionType.command.name()));
final List<InterpreterCompletion> expectedResultTwo = Arrays.asList(new InterpreterCompletion("help", "help", CompletionType.command.name()));
final List<InterpreterCompletion> resultOne = interpreter.completion("co", 0, null);
final List<InterpreterCompletion> resultTwo = interpreter.completion("he", 0, null);
final List<InterpreterCompletion> resultAll = interpreter.completion("", 0, null);
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);
}
Aggregations