You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by kg...@apache.org on 2018/06/15 06:20:08 UTC
hive git commit: HIVE-19744: In Beeline if -u is specified the
default connection should not be tried at all (Zoltan Haindrich reviewed by
Peter Vary)
Repository: hive
Updated Branches:
refs/heads/master f476fb4f9 -> 477f54184
HIVE-19744: In Beeline if -u is specified the default connection should not be tried at all (Zoltan Haindrich reviewed by Peter Vary)
Signed-off-by: Zoltan Haindrich <ki...@rxd.hu>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/477f5418
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/477f5418
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/477f5418
Branch: refs/heads/master
Commit: 477f541844db3ea5eaee8746033bf80cd48b7f8c
Parents: f476fb4
Author: Zoltan Haindrich <ki...@rxd.hu>
Authored: Fri Jun 15 07:14:22 2018 +0200
Committer: Zoltan Haindrich <ki...@rxd.hu>
Committed: Fri Jun 15 08:19:35 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/hive/beeline/BeeLine.java | 36 ++++++++++++--------
.../BeelineWithHS2ConnectionFileTestBase.java | 32 +++++++++++++----
.../TestBeelineConnectionUsingHiveSite.java | 26 +++++++++++---
.../TestBeelineWithUserHs2ConnectionFile.java | 6 ++--
4 files changed, 70 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/477f5418/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 ddb774e..e1efa34 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -51,8 +51,8 @@ import java.sql.SQLWarning;
import java.sql.Statement;
import java.text.ChoiceFormat;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -75,11 +75,6 @@ import java.util.TreeMap;
import java.util.TreeSet;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
-import jline.console.completer.Completer;
-import jline.console.completer.StringsCompleter;
-import jline.console.completer.FileNameCompleter;
-import jline.console.ConsoleReader;
-import jline.console.history.FileHistory;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
@@ -91,21 +86,26 @@ import org.apache.hadoop.fs.FileSystem;
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.BeelineConfFileParseException;
import org.apache.hive.beeline.hs2connection.BeelineSiteParseException;
import org.apache.hive.beeline.hs2connection.BeelineSiteParser;
-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.HS2ConnectionFileUtils;
import org.apache.hive.beeline.hs2connection.HiveSiteHS2ConnectionFileParser;
+import org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser;
+import org.apache.hive.common.util.ShutdownHookManager;
+import org.apache.hive.jdbc.JdbcUriParseException;
+import org.apache.hive.jdbc.Utils;
+import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
import org.apache.thrift.transport.TTransportException;
import com.google.common.annotations.VisibleForTesting;
-import org.apache.hive.jdbc.JdbcUriParseException;
-import org.apache.hive.jdbc.Utils;
-import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
+import jline.console.ConsoleReader;
+import jline.console.completer.Completer;
+import jline.console.completer.FileNameCompleter;
+import jline.console.completer.StringsCompleter;
+import jline.console.history.FileHistory;
/**
* A console SQL shell with command completion.
@@ -900,7 +900,11 @@ public class BeeLine implements Closeable {
comForDebug = constructCmdUrl(url, user, driver, true);
}
debug(comForDebug);
- return dispatch(com);
+ if (!dispatch(com)) {
+ exit = true;
+ return false;
+ }
+ return true;
}
// load property file
String propertyFile = cl.getOptionValue("property-file");
@@ -1286,7 +1290,9 @@ public class BeeLine implements Closeable {
if (!dispatch(line)) {
lastExecutionResult = ERRNO_OTHER;
- if (exitOnError) break;
+ if (exitOnError) {
+ break;
+ }
} else if (line != null) {
lastExecutionResult = ERRNO_OK;
}
@@ -2222,7 +2228,7 @@ public class BeeLine implements Closeable {
}
info("scan complete in "
+ (System.currentTimeMillis() - start) + "ms");
- return (Driver[]) driverClasses.toArray(new Driver[0]);
+ return driverClasses.toArray(new Driver[0]);
}
// /////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/hive/blob/477f5418/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/BeelineWithHS2ConnectionFileTestBase.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/BeelineWithHS2ConnectionFileTestBase.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/BeelineWithHS2ConnectionFileTestBase.java
index 2ed631a..06ada23 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/BeelineWithHS2ConnectionFileTestBase.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/BeelineWithHS2ConnectionFileTestBase.java
@@ -17,6 +17,7 @@
*/
package org.apache.hive.beeline.hs2connection;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.ByteArrayOutputStream;
@@ -191,8 +192,28 @@ public abstract class BeelineWithHS2ConnectionFileTestBase {
assertFalse(rowSet.numRows() == 0);
}
- protected String testBeeLineConnection(String path, String[] beelineArgs,
- String expectedOutput) throws IOException {
+ protected void assertBeelineOutputContains(String path, String[] beelineArgs,
+ String expectedOutput) throws Exception {
+ BeelineResult res = getBeelineOutput(path, beelineArgs);
+ assertEquals(0, res.exitCode);
+ Assert.assertNotNull(res.output);
+ Assert.assertTrue("Output " + res.output + " does not contain " + expectedOutput,
+ res.output.toLowerCase().contains(expectedOutput.toLowerCase()));
+ }
+
+ static class BeelineResult {
+
+ public final String output;
+ public final int exitCode;
+
+ public BeelineResult(String output, int exitCode) {
+ this.output = output;
+ this.exitCode = exitCode;
+ }
+
+ }
+
+ protected BeelineResult getBeelineOutput(String path, String[] beelineArgs) throws Exception {
TestBeeLine beeLine = null;
try {
if(path != null) {
@@ -202,13 +223,10 @@ public abstract class BeelineWithHS2ConnectionFileTestBase {
} else {
beeLine = new TestBeeLine();
}
- beeLine.begin(beelineArgs, null);
+ int exitCode = beeLine.begin(beelineArgs, null);
String output = beeLine.getOutput();
System.out.println(output);
- Assert.assertNotNull(output);
- Assert.assertTrue("Output " + output + " does not contain " + expectedOutput,
- output.toLowerCase().contains(expectedOutput.toLowerCase()));
- return output;
+ return new BeelineResult(output, exitCode);
} finally {
if (beeLine != null) {
beeLine.close();
http://git-wip-us.apache.org/repos/asf/hive/blob/477f5418/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineConnectionUsingHiveSite.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineConnectionUsingHiveSite.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineConnectionUsingHiveSite.java
index 8e60d67..480d414 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineConnectionUsingHiveSite.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineConnectionUsingHiveSite.java
@@ -17,6 +17,10 @@
*/
package org.apache.hive.beeline.hs2connection;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
@@ -27,21 +31,31 @@ public class TestBeelineConnectionUsingHiveSite extends BeelineWithHS2Connection
public void testBeelineConnectionHttp() throws Exception {
setupHs2();
String path = createDefaultHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
}
@Test
public void testBeelineConnectionSSL() throws Exception {
setupSSLHs2();
String path = createDefaultHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
}
@Test
public void testBeelineConnectionNoAuth() throws Exception {
setupNoAuthHs2();
String path = createDefaultHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
+ }
+
+ @Test
+ public void testBeelineDoesntUseDefaultIfU() throws Exception {
+ setupNoAuthHs2();
+ String path = createDefaultHs2ConnectionFile();
+ BeelineResult res = getBeelineOutput(path, new String[] {"-u", "invalidUrl", "-e", "show tables;" });
+ assertEquals(1, res.exitCode);
+ assertFalse(tableName + " should not appear", res.output.toLowerCase().contains(tableName));
+
}
/*
@@ -51,7 +65,9 @@ public class TestBeelineConnectionUsingHiveSite extends BeelineWithHS2Connection
@Test
public void testBeelineWithNoConnectionFile() throws Exception {
setupNoAuthHs2();
- testBeeLineConnection(null, new String[] { "-e", "show tables;" }, "no current connection");
+ BeelineResult res = getBeelineOutput(null, new String[] {"-e", "show tables;" });
+ assertEquals(1, res.exitCode);
+ assertTrue(res.output.toLowerCase().contains("no current connection"));
}
@Test
@@ -60,7 +76,7 @@ public class TestBeelineConnectionUsingHiveSite extends BeelineWithHS2Connection
String url = miniHS2.getBaseJdbcURL() + "default";
String args[] = new String[] { "-u", url, "-n", System.getProperty("user.name"), "-p", "foo",
"-e", "show tables;" };
- testBeeLineConnection(null, args, tableName);
+ assertBeelineOutputContains(null, args, tableName);
}
private void setupNoAuthHs2() throws Exception {
http://git-wip-us.apache.org/repos/asf/hive/blob/477f5418/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java
index ac595b4..84a8b37 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java
@@ -29,7 +29,7 @@ public class TestBeelineWithUserHs2ConnectionFile extends BeelineWithHS2Connecti
public void testBeelineConnectionHttp() throws Exception {
setupHttpHs2();
String path = createHttpHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
}
private void setupHttpHs2() throws Exception {
@@ -64,7 +64,7 @@ public class TestBeelineWithUserHs2ConnectionFile extends BeelineWithHS2Connecti
public void testBeelineConnectionNoAuth() throws Exception {
setupNoAuthConfHS2();
String path = createNoAuthHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
}
private void setupNoAuthConfHS2() throws Exception {
@@ -91,7 +91,7 @@ public class TestBeelineWithUserHs2ConnectionFile extends BeelineWithHS2Connecti
public void testBeelineConnectionSSL() throws Exception {
setupSslHs2();
String path = createSSLHs2ConnectionFile();
- testBeeLineConnection(path, new String[] { "-e", "show tables;" }, tableName);
+ assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName);
}
private String createSSLHs2ConnectionFile() throws Exception {