Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ function addEachJarInDir(){
fi
}

function addEachJarInDirRecursive(){
if [[ -d "${1}" ]]; then
for jar in $(find -L "${1}" -type f -name '*jar'); do
ZEPPELIN_CLASSPATH="$jar:$ZEPPELIN_CLASSPATH"
done
fi
}


function addJarInDir(){
if [[ -d "${1}" ]]; then
ZEPPELIN_CLASSPATH="${1}/*:${ZEPPELIN_CLASSPATH}"
Expand Down
2 changes: 1 addition & 1 deletion bin/interpreter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [[ "${INTERPRETER_ID}" == "spark" ]]; then
# add Hadoop jars into classpath
if [[ -n "${HADOOP_HOME}" ]]; then
# Apache
addEachJarInDir "${HADOOP_HOME}/share"
addEachJarInDirRecursive "${HADOOP_HOME}/share"

# CDH
addJarInDir "${HADOOP_HOME}"
Expand Down
34 changes: 34 additions & 0 deletions docs/rest-api/rest-interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,37 @@ limitations under the License.
</td>
</tr>
</table>


<br/>

<table class="table-configuration">
<col width="200">
<tr>
<th>Restart an interpreter</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```PUT``` method restart the given interpreter id.</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/interpreter/setting/restart/[interpreter ID]```</td>
</tr>
<tr>
<td>Success code</td>
<td>200</td>
</tr>
<tr>
<td> Fail code</td>
<td> 500 </td>
</tr>
<tr>
<td> sample JSON response
</td>
<td>
<pre>{"status":"OK"}</pre>
</td>
</tr>
</table>
40 changes: 20 additions & 20 deletions docs/rest-api/rest-notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
{% include JB/setup %}

## Zeppelin REST API
Zeppelin provides several REST API's for interaction and remote activation of zeppelin functionality.
Zeppelin provides several REST APIs for interaction and remote activation of zeppelin functionality.

All REST API are available starting with the following endpoint ```http://[zeppelin-server]:[zeppelin-port]/api```
All REST APIs are available starting with the following endpoint ```http://[zeppelin-server]:[zeppelin-port]/api```

Note that zeppein REST API receive or return JSON objects, it it recommended you install some JSON view such as
[JSONView](https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc)
Note that zeppelin REST APIs receive or return JSON objects, it is recommended for you to install some JSON viewer
such as [JSONView](https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc)


If you work with zeppelin and find a need for an additional REST API please [file an issue or send us mail](../../community.html)
Expand All @@ -43,7 +43,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```GET``` method list the available notebooks on your server.
<td>This ```GET``` method lists the available notebooks on your server.
Notebook JSON contains the ```name``` and ```id``` of all notebooks.
</td>
</tr>
Expand Down Expand Up @@ -75,8 +75,8 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method create a new notebook using the given name or default name if none given.
The body field of the returned JSON contain the new notebook id.
<td>This ```POST``` method creates a new notebook using the given name or default name if none given.
The body field of the returned JSON contains the new notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -129,7 +129,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```DELETE``` method delete a notebook by the given notebook id.
<td>This ```DELETE``` method deletes a notebook by the given notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -160,9 +160,9 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method clone a notebook by the given id and create a new notebook using the given name
<td>This ```POST``` method clones a notebook by the given id and create a new notebook using the given name
or default name if none given.
The body field of the returned JSON contain the new notebook id.
The body field of the returned JSON contains the new notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -197,7 +197,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method run all paragraph in the given notebook id.
<td>This ```POST``` method runs all paragraph in the given notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -228,7 +228,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```DELETE``` method stop all paragraph in the given notebook id.
<td>This ```DELETE``` method stops all paragraph in the given notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -261,7 +261,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```GET``` method get all paragraph status by the given notebook id.
<td>This ```GET``` method gets all paragraph status by the given notebook id.
The body field of the returned JSON contains of the array that compose of the paragraph id, paragraph status, paragraph finish date, paragraph started date.
</td>
</tr>
Expand Down Expand Up @@ -293,7 +293,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method run the paragraph by given notebook and paragraph id.
<td>This ```POST``` method runs the paragraph by given notebook and paragraph id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -324,7 +324,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```DELETE``` method stop the paragraph by given notebook and paragraph id.
<td>This ```DELETE``` method stops the paragraph by given notebook and paragraph id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -355,7 +355,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method add cron job by the given notebook id.
<td>This ```POST``` method adds cron job by the given notebook id.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -390,7 +390,7 @@ limitations under the License.
</tr>
<tr>
<td>Description</td>
<td>This ```DELETE``` method remove cron job by the given notebook id.
<td>This ```DELETE``` method removes cron job by the given notebook id.
</td>
</tr>
<tr>
Expand All @@ -416,13 +416,13 @@ limitations under the License.
<table class="table-configuration">
<col width="200">
<tr>
<th>Get clone job</th>
<th>Get cron job</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```GET``` method get cron job expression of given notebook id.
The body field of the returned JSON contain the cron expression.
<td>This ```GET``` method gets cron job expression of given notebook id.
The body field of the returned JSON contains the cron expression.
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;

import py4j.GatewayServer;

/**
Expand Down Expand Up @@ -368,12 +373,96 @@ public int getProgress(InterpreterContext context) {
return sparkInterpreter.getProgress(context);
}


@Override
public List<String> completion(String buf, int cursor) {
// not supported
return new LinkedList<String>();
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<String>();
}

outputStream.reset();

pythonInterpretRequest = new PythonInterpretRequest(completionCommand, "");
statementOutput = null;

synchronized (statementSetNotifier) {
statementSetNotifier.notify();
}

synchronized (statementFinishedNotifier) {
while (statementOutput == null) {
try {
statementFinishedNotifier.wait(1000);
} catch (InterruptedException e) {
// not working
logger.info("wait drop");
return new LinkedList<String>();
}
}
}

if (statementError) {
return new LinkedList<String>();
}
InterpreterResult completionResult = new InterpreterResult(Code.SUCCESS, statementOutput);
//end code for completion

Gson gson = new Gson();

return gson.fromJson(completionResult.message(), LinkedList.class);
}

private String getCompletionTargetString(String text, int cursor) {
String[] completionSeqCharaters = {" ", "\n", "\t"};
int completionEndPosition = cursor;
int completionStartPosition = cursor;
int indexOfReverseSeqPostion = cursor;

String resultCompletionText = "";
String completionScriptText = "";
try {
completionScriptText = text.substring(0, cursor);
}
catch (Exception e) {
logger.error(e.toString());
return null;
}
completionEndPosition = completionScriptText.length();

String tempReverseCompletionText = new StringBuilder(completionScriptText).reverse().toString();

for (String seqCharacter : completionSeqCharaters) {
indexOfReverseSeqPostion = tempReverseCompletionText.indexOf(seqCharacter);

if (indexOfReverseSeqPostion < completionStartPosition && indexOfReverseSeqPostion > 0) {
completionStartPosition = indexOfReverseSeqPostion;
}

}

if (completionStartPosition == completionEndPosition) {
completionStartPosition = 0;
}
else
{
completionStartPosition = completionEndPosition - completionStartPosition;
}
resultCompletionText = completionScriptText.substring(
completionStartPosition , completionEndPosition);

return resultCompletionText;
}


private SparkInterpreter getSparkInterpreter() {
InterpreterGroup intpGroup = getInterpreterGroup();
LazyOpenInterpreter lazy = null;
Expand Down
47 changes: 46 additions & 1 deletion spark/src/main/resources/python/zeppelin_pyspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

import sys, getopt, traceback
import sys, getopt, traceback, json, re

from py4j.java_gateway import java_import, JavaGateway, GatewayClient
from py4j.protocol import Py4JJavaError
Expand Down Expand Up @@ -107,6 +107,50 @@ def isAutoConvertEnabled(self):
def isImportAllPackageUnderSparkSql(self):
return self.version >= self.SPARK_1_3_0

class PySparkCompletion:
def getGlobalCompletion(self):
objectDefList = []
try:
for completionItem in list(globals().iterkeys()):
objectDefList.append(completionItem)
except:
return None
else:
return objectDefList

def getMethodCompletion(self, text_value):
objectDefList = []
completion_target = text_value
try:
if len(completion_target) <= 0:
return None
if text_value[-1] == ".":
completion_target = text_value[:-1]
exec("%s = %s(%s)" % ("objectDefList", "dir", completion_target))
except:
return None
else:
return objectDefList


def getCompletion(self, text_value):
completionList = set()

globalCompletionList = self.getGlobalCompletion()
if globalCompletionList != None:
for completionItem in list(globalCompletionList):
completionList.add(completionItem)

if text_value != None:
objectCompletionList = self.getMethodCompletion(text_value)
if objectCompletionList != None:
for completionItem in list(objectCompletionList):
completionList.add(completionItem)
if len(completionList) <= 0:
print ""
else:
print json.dumps(filter(lambda x : not re.match("^__.*", x), list(completionList)))


output = Logger()
sys.stdout = output
Expand Down Expand Up @@ -149,6 +193,7 @@ def isImportAllPackageUnderSparkSql(self):
sqlc = SQLContext(sc, intp.getSQLContext())
sqlContext = sqlc

completion = PySparkCompletion()
z = PyZeppelinContext(intp.getZeppelinContext())

while True :
Expand Down
Loading