-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ZEPPELIN-1293. Livy Interpreter: Automatically attach or create to a new session #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,15 +51,15 @@ public void open() { | |
| // As we don't know whether livyserver use spark2 or spark1, so we will detect SparkSession | ||
| // to judge whether it is using spark2. | ||
| try { | ||
| InterpreterResult result = sparkInterpreter.interpret("spark", false); | ||
| InterpreterResult result = sparkInterpreter.interpret("spark", false, false); | ||
| if (result.code() == InterpreterResult.Code.SUCCESS && | ||
| result.message().get(0).getData().contains("org.apache.spark.sql.SparkSession")) { | ||
| LOGGER.info("SparkSession is detected so we are using spark 2.x for session {}", | ||
| sparkInterpreter.getSessionInfo().id); | ||
| isSpark2 = true; | ||
| } else { | ||
| // spark 1.x | ||
| result = sparkInterpreter.interpret("sqlContext", false); | ||
| result = sparkInterpreter.interpret("sqlContext", false, false); | ||
| if (result.code() == InterpreterResult.Code.SUCCESS) { | ||
| LOGGER.info("sqlContext is detected."); | ||
| } else if (result.code() == InterpreterResult.Code.ERROR) { | ||
|
|
@@ -68,7 +68,7 @@ public void open() { | |
| LOGGER.info("sqlContext is not detected, try to create SQLContext by ourselves"); | ||
| result = sparkInterpreter.interpret( | ||
| "val sqlContext = new org.apache.spark.sql.SQLContext(sc)\n" | ||
| + "import sqlContext.implicits._", false); | ||
| + "import sqlContext.implicits._", false, false); | ||
| if (result.code() == InterpreterResult.Code.ERROR) { | ||
| throw new LivyException("Fail to create SQLContext," + | ||
| result.message().get(0).getData()); | ||
|
|
@@ -113,37 +113,44 @@ public InterpreterResult interpret(String line, InterpreterContext context) { | |
| } else { | ||
| sqlQuery = "sqlContext.sql(\"\"\"" + line + "\"\"\").show(" + maxResult + ")"; | ||
| } | ||
| InterpreterResult res = sparkInterpreter.interpret(sqlQuery, this.displayAppInfo); | ||
|
|
||
| if (res.code() == InterpreterResult.Code.SUCCESS) { | ||
| StringBuilder resMsg = new StringBuilder(); | ||
| resMsg.append("%table "); | ||
| String[] rows = res.message().get(0).getData().split("\n"); | ||
| String[] headers = rows[1].split("\\|"); | ||
| for (int head = 1; head < headers.length; head++) { | ||
| resMsg.append(headers[head].trim()).append("\t"); | ||
| } | ||
| resMsg.append("\n"); | ||
| if (rows[3].indexOf("+") == 0) { | ||
|
|
||
| } else { | ||
| for (int cols = 3; cols < rows.length - 1; cols++) { | ||
| String[] col = rows[cols].split("\\|"); | ||
| for (int data = 1; data < col.length; data++) { | ||
| resMsg.append(col[data].trim()).append("\t"); | ||
| InterpreterResult result = sparkInterpreter.interpret(sqlQuery, this.displayAppInfo, true); | ||
|
|
||
| if (result.code() == InterpreterResult.Code.SUCCESS) { | ||
| InterpreterResult result2 = new InterpreterResult(InterpreterResult.Code.SUCCESS); | ||
| for (InterpreterResultMessage message : result.message()) { | ||
| // convert Text type to Table type. We assume the text type must be the sql output. This | ||
| // assumption is correct for now. Ideally livy should return table type. We may do it in | ||
| // the future release of livy. | ||
| if (message.getType() == InterpreterResult.Type.TEXT) { | ||
| StringBuilder resMsg = new StringBuilder(); | ||
| String[] rows = message.getData().split("\n"); | ||
| String[] headers = rows[1].split("\\|"); | ||
| for (int head = 1; head < headers.length; head++) { | ||
| resMsg.append(headers[head].trim()).append("\t"); | ||
| } | ||
| resMsg.append("\n"); | ||
| if (rows[3].indexOf("+") == 0) { | ||
|
|
||
| } else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this exists before, but this construct is a bit strange?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about this logic, @prabhjyotsingh is the original author who might know this. |
||
| for (int cols = 3; cols < rows.length - 1; cols++) { | ||
| String[] col = rows[cols].split("\\|"); | ||
| for (int data = 1; data < col.length; data++) { | ||
| resMsg.append(col[data].trim()).append("\t"); | ||
| } | ||
| resMsg.append("\n"); | ||
| } | ||
| } | ||
| if (rows[rows.length - 1].indexOf("only") == 0) { | ||
| resMsg.append("<font color=red>" + rows[rows.length - 1] + ".</font>"); | ||
| } | ||
| result2.add(InterpreterResult.Type.TABLE, resMsg.toString()); | ||
| } else { | ||
| result2.add(message.getType(), message.getData()); | ||
| } | ||
| } | ||
| if (rows[rows.length - 1].indexOf("only") == 0) { | ||
| resMsg.append("<font color=red>" + rows[rows.length - 1] + ".</font>"); | ||
| } | ||
|
|
||
| return new InterpreterResult(InterpreterResult.Code.SUCCESS, | ||
| resMsg.toString() | ||
| ); | ||
| return result2; | ||
| } else { | ||
| return res; | ||
| return result; | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.error("Exception in LivySparkSQLInterpreter while interpret ", e); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's our coding style guide on multiple imports? is it clearer to list them out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done by intellij which would use * when imports more than 5 classes in one package. I think it should be fine to do that.