diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index e54e818b69..3b090853b7 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -1221,6 +1221,16 @@ private String getDefaultConnectionUrl(CommandLine cl) throws BeelineConfFilePar } hiveSiteConnectionProperties.setProperty(key, mergedConnectionProperties.getProperty(key)); } + + // Without specifying AUTH_USER or AUTH_PASSWD beeline will ask for username and password which is different from the -u behaviour + if (!hiveSiteConnectionProperties.contains(JdbcConnectionParams.AUTH_USER)) { + hiveSiteConnectionProperties.put(JdbcConnectionParams.AUTH_USER, ""); + } + + if (!hiveSiteConnectionProperties.contains(JdbcConnectionParams.AUTH_PASSWD)) { + hiveSiteConnectionProperties.put(JdbcConnectionParams.AUTH_PASSWD, ""); + } + // return the url based on the aggregated connection properties return HS2ConnectionFileUtils.getUrl(hiveSiteConnectionProperties); } diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java index 84a8b3754b..9677e0807d 100644 --- itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java +++ itests/hive-unit/src/test/java/org/apache/hive/beeline/hs2connection/TestBeelineWithUserHs2ConnectionFile.java @@ -67,6 +67,13 @@ public void testBeelineConnectionNoAuth() throws Exception { assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName); } + @Test + public void testBeelineConnectionNoAuthWithoutUserAndPasswordSpecified() throws Exception { + setupNoAuthConfHS2(); + String path = createNoAuthHs2ConnectionFileWithoutUserAndPasswordSpecified(); + assertBeelineOutputContains(path, new String[] { "-e", "show tables;" }, tableName); + } + private void setupNoAuthConfHS2() throws Exception { // use default configuration for no-auth mode miniHS2.start(confOverlay); @@ -87,6 +94,17 @@ private String createNoAuthHs2ConnectionFile() throws Exception { return writer.path(); } + private String createNoAuthHs2ConnectionFileWithoutUserAndPasswordSpecified() throws Exception { + Hs2ConnectionXmlConfigFileWriter writer = new Hs2ConnectionXmlConfigFileWriter(); + String baseJdbcURL = miniHS2.getBaseJdbcURL(); + URI uri = new URI(baseJdbcURL.substring(5)); + writer.writeProperty(HS2ConnectionFileParser.BEELINE_CONNECTION_PROPERTY_PREFIX + "hosts", + uri.getHost() + ":" + uri.getPort()); + + writer.close(); + return writer.path(); + } + @Test public void testBeelineConnectionSSL() throws Exception { setupSslHs2();