[56/67] [abbrv] hive git commit: HIVE-14063: beeline to auto connect to the HiveServer2 (Vihang Karajgaonkar, reviewed by Aihua Xu, Szehon Ho, Sergio Peña)
HIVE-14063: beeline to auto connect to the HiveServer2 (Vihang Karajgaonkar, reviewed by Aihua Xu, Szehon Ho, Sergio Peña) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/8029e11b Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/8029e11b Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/8029e11b Branch: refs/heads/hive-14535 Commit: 8029e11b3c913e0aebc0a719a19b85d96db28a32 Parents: 9caf230 Author: Aihua XuAuthored: Mon Oct 17 13:06:30 2016 -0400 Committer: Aihua Xu Committed: Mon Oct 17 13:08:29 2016 -0400 -- .../java/org/apache/hive/beeline/BeeLine.java | 176 ++- .../java/org/apache/hive/beeline/Commands.java | 52 +++-- .../BeelineHS2ConnectionFileParseException.java | 30 +++ .../hs2connection/HS2ConnectionFileParser.java | 88 .../hs2connection/HS2ConnectionFileUtils.java | 119 +++ .../HiveSiteHS2ConnectionFileParser.java| 172 +++ .../UserHS2ConnectionFileParser.java| 117 ++ .../apache/hive/beeline/TestBeeLineHistory.java | 4 +- .../TestUserHS2ConnectionFileParser.java| 211 ++ beeline/src/test/resources/hive-site.xml| 5 + .../test-hs2-conn-conf-kerberos-http.xml| 48 + .../test-hs2-conn-conf-kerberos-nossl.xml | 32 +++ .../test-hs2-conn-conf-kerberos-ssl.xml | 40 .../resources/test-hs2-connection-conf-list.xml | 36 .../test-hs2-connection-config-noauth.xml | 28 +++ .../test-hs2-connection-multi-conf-list.xml | 37 .../test-hs2-connection-zookeeper-config.xml| 32 +++ .../TestBeelineConnectionUsingHiveSite.java | 109 ++ .../TestBeelineWithHS2ConnectionFile.java | 214 +++ .../TestBeelineWithUserHs2ConnectionFile.java | 129 +++ 20 files changed, 1612 insertions(+), 67 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hive/blob/8029e11b/beeline/src/java/org/apache/hive/beeline/BeeLine.java -- diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 79922d2..fdbe0a2 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -28,6 +28,7 @@ import java.io.Closeable; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -93,8 +94,15 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.io.IOUtils; import org.apache.hive.beeline.cli.CliOptionsProcessor; import org.apache.hive.common.util.ShutdownHookManager; +import org.apache.hive.beeline.hs2connection.BeelineHS2ConnectionFileParseException; +import org.apache.hive.beeline.hs2connection.HS2ConnectionFileUtils; +import org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser; +import org.apache.hive.beeline.hs2connection.HS2ConnectionFileParser; +import org.apache.hive.beeline.hs2connection.HiveSiteHS2ConnectionFileParser; import org.apache.thrift.transport.TTransportException; +import com.google.common.annotations.VisibleForTesting; + import org.apache.hive.jdbc.Utils; import org.apache.hive.jdbc.Utils.JdbcConnectionParams; @@ -279,7 +287,6 @@ public class BeeLine implements Closeable { "org.apache.hadoop.hive.jdbc.HiveDriver", })); - static { try { Class.forName("jline.console.ConsoleReader"); @@ -728,6 +735,46 @@ public class BeeLine implements Closeable { return -1; } +boolean connSuccessful = connectUsingArgs(cl); +// checks if default hs2 connection configuration file is present +// and uses it to connect if found +// no-op if the file is not present +if(!connSuccessful && !exit) { + connSuccessful = defaultBeelineConnect(); +} + +int code = 0; +if (cl.getOptionValues('e') != null) { + commands = Arrays.asList(cl.getOptionValues('e')); +} + +if (!commands.isEmpty() && getOpts().getScriptFile() != null) { + error("The '-e' and '-f' options cannot be specified simultaneously"); + return 1; +} else if(!commands.isEmpty() && !connSuccessful) { + error("Cannot run commands specified using -e. No current connection"); + return 1; +} +if (!commands.isEmpty()) { + for (Iterator i = commands.iterator(); i.hasNext();) { +String command = i.next().toString(); +debug(loc("executing-command", command)); +if (!dispatch(command)) { + code++; +} + } + exit = true; // execute and exit +
hive git commit: HIVE-14063: beeline to auto connect to the HiveServer2 (Vihang Karajgaonkar, reviewed by Aihua Xu, Szehon Ho, Sergio Peña)
Repository: hive Updated Branches: refs/heads/master 9caf23001 -> 8029e11b3 HIVE-14063: beeline to auto connect to the HiveServer2 (Vihang Karajgaonkar, reviewed by Aihua Xu, Szehon Ho, Sergio Peña) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/8029e11b Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/8029e11b Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/8029e11b Branch: refs/heads/master Commit: 8029e11b3c913e0aebc0a719a19b85d96db28a32 Parents: 9caf230 Author: Aihua XuAuthored: Mon Oct 17 13:06:30 2016 -0400 Committer: Aihua Xu Committed: Mon Oct 17 13:08:29 2016 -0400 -- .../java/org/apache/hive/beeline/BeeLine.java | 176 ++- .../java/org/apache/hive/beeline/Commands.java | 52 +++-- .../BeelineHS2ConnectionFileParseException.java | 30 +++ .../hs2connection/HS2ConnectionFileParser.java | 88 .../hs2connection/HS2ConnectionFileUtils.java | 119 +++ .../HiveSiteHS2ConnectionFileParser.java| 172 +++ .../UserHS2ConnectionFileParser.java| 117 ++ .../apache/hive/beeline/TestBeeLineHistory.java | 4 +- .../TestUserHS2ConnectionFileParser.java| 211 ++ beeline/src/test/resources/hive-site.xml| 5 + .../test-hs2-conn-conf-kerberos-http.xml| 48 + .../test-hs2-conn-conf-kerberos-nossl.xml | 32 +++ .../test-hs2-conn-conf-kerberos-ssl.xml | 40 .../resources/test-hs2-connection-conf-list.xml | 36 .../test-hs2-connection-config-noauth.xml | 28 +++ .../test-hs2-connection-multi-conf-list.xml | 37 .../test-hs2-connection-zookeeper-config.xml| 32 +++ .../TestBeelineConnectionUsingHiveSite.java | 109 ++ .../TestBeelineWithHS2ConnectionFile.java | 214 +++ .../TestBeelineWithUserHs2ConnectionFile.java | 129 +++ 20 files changed, 1612 insertions(+), 67 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hive/blob/8029e11b/beeline/src/java/org/apache/hive/beeline/BeeLine.java -- diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 79922d2..fdbe0a2 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -28,6 +28,7 @@ import java.io.Closeable; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -93,8 +94,15 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.io.IOUtils; import org.apache.hive.beeline.cli.CliOptionsProcessor; import org.apache.hive.common.util.ShutdownHookManager; +import org.apache.hive.beeline.hs2connection.BeelineHS2ConnectionFileParseException; +import org.apache.hive.beeline.hs2connection.HS2ConnectionFileUtils; +import org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser; +import org.apache.hive.beeline.hs2connection.HS2ConnectionFileParser; +import org.apache.hive.beeline.hs2connection.HiveSiteHS2ConnectionFileParser; import org.apache.thrift.transport.TTransportException; +import com.google.common.annotations.VisibleForTesting; + import org.apache.hive.jdbc.Utils; import org.apache.hive.jdbc.Utils.JdbcConnectionParams; @@ -279,7 +287,6 @@ public class BeeLine implements Closeable { "org.apache.hadoop.hive.jdbc.HiveDriver", })); - static { try { Class.forName("jline.console.ConsoleReader"); @@ -728,6 +735,46 @@ public class BeeLine implements Closeable { return -1; } +boolean connSuccessful = connectUsingArgs(cl); +// checks if default hs2 connection configuration file is present +// and uses it to connect if found +// no-op if the file is not present +if(!connSuccessful && !exit) { + connSuccessful = defaultBeelineConnect(); +} + +int code = 0; +if (cl.getOptionValues('e') != null) { + commands = Arrays.asList(cl.getOptionValues('e')); +} + +if (!commands.isEmpty() && getOpts().getScriptFile() != null) { + error("The '-e' and '-f' options cannot be specified simultaneously"); + return 1; +} else if(!commands.isEmpty() && !connSuccessful) { + error("Cannot run commands specified using -e. No current connection"); + return 1; +} +if (!commands.isEmpty()) { + for (Iterator i = commands.iterator(); i.hasNext();) { +String command = i.next().toString(); +debug(loc("executing-command", command)); +if (!dispatch(command)) { +