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
50 changes: 41 additions & 9 deletions beeline/src/java/org/apache/hive/beeline/BeeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1359,22 +1359,52 @@ private int executeFile(String fileName) {
}
}

public String executeReader(ConsoleReader reader, Character mask) {
String line = null;
StringBuilder qsb = new StringBuilder();
try {
while ((line = (getOpts().isSilent() && getOpts().getScriptFile() != null) ? reader
.readLine(null, mask) : reader.readLine(getPrompt())) != null) {
// Skipping through comments
if (!line.startsWith("--")) {
qsb.append(line + "\n");
}
}
if (qsb.length() > 0) {
qsb.delete(qsb.length() - 2, qsb.length());
}
line = qsb.toString();
}
catch (Throwable t) {
handleException(t);
}
return line;
}

private int execute(ConsoleReader reader, boolean exitOnError) {
int lastExecutionResult = ERRNO_OK;
Character mask = (System.getProperty("jline.terminal", "").equals("jline.UnsupportedTerminal")) ? null
: ConsoleReader.NULL_MASK;
String line = null;

while (!exit) {
try {
// Execute one instruction; terminate on executing a script if there is an error
// in silent mode, prevent the query and prompt being echoed back to terminal
String line = (getOpts().isSilent() && getOpts().getScriptFile() != null) ? reader
.readLine(null, mask) : reader.readLine(getPrompt());

// trim line
if (line != null) {
line = line.trim();
if (getOpts().getScriptFile() != null)
{
line = executeReader(reader, mask);
exit = true;
}
else if (getOpts().getScriptFile() == null) {
// Execute one instruction; terminate on executing a script if there is an error
// in silent mode, prevent the query and prompt being echoed back to terminal
line = (getOpts().isSilent() && getOpts().getScriptFile() != null) ? reader
.readLine(null, mask) : reader.readLine(getPrompt());

// trim line
if (line != null) {
line = line.trim();
}
}

if (!dispatch(line)) {
lastExecutionResult = ERRNO_OTHER;
Expand Down Expand Up @@ -1500,7 +1530,9 @@ boolean dispatch(String line) {
return true;
}

line = line.trim();
if (getOpts().getScriptFile() == null) {
line = line.trim();
}

// save it to the current script, if any
if (scriptOutputFile != null) {
Expand Down
22 changes: 15 additions & 7 deletions beeline/src/java/org/apache/hive/beeline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1202,16 +1202,24 @@ private boolean execute(String line, boolean call, boolean entireLineAsCommand)
// bug 879518.

// use multiple lines for statements not terminated by the delimiter
try {
line = handleMultiLineCmd(line);
} catch (Exception e) {
beeLine.handleException(e);
if (beeLine.getOpts().getScriptFile() == null) {
try {
line = handleMultiLineCmd(line);
} catch (Exception e) {
beeLine.handleException(e);
}
line = line.trim();
}

line = line.trim();

List<String> cmdList = getCmdList(line, entireLineAsCommand);
String sql = null;
for (int i = 0; i < cmdList.size(); i++) {
String sql = cmdList.get(i).trim();
if (beeLine.getOpts().getScriptFile() == null) {
sql = cmdList.get(i).trim();
}
else {
sql = cmdList.get(i);
}
if (sql.length() != 0) {
if (!executeInternal(sql, call)) {
return false;
Expand Down