You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/03/12 13:56:33 UTC
svn commit: r1666171 -
/hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java
Author: xuefu
Date: Thu Mar 12 12:56:32 2015
New Revision: 1666171
URL: http://svn.apache.org/r1666171
Log:
HIVE-9877: Beeline cannot run multiple statements in the same row (Chaoyu via Xuefu)
Modified:
hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java
Modified: hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java
URL: http://svn.apache.org/viewvc/hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java?rev=1666171&r1=1666170&r2=1666171&view=diff
==============================================================================
--- hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java (original)
+++ hive/trunk/beeline/src/java/org/apache/hive/beeline/Commands.java Thu Mar 12 12:56:32 2015
@@ -768,6 +768,9 @@ public class Commands {
}
String extra = beeLine.getConsoleReader().readLine(prompt.toString());
+ if (extra == null) { //it happens when using -f and the line of cmds does not end with ;
+ break;
+ }
if (!beeLine.isComment(extra)) {
line += "\n" + extra;
}
@@ -776,100 +779,104 @@ public class Commands {
beeLine.handleException(e);
}
- line = line.trim();
- if (line.endsWith(";")) {
- line = line.substring(0, line.length() - 1);
- }
-
if (!(beeLine.assertConnection())) {
return false;
}
- String sql = line;
-
- if (sql.startsWith(BeeLine.COMMAND_PREFIX)) {
- sql = sql.substring(1);
- }
-
- String prefix = call ? "call" : "sql";
-
- if (sql.startsWith(prefix)) {
- sql = sql.substring(prefix.length());
- }
-
- // batch statements?
- if (beeLine.getBatch() != null) {
- beeLine.getBatch().add(sql);
- return true;
- }
-
- try {
- Statement stmnt = null;
- boolean hasResults;
- Thread logThread = null;
-
- try {
- long start = System.currentTimeMillis();
-
- if (call) {
- stmnt = beeLine.getDatabaseConnection().getConnection().prepareCall(sql);
- hasResults = ((CallableStatement) stmnt).execute();
- } else {
- stmnt = beeLine.createStatement();
- if (beeLine.getOpts().isSilent()) {
- hasResults = stmnt.execute(sql);
- } else {
- logThread = new Thread(createLogRunnable(stmnt));
- logThread.setDaemon(true);
- logThread.start();
- hasResults = stmnt.execute(sql);
- logThread.interrupt();
- logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
- }
- }
+ line = line.trim();
+ String[] cmds = line.split(";");
+ for (int i = 0; i < cmds.length; i++) {
+ String sql = cmds[i].trim();
+ if (sql.length() != 0) {
+ if (beeLine.isComment(sql)) {
+ //skip this and rest cmds in the line
+ break;
+ }
+ if (sql.startsWith(BeeLine.COMMAND_PREFIX)) {
+ sql = sql.substring(1);
+ }
+
+ String prefix = call ? "call" : "sql";
+
+ if (sql.startsWith(prefix)) {
+ sql = sql.substring(prefix.length());
+ }
+
+ // batch statements?
+ if (beeLine.getBatch() != null) {
+ beeLine.getBatch().add(sql);
+ continue;
+ }
+
+ try {
+ Statement stmnt = null;
+ boolean hasResults;
+ Thread logThread = null;
+
+ try {
+ long start = System.currentTimeMillis();
+
+ if (call) {
+ stmnt = beeLine.getDatabaseConnection().getConnection().prepareCall(sql);
+ hasResults = ((CallableStatement) stmnt).execute();
+ } else {
+ stmnt = beeLine.createStatement();
+ if (beeLine.getOpts().isSilent()) {
+ hasResults = stmnt.execute(sql);
+ } else {
+ logThread = new Thread(createLogRunnable(stmnt));
+ logThread.setDaemon(true);
+ logThread.start();
+ hasResults = stmnt.execute(sql);
+ logThread.interrupt();
+ logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
+ }
+ }
- beeLine.showWarnings();
+ beeLine.showWarnings();
- if (hasResults) {
- do {
- ResultSet rs = stmnt.getResultSet();
- try {
- int count = beeLine.print(rs);
+ if (hasResults) {
+ do {
+ ResultSet rs = stmnt.getResultSet();
+ try {
+ int count = beeLine.print(rs);
+ long end = System.currentTimeMillis();
+
+ beeLine.info(beeLine.loc("rows-selected", count) + " "
+ + beeLine.locElapsedTime(end - start));
+ } finally {
+ if (logThread != null) {
+ logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
+ showRemainingLogsIfAny(stmnt);
+ logThread = null;
+ }
+ rs.close();
+ }
+ } while (BeeLine.getMoreResults(stmnt));
+ } else {
+ int count = stmnt.getUpdateCount();
long end = System.currentTimeMillis();
-
- beeLine.info(beeLine.loc("rows-selected", count) + " "
- + beeLine.locElapsedTime(end - start));
- } finally {
- if (logThread != null) {
- logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
- showRemainingLogsIfAny(stmnt);
- logThread = null;
+ beeLine.info(beeLine.loc("rows-affected", count)
+ + " " + beeLine.locElapsedTime(end - start));
+ }
+ } finally {
+ if (logThread != null) {
+ if (!logThread.isInterrupted()) {
+ logThread.interrupt();
}
- rs.close();
+ logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
+ showRemainingLogsIfAny(stmnt);
+ }
+ if (stmnt != null) {
+ stmnt.close();
}
- } while (BeeLine.getMoreResults(stmnt));
- } else {
- int count = stmnt.getUpdateCount();
- long end = System.currentTimeMillis();
- beeLine.info(beeLine.loc("rows-affected", count)
- + " " + beeLine.locElapsedTime(end - start));
- }
- } finally {
- if (logThread != null) {
- if (!logThread.isInterrupted()) {
- logThread.interrupt();
}
- logThread.join(DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT);
- showRemainingLogsIfAny(stmnt);
- }
- if (stmnt != null) {
- stmnt.close();
+ } catch (Exception e) {
+ return beeLine.error(e);
}
+ beeLine.showWarnings();
}
- } catch (Exception e) {
- return beeLine.error(e);
}
- beeLine.showWarnings();
return true;
}