Search in sources :

Example 1 with InterpreterCompletion

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) {
    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));
        }
    }
    return voices;
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)

Example 2 with InterpreterCompletion

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

the class PySparkInterpreter method completion.

@Override
public List<InterpreterCompletion> completion(String buf, int cursor) {
    if (buf.length() < cursor) {
        cursor = buf.length();
    }
    String completionString = getCompletionTargetString(buf, cursor);
    String completionCommand = "completion.getCompletion('" + completionString + "')";
    //start code for completion
    SparkInterpreter sparkInterpreter = getSparkInterpreter();
    if (sparkInterpreter.getSparkVersion().isUnsupportedVersion() == false && pythonscriptRunning == false) {
        return new LinkedList<>();
    }
    pythonInterpretRequest = new PythonInterpretRequest(completionCommand, "");
    statementOutput = null;
    synchronized (statementSetNotifier) {
        statementSetNotifier.notify();
    }
    String[] completionList = null;
    synchronized (statementFinishedNotifier) {
        long startTime = System.currentTimeMillis();
        while (statementOutput == null && pythonscriptRunning) {
            try {
                if (System.currentTimeMillis() - startTime > MAX_TIMEOUT_SEC * 1000) {
                    logger.error("pyspark 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);
    }
    if (completionList == null) {
        return new LinkedList<>();
    }
    List<InterpreterCompletion> results = new LinkedList<>();
    for (String name : completionList) {
        results.add(new InterpreterCompletion(name, name));
    }
    return results;
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList)

Example 3 with InterpreterCompletion

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

the class SparkInterpreter method completion.

@Override
public List<InterpreterCompletion> completion(String buf, int cursor) {
    if (completer == null) {
        logger.warn("Can't find completer");
        return new LinkedList<>();
    }
    if (buf.length() < cursor) {
        cursor = buf.length();
    }
    String completionText = getCompletionTargetString(buf, cursor);
    if (completionText == null) {
        completionText = "";
        cursor = completionText.length();
    }
    ScalaCompleter c = (ScalaCompleter) Utils.invokeMethod(completer, "completer");
    Candidates ret = c.complete(completionText, cursor);
    List<String> candidates = WrapAsJava$.MODULE$.seqAsJavaList(ret.candidates());
    List<InterpreterCompletion> completions = new LinkedList<>();
    for (String candidate : candidates) {
        completions.add(new InterpreterCompletion(candidate, candidate));
    }
    return completions;
}
Also used : Candidates(scala.tools.nsc.interpreter.Completion.Candidates) InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) ScalaCompleter(scala.tools.nsc.interpreter.Completion.ScalaCompleter)

Example 4 with InterpreterCompletion

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

the class HDFSFileInterpreter method completion.

@Override
public List<InterpreterCompletion> completion(String buf, int cursor) {
    logger.info("Completion request at position\t" + cursor + " in string " + buf);
    final List<InterpreterCompletion> suggestions = new ArrayList<>();
    if (StringUtils.isEmpty(buf)) {
        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(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;
    }
    // last word will contain the path we're working with.
    String lastToken = buf.substring(buf.lastIndexOf(" ") + 1);
    if (lastToken.startsWith("-")) {
        //flag not path
        return null;
    }
    //all things before the last '/'
    String localPath = "";
    //unfished filenames or directories
    String unfinished = lastToken;
    if (lastToken.contains("/")) {
        localPath = lastToken.substring(0, lastToken.lastIndexOf('/') + 1);
        unfinished = lastToken.substring(lastToken.lastIndexOf('/') + 1);
    }
    //adjust for cwd
    String globalPath = getNewPath(localPath);
    if (isDirectory(globalPath)) {
        try {
            String fileStatusString = listDir(globalPath);
            if (fileStatusString != null) {
                AllFileStatus allFiles = gson.fromJson(fileStatusString, AllFileStatus.class);
                if (allFiles != null && allFiles.FileStatuses != null && allFiles.FileStatuses.FileStatus != null) {
                    for (OneFileStatus fs : allFiles.FileStatuses.FileStatus) {
                        if (fs.pathSuffix.contains(unfinished)) {
                            //only suggest the text after the last .
                            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(new InterpreterCompletion(suggestedFinish, suggestedFinish));
                        }
                    }
                    return suggestions;
                }
            }
        } catch (Exception e) {
            logger.error("listall: listDir " + globalPath, e);
            return null;
        }
    } else {
        logger.info("path is not a directory.  No values suggested.");
    }
    //Error in string.
    return null;
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 5 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)

Aggregations

InterpreterCompletion (org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)32 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)8 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)6 IOException (java.io.IOException)5 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Properties (java.util.Properties)4 Gson (com.google.gson.Gson)2 Map (java.util.Map)2 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)2 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)2 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)2 Notebook (org.apache.zeppelin.notebook.Notebook)2 Paragraph (org.apache.zeppelin.notebook.Paragraph)2 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 Connection (java.sql.Connection)1