Skip to content

Commit 85d0656

Browse files
a49apan3793
authored andcommitted
[KYUUBI #2781] Fix KyuubiDataSource#getConnection to set user and password
### _Why are the changes needed?_ Fix KyuubiDataSource#getConnection to set user and password Inspired by MySQL JDBC source code ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2844 from deadwind4/KYUUBI-2781. Closes #2781 f4c6a80 [Ada Wang] [KYUUBI #2781] Fix KyuubiDataSource#getConnection to set user and password Authored-by: Ada Wang <wang4luning@gmail.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 24c74e8 commit 85d0656

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDataSource.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
package org.apache.kyuubi.jdbc.hive;
1919

20+
import static org.apache.kyuubi.jdbc.hive.Utils.JdbcConnectionParams.AUTH_PASSWD;
21+
import static org.apache.kyuubi.jdbc.hive.Utils.JdbcConnectionParams.AUTH_USER;
22+
2023
import java.sql.Connection;
2124
import java.sql.SQLException;
25+
import java.util.Properties;
2226
import org.apache.kyuubi.jdbc.hive.adapter.SQLDataSource;
2327

2428
/** KyuubiDataSource. */
@@ -28,13 +32,20 @@ public KyuubiDataSource() {}
2832

2933
@Override
3034
public Connection getConnection() throws SQLException {
31-
return getConnection("", "");
35+
return getConnection(null, null);
3236
}
3337

3438
@Override
3539
public Connection getConnection(String username, String password) throws SQLException {
3640
try {
37-
return new KyuubiConnection("", null);
41+
Properties info = new Properties();
42+
if (username != null) {
43+
info.setProperty(AUTH_USER, username);
44+
}
45+
if (password != null) {
46+
info.setProperty(AUTH_PASSWD, password);
47+
}
48+
return new KyuubiConnection("", info);
3849
} catch (Exception ex) {
3950
throw new SQLException("Error in getting HiveConnection", ex);
4051
}

0 commit comments

Comments
 (0)