All Products
Search
Document Center

E-MapReduce:Connect to Kyuubi

Last Updated:Dec 04, 2024

This topic describes how to use Beeline or a Java Database Connectivity (JDBC) driver to connect to Kyuubi. If you use Beeline to connect to Kyuubi, you can use ZooKeeper to connect to Kyuubi or directly connect to Kyuubi.

Prerequisites

  • A DataLake cluster that contains the Kyuubi service is created in the E-MapReduce (EMR) console. For more information, see Create a cluster.

  • You have logged on to the DataLake cluster. For more information, see Log on to a cluster.

Use Beeline to connect to Kyuubi

You can use Hive Beeline or Kyuubi Beeline to connect to the Kyuubi server. Kyuubi Beeline is named kyuubi-beeline in an EMR cluster. The following examples describe how to use kyuubi-beeline to connect to Kyuubi.

Common clusters

  • (Recommended) Method 1: Use ZooKeeper to connect to Kyuubi

    kyuubi-beeline -n user1 \
      -u "jdbc:hive2://master-1-1:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi"
  • Method 2: Directly connect to Kyuubi

    kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/"

    Run the following command to submit an SQL file:

    kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/" -f query1.sql

High-security clusters

Before you connect to Kyuubi, run the kinit command for identity authentication. For more information about Kerberos, see Basic operations on Kerberos.

  • (Recommended) Method 1: Use ZooKeeper to connect to Kyuubi

    kyuubi-beeline -n user1 \
      -u "jdbc:hive2://master-1-1:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=kyuubi;principal=kyuubi/_HOST@EMR"
  • Method 2: Directly connect to Kyuubi

    kyuubi-beeline -n user1 -u "jdbc:hive2://master-1-1:10009/;principal=kyuubi/_HOST@EMR"

Use a JDBC driver to connect to Kyuubi

The following example uses a Maven project to describe how to use a JDBC driver of Hive to connect a Java application to Kyuubi.

Maven dependency

Add the following dependency to the Maven project:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>2.3.9</version>
</dependency>

Sample code

Common clusters

import java.sql.*;

public class JDBCTest {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String kyuubiJdbcUrl = "jdbc:hive2://master-1-1:10009/default;";

    public static void main(String[] args) throws Exception {
        Class.forName(driverName);
        Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
        Statement st = conn.createStatement();
        ResultSet res = st.executeQuery("show databases");
        while (res.next()) {
            System.out.println(res.getString(1));
        }
        res.close();
        st.close();
        conn.close();
    }
}

High-security clusters

import java.sql.*;

public class JDBCTest {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String kyuubiJdbcUrl = "jdbc:hive2://master-1-1:10009/default;principal=kyuubi/_HOST@EMR";

    public static void main(String[] args) throws Exception {
        Class.forName(driverName);
        Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
        Statement st = conn.createStatement();
        ResultSet res = st.executeQuery("show databases");
        while (res.next()) {
            System.out.println(res.getString(1));
        }
        res.close();
        st.close();
        conn.close();
    }
}

References