kyuubi/docs/quick_start/quick_start_with_jdbc.md
Cheng Pan e1e57e5233
[KYUUBI #4763] [DOCS] Fix the Kyuubi JDBC kerberos parameters
### _Why are the changes needed?_

The Kerberos-related parameters in Kyuubi JDBC driver are

- `kyuubiClientPrincipal`
- `kyuubiClientKeytab`
- `principal`. Since 1.7.0, `kyuubiServerPrincipal` is added as an alias

### _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

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #4763 from pan3793/kerberos-doc.

Closes #4763

7400e3a08 [Cheng Pan] nit
021c73174 [Cheng Pan] nit
337fb1229 [Cheng Pan] fix
4c4907bc8 [Cheng Pan] fix
d2478eeb7 [Cheng Pan] nit
3b0899d3e [Cheng Pan] nit
8dfdb6bde [Cheng Pan] [DOCS] Fix the Kyuubi JDBC kerberos parameters

Authored-by: Cheng Pan <chengpan@apache.org>
Signed-off-by: Cheng Pan <chengpan@apache.org>
2023-04-25 02:16:28 +08:00

3.3 KiB

Getting Started with Hive JDBC

How to get the Kyuubi JDBC driver

Kyuubi Thrift API is fully compatible w/ HiveServer2, so technically, it allows to use any Hive JDBC driver to connect Kyuubi Server. But it's recommended to use Kyuubi Hive JDBC driver, which is forked from Hive 3.1.x JDBC driver, aims to support some missing functionalities of the original Hive JDBC driver.

The driver is available from Maven Central:

<dependency>
    <groupId>org.apache.kyuubi</groupId>
    <artifactId>kyuubi-hive-jdbc-shaded</artifactId>
    <version>1.7.0</version>
</dependency>

Connect to non-kerberized Kyuubi Server

The below java code is using a keytab file to login and connect to Kyuubi server by JDBC.

package org.apache.kyuubi.examples;
  
import java.sql.*;

public class KyuubiJDBC {

  private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
  private static String kyuubiJdbcUrl = "jdbc:kyuubi://localhost:10009/default;";

  public static void main(String[] args) throws SQLException {
    try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
      try (Statement stmt = conn.createStatement()) {
        try (ResultSet rs = st.executeQuery("show databases")) {
          while (rs.next()) {
            System.out.println(rs.getString(1));
          }
        }   
      }
    }
  }
}

Connect to Kerberized Kyuubi Server

The following Java code uses a keytab file to login and connect to Kyuubi Server by JDBC.

package org.apache.kyuubi.examples;

import java.sql.*;

public class KyuubiJDBCDemo {

  private static String driverName = "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
  private static String kyuubiJdbcUrlTemplate = "jdbc:kyuubi://localhost:10009/default;" +
          "kyuubiClientPrincipal=%s;kyuubiClientKeytab=%s;kyuubiServerPrincipal=%s";

  public static void main(String[] args) throws SQLException {
    String clientPrincipal = args[0]; // Kerberos principal
    String clientKeytab = args[1];    // Keytab file location
    String serverPrincipal = arg[2];  // Kerberos principal used by Kyuubi Server
    String kyuubiJdbcUrl = String.format(kyuubiJdbcUrl, clientPrincipal, clientKeytab, serverPrincipal);
    try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
      try (Statement stmt = conn.createStatement()) {
        try (ResultSet rs = st.executeQuery("show databases")) {
          while (rs.next()) {
            System.out.println(rs.getString(1));
          }
        }
      }
    }
  }
}