Skip to content

Commit

Permalink
HIVE-15540: Impl DatabaseMetaData#getURL() and `DatabaseMetaData#ge…
Browse files Browse the repository at this point in the history
…tUserName()` for HiveServer2 JDBC Driver
  • Loading branch information
linghengqian committed Dec 12, 2024
1 parent 4218877 commit edf9bda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.hive.jdbc;

import org.apache.hive.jdbc.HiveConnection;
import org.apache.hive.jdbc.Utils;
import org.apache.hive.jdbc.Utils.JdbcConnectionParams;

import java.util.LinkedHashMap;
Expand Down Expand Up @@ -107,4 +105,16 @@ public void testHiveConnectionUdateServerHiveConf() {
.get(Utils.JdbcConnectionParams.HIVE_CONF_PREFIX + "hive.default.nulls.last"));

}

@Test
public void testGetUserName() throws SQLException {
HiveConnection hiveConnection = new HiveConnection("jdbc:hive2:///;user=foo", new Properties());
hiveDatabaseMetaData = new HiveDatabaseMetaData(hiveConnection, null, null);
assertEquals("foo", hiveDatabaseMetaData.getUserName());
}

@Test
public void testGetURL() {
assertEquals(connection.getConnectedUrl(), hiveDatabaseMetaData.getURL());
}
}
2 changes: 1 addition & 1 deletion jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ public void updateServerHiveConf(Map<String, String> serverHiveConf, JdbcConnect
/**
* @return username from sessConfMap
*/
private String getUserName() {
String getUserName() {
return getSessionValue(JdbcConnectionParams.AUTH_USER, JdbcConnectionParams.ANONYMOUS_USER);
}

Expand Down
8 changes: 4 additions & 4 deletions jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
};
}

public String getURL() throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
public String getURL() {
return connection.getConnectedUrl();
}

public String getUserName() throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
public String getUserName() {
return connection.getUserName();
}

public ResultSet getVersionColumns(String catalog, String schema, String table)
Expand Down

0 comments on commit edf9bda

Please sign in to comment.