Kyuubi Gateway provides Java Database Connectivity (JDBC) and Open Database Connectivity (ODBC) interfaces. These interfaces allow you to connect Serverless Spark to SQL query tools and business intelligence (BI) tools, such as Tableau and Power BI, for efficient data access and analysis. The gateway also supports enterprise applications through its multi-tenant resource isolation feature.
Create a Kyuubi Gateway
-
Go to the Gateway page.
-
Log on to the EMR console.
-
In the navigation pane on the left, choose EMR Serverless > Spark.
-
On the Spark page, click the name of the target workspace.
-
On the EMR Serverless Spark page, click in the navigation pane on the left.
-
-
On the Kyuubi Gateway page, click Create Kyuubi Gateway.
-
On the Create Kyuubi Gateway page, configure the parameters and click create.
Parameter
Description
Name
The name of the new gateway. The name can contain only lowercase letters, digits, and hyphens (-). It must start and end with a letter or a digit.
Kyuubi Gateway Resources
The default value is
2 CPU, 8 GB.The supported specifications and their recommended maximum concurrency are as follows:
-
1 CPU, 4 GB: 10 -
2 CPU, 8 GB: 20 -
4 CPU, 16 GB: 30 -
8 CPU, 32 GB: 45 -
16 CPU, 64 GB: 85 -
32 CPU, 128 GB: 135
NoteMany Spark configuration items can reduce the instantaneous submission concurrency for Spark tasks.
Kyuubi Version
The Kyuubi version used by the current gateway.
NoteIf you use DLF (formerly DLF 2.5) in the Catalogs, you must set Kyuubi Version to 1.9.2-0.0.1 or later.
Engine Version
The engine version used by the current gateway. For more information about engine version numbers, see Engine versions.
Associated Queue
The created gateway will be deployed in the selected queue. When you submit a Spark task through the gateway, the task is submitted using the identity of the gateway creator.
Authentication Method
Only token-based authentication is supported.
After you create a gateway, you must generate a unique authentication token for it. This token is used for identity verification and access control in subsequent requests. For more information about how to create a token, see Gateway management.
High Service Availability
After you enable service high availability (HA), three or more Kyuubi Servers are deployed to ensure HA.
After you turn on this switch, you must also configure the following parameters:
-
Number of Kyuubi Servers: The number of Kyuubi servers.
-
Zookeeper cluster address: A high-availability Kyuubi Gateway depends on a Zookeeper cluster. Enter the Zookeeper cluster endpoint. Separate multiple nodes with commas (,). Make sure the network is connected. For example,
zk1:2181,zk2:2181,zk3:2181.
Normal Network Connection
Select an existing network connection to access data sources in a VPC or external services. For more information about how to create a network connection, see Network connectivity between EMR Serverless Spark and other VPCs.
Endpoint(Public)
This feature is disabled by default. If you enable this feature, the system accesses Kyuubi through a public endpoint. Otherwise, Kyuubi is accessed through an internal same-region endpoint by default.
Kyuubi Configuration
Enter the Kyuubi configuration information. By default, parameters are separated by spaces. For example:
kyuubi.engine.pool.size 1.Only the following Kyuubi configurations are supported.
kyuubi.engine.pool.size kyuubi.engine.pool.size.threshold kyuubi.engine.share.level kyuubi.engine.single.spark.session kyuubi.session.engine.idle.timeout kyuubi.session.engine.initialize.timeout kyuubi.engine.security.token.max.lifetime kyuubi.session.engine.check.interval kyuubi.session.idle.timeout kyuubi.session.engine.request.timeout kyuubi.session.engine.login.timeout kyuubi.backend.engine.exec.pool.shutdown.timeout kyuubi.backend.server.exec.pool.shutdown.timeout kyuubi.backend.server.exec.pool.keepalive.time kyuubi.frontend.thrift.login.timeout kyuubi.operation.status.polling.timeout kyuubi.engine.pool.selectPolicy kyuubi.authentication kyuubi.kinit.principal kyuubi.kinit.keytab kyuubi.authentication.ldap.* kyuubi.hadoop.proxyuser.hive.hosts kyuubi.hadoop.proxyuser.hive.groups kyuubi.hadoop.proxyuser.kyuubi.hosts kyuubi.hadoop.proxyuser.kyuubi.groups kyuubi.ha.*Spark Configuration
Enter the Spark configuration information. By default, parameters are separated by spaces. All parameters are supported except those of the
spark.kubernetes.*type. For example:spark.sql.catalog.paimon.metastore dlf. -
-
On the Kyuubi Gateway page, find the gateway that you created and click START in the Actions column.
Manage tokens
-
On the Kyuubi Gateway page, locate the target gateway and click Token Management in the Actions column.
-
Click Create Token.
-
In the Create Token dialog box, configure the parameters and click OK.
Parameter
Description
Name
The name of the new token.
Expired At
Set the time-to-live (TTL) for the token. The number of days must be greater than or equal to 1. By default, this feature is enabled and the token expires after 365 days.
Assign Object
Note-
If you use DLF (formerly DLF 2.5) by default on the Catalogs tab, you must configure this parameter.
-
Make sure that the configured Resource Access Management (RAM) user or RAM role has the permissions to access DLF. For more information about how to grant permissions, see Add an authorization.
-
The RAM user or RAM role must be added to the Spark workspace before it appears in the Assign Object drop-down list. For more information, see Manage users and roles.
From the drop-down list, select the RAM user or RAM role that you added in Access Control.
Specify the RAM user or RAM role to which the token is assigned. This user or role is used to access DLF when you connect to the Kyuubi Gateway to submit a Spark task.
-
-
Copy the token information.
ImportantAfter a token is created, you must copy the token information immediately because you cannot view it again later. If a token expires or is lost, you must create or reset the token.
Connect to a Kyuubi Gateway
When you connect to a Kyuubi Gateway, replace the placeholders in the JDBC URL with your actual information:
-
<endpoint>: The endpoint that you can obtain from the Overview tab. -
<port>: The port number. Use port 443 for public endpoint access and port 80 for internal same-region endpoint access. -
<token>: The token that you copied from the Token Management tab. -
<tokenname>: The token name. You can obtain the name from the Token Management tab. -
<UserName/RoleName>: The RAM user or RAM role that you added in Access Control.
Connect using Beeline
When you connect to a Kyuubi Gateway, ensure that your Beeline version is compatible with the Kyuubi server-side version. If you have not installed Beeline, see Getting Started - Apache Kyuubi.
Perform one of the following operations based on the default catalog that is used on the Catalogs page.
Use DLF (formerly DLF 2.5)
beeline -u "jdbc:hive2://<endpoint>:<port>/;transportMode=http;user=<UserName/RoleName>;httpPath=cliservice/token/<token>"
Use other catalogs
beeline -u "jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>"
When you connect using Beeline, you can modify session parameters. For example, beeline -u "jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>;#spark.sql.shuffle.partitions=100;spark.executor.instances=2;".
Connect using Java
-
Update the pom.xml file.
Replace
hadoop-commonandhive-jdbcwith the appropriate dependency versions.<dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>2.3.9</version> </dependency> </dependencies> -
Write Java code to connect to the Kyuubi Gateway.
Perform one of the following operations based on the default catalog that is used on the Catalogs page.
Use DLF (formerly DLF 2.5)
import org.apache.hive.jdbc.HiveStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; public class Main { public static void main(String[] args) throws Exception { String url = "jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>;user=<UserName/RoleName>"; Class.forName("org.apache.hive.jdbc.HiveDriver"); Connection conn = DriverManager.getConnection(url); HiveStatement stmt = (HiveStatement) conn.createStatement(); String sql = "select * from students;"; System.out.println("Running " + sql); ResultSet res = stmt.executeQuery(sql); ResultSetMetaData md = res.getMetaData(); String[] columns = new String[md.getColumnCount()]; for (int i = 0; i < columns.length; i++) { columns[i] = md.getColumnName(i + 1); } while (res.next()) { System.out.print("Row " + res.getRow() + "=["); for (int i = 0; i < columns.length; i++) { if (i != 0) { System.out.print(", "); } System.out.print(columns[i] + "='" + res.getObject(i + 1) + "'"); } System.out.println(")]"); } conn.close(); } }Use other catalogs
import org.apache.hive.jdbc.HiveStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; public class Main { public static void main(String[] args) throws Exception { String url = "jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>"; Class.forName("org.apache.hive.jdbc.HiveDriver"); Connection conn = DriverManager.getConnection(url); HiveStatement stmt = (HiveStatement) conn.createStatement(); String sql = "select * from students;"; System.out.println("Running " + sql); ResultSet res = stmt.executeQuery(sql); ResultSetMetaData md = res.getMetaData(); String[] columns = new String[md.getColumnCount()]; for (int i = 0; i < columns.length; i++) { columns[i] = md.getColumnName(i + 1); } while (res.next()) { System.out.print("Row " + res.getRow() + "=["); for (int i = 0; i < columns.length; i++) { if (i != 0) { System.out.print(", "); } System.out.print(columns[i] + "='" + res.getObject(i + 1) + "'"); } System.out.println(")]"); } conn.close(); } }
Connect using Python
-
Run the following command to install the PyHive and Thrift packages.
pip3 install pyhive thrift -
Write a Python script to connect to the Kyuubi Gateway.
The following example shows a Python script that connects to a Kyuubi Gateway and displays a list of databases.
Perform one of the following operations based on the default catalog that is used on the Catalogs page.
Use DLF (formerly DLF 2.5)
from pyhive import hive if __name__ == '__main__': cursor = hive.connect('<endpoint>', port="<port>", scheme='http', username='<UserName/RoleName>', password='<token>').cursor() cursor.execute('show databases') print(cursor.fetchall()) cursor.close()Use other catalogs
from pyhive import hive if __name__ == '__main__': cursor = hive.connect('<endpoint>', port="<port>", scheme='http', username='<tokenname>', password='<token>').cursor() cursor.execute('show databases') print(cursor.fetchall()) cursor.close()
Connect using the REST API
Kyuubi Gateway provides open-source-compatible REST APIs that support interaction with the Kyuubi service over HTTP. Currently, only the following API paths are supported:
-
/api/v1/sessions/* -
/api/v1/operations/* -
/api/v1/batches/*
The following examples show how to use the REST API to connect to a Kyuubi Gateway.
-
Example 1: Start a session and perform an SQL query.
-
Create a session and specify Spark configurations.
Perform one of the following operations based on the default catalog that is used on the Catalogs page.
Note-
spark.emr.serverless.kyuubi.engine.queuespecifies the queue that is used by the Spark task at runtime. Replace<dev_queue>with the actual queue name. -
Replace
<UserName/Rolename>with the actual username or role name. -
<password>is a placeholder. You can enter any value.
Use DLF (formerly DLF 2.5)
curl -X 'POST' \ 'http://<endpoint>:<port>/api/v1/sessions/token/<token>' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -u '<UserName/Rolename>:<password>' \ -d '{ "configs": { "set:hivevar:spark.emr.serverless.kyuubi.engine.queue": "<dev_queue>" } }'Use other catalogs
curl -X 'POST' \ 'http://<endpoint>:<port>/api/v1/sessions/token/<token>' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "configs": { "set:hivevar:spark.emr.serverless.kyuubi.engine.queue": "<dev_queue>" } }'A message similar to the following is returned. In the message,
identifieris the Kyuubi session handle, which uniquely identifies a session. In this topic, this value is referred to as<sessionHandle>.{"identifier":"619e6ded-xxxx-xxxx-xxxx-c2a43f6fac46","kyuubiInstance":"0.0.0.0:10099"} -
-
Create a statement.
Use DLF (formerly DLF 2.5)
curl -X 'POST' \ 'http://<endpoint>:<port>/api/v1/sessions/<sessionHandle>/operations/statement/token/<token>' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -u '<UserName/RoleName>:<password>' \ -d '{ "statement": "select * from test;", "runAsync": true, "queryTimeout": 0, "confOverlay": { "additionalProp1": "string", "additionalProp2": "string" } }'Use other catalogs
curl -X 'POST' \ 'http://<endpoint>:<port>/api/v1/sessions/<sessionHandle>/operations/statement/token/<token>' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "statement": "select * from test;", "runAsync": true, "queryTimeout": 0, "confOverlay": { "additionalProp1": "string", "additionalProp2": "string" } }'A message similar to the following is returned. In the message,
identifieris the Kyuubi operation handle, which uniquely identifies a specific operation. In this topic, this value is referred to as<operationHandle>.{"identifier":"a743e8ff-xxxx-xxxx-xxxx-a66fec66cfa4"} -
Retrieve the statement status.
Use DLF (formerly DLF 2.5)
curl --location -X 'GET' \ 'http://<endpoint>:<port>/api/v1/operations/<operationHandle>/event/token/<token>' \ -H 'accept: application/json' \ -u '<UserName/RoleName>:<password>'Use other catalogs
curl --location -X 'GET' \ 'http://<endpoint>:<port>/api/v1/operations/<operationHandle>/event/token/<token>' \ -H 'accept: application/json' -
Retrieve the statement result.
Use DLF (formerly DLF 2.5)
curl --location -X 'GET' \ 'http://<endpoint>:<port>/api/v1/operations/<operationHandle>/rowset/token/<token>/?maxrows=100&fetchorientation=FETCH_NEXT' \ -H 'accept: application/json' \ -u '<UserName/RoleName>:<password>'Use other catalogs
curl --location -X 'GET' \ 'http://<endpoint>:<port>/api/v1/operations/<operationHandle>/rowset/token/<token>/?maxrows=100&fetchorientation=FETCH_NEXT' \ -H 'accept: application/json'
-
-
Example 2: Use the batches API to submit a batch job.
Submit a Spark batch processing job to the Kyuubi Gateway using the REST API. The Kyuubi Gateway starts a Spark application and executes the specified task based on the parameters in the request.
In this example, in addition to replacing information such as
<endpoint>,<port>, and<token>, you must also click spark-examples_2.12-3.3.1.jar to download the test JAR package.NoteThis JAR package is a simple example that is provided with Spark and is used to calculate the value of Pi (π).
Use DLF (formerly DLF 2.5)
curl --location \ --request POST 'http://<endpoint>:<port>/api/v1/batches/token/<token>' \ --user '<UserName/RoleName>:<password>' \ --form 'batchRequest="{ \"batchType\": \"SPARK\", \"className\": \"org.apache.spark.examples.SparkPi\", \"name\": \"kyuubi-spark-pi\", \"resource\": \"oss://bucket/path/to/spark-examples_2.12-3.3.1.jar\" }";type=application/json'Use other catalogs
curl --location \ --request POST 'http://<endpoint>:<port>/api/v1/batches/token/<token>' \ --form 'batchRequest="{ \"batchType\": \"SPARK\", \"className\": \"org.apache.spark.examples.SparkPi\", \"name\": \"kyuubi-spark-pi\", \"resource\": \"oss://bucket/path/to/spark-examples_2.12-3.3.1.jar\" }";type=application/json'
Connect using Apache Superset
Apache Superset is a modern data exploration and visualization platform with a rich variety of charts. For more information about Superset, see the Superset documentation.
Before you connect to a Kyuubi Gateway using Superset, ensure that you have installed Thrift 0.20.0 or later. If you have not, run the following command to install it:
pip install thrift==0.20.0
-
Start Superset and go to the Superset interface. For more information about how to start Superset, see the Superset documentation.
-
In the upper-right corner of the page, click DATABASE to go to the Connect a database page.
-
On the Connect a database page, select Apache Spark SQL.
-
In the SQLAlchemy URI field, enter the connection string that corresponds to the access method.
Public network access
hive+https://<username>:<token>@<endpoint>:443/<db_name>VPC network access
hive+http://<username>:<token>@<endpoint>:80/<db_name>The following table describes the parameters.
Parameter
Description
username
The username. You can enter any value.
Token
The access token.
Endpoint
The access endpoint of the Kyuubi Gateway. You must distinguish between the public endpoint and the internal endpoint.
db_name
The database name.
-
Click Connect to complete the connection configuration.
Connect using HUE
Before you connect to a Kyuubi Gateway using HUE, ensure that you have installed Thrift 0.20.0. If you have not, run the following command to install it:
pip install thrift==0.20.0
-
Edit the HUE configuration file
/etc/hue/hue.confand add the configuration that corresponds to your access method.Public network access
[[[sparksql]]] name = Spark Sql interface=sqlalchemy options='{"url": "hive+https://<username>:<token>@<endpoint>:443/"}'VPC network access
[[[sparksql]]] name = Spark Sql interface=sqlalchemy options='{"url": "hive+http://<username>:<token>@<endpoint>:80/"}'The parameters are described in the following table.
Parameter
Description
username
The username. You can enter any value.
Token
The access token.
Endpoint
The access endpoint of the Kyuubi Gateway.
-
Restart the HUE service.
sudo service hue restart -
Log on to the HUE web UI. In the navigation pane on the left, choose Query > Editor > SparkSql to verify the connection.
Connect using DataGrip
Before you connect to a Kyuubi Gateway using DataGrip, ensure that you have downloaded the Apache Spark JDBC Driver (version 1.2.2, for Spark 3.x compatibility).
-
Open DataGrip and create a new project.
-
In the Database Explorer panel on the right, click the + icon and choose Data Source > Other > Apache Spark.
-
In the Data Sources and Drivers dialog box, configure the following parameters.
Parameter
Description
Name
A custom connection name.
Authentication
Select No auth or User & Password. You can enter any username.
Driver
Select Apache Spark ver. 1.2.2.
URL
Public network access
jdbc:hive2://<endpoint>:443/;transportMode=http;httpPath=cliservice/token/<token>VPC network access
jdbc:hive2://<endpoint>:80/;transportMode=http;httpPath=cliservice/token/<token>Where
<endpoint>is the access endpoint of the Kyuubi Gateway, and<token>is the access token. -
Click Test Connection to verify the connection.

-
Click OK to save the configuration.
Configure and connect to a high-availability Kyuubi Gateway
-
Establish a network connection.
To establish a network connection, see Establish network connectivity between EMR Serverless Spark and other VPCs. Ensure that your client can access the Zookeeper cluster in the target VPC. For example, you can use the Zookeeper component of Alibaba Cloud MSE or EMR on ECS.
-
Enable high availability for the Kyuubi Gateway.
When you create or edit a Kyuubi Gateway, enable High Service Availability, configure the related parameters, and select the established network connection for Normal Network Connection.
-
Connect to the high-availability Kyuubi Gateway.
After you complete the preceding configurations, the Kyuubi Gateway achieves high availability using Zookeeper. You can verify its availability using a REST API or JDBC connection.
When you connect to a Kyuubi Gateway, replace the placeholders in the JDBC URL with your actual information:
-
<endpoint>: The endpoint that you can obtain from the Overview tab. -
<port>: The port number. Use port 443 for public endpoint access and port 80 for internal same-region endpoint access. -
<token>: The token that you copied from the Token Management tab. -
<tokenname>: The token name. You can obtain the name from the Token Management tab. -
<UserName/RoleName>: The RAM user or RAM role that you added in Access Control.
The following examples show how to connect to a high-availability Kyuubi Gateway.
Connect using Beeline
-
Click kyuubi-hive-jdbc-1.9.2.jar to download the JDBC Driver JAR file.
-
Replace the JDBC Driver JAR file.
-
Back up and move the original JDBC Driver JAR file.
mv /your_path/apache-kyuubi-1.9.2-bin/beeline-jars /bak_pathNoteIf you are using EMR on ECS, the default path for Kyuubi is
/opt/apps/KYUUBI/kyuubi-1.9.2-1.0.0/beeline-jars. If you are unsure of the Kyuubi installation path, you can run theenv | grep KYUUBI_HOMEcommand to find it. -
Replace it with the new JDBC Driver JAR file.
cp /download/serverless-spark-kyuubi-hive-jdbc-1.9.2.jar /your_path/apache-kyuubi-1.9.2-bin/beeline-jars
-
-
Connect using Beeline.
/your_path/apache-kyuubi-1.9.2-bin/bin/beeline -u 'jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>'
Connect using Java
-
Click serverless-spark-kyuubi-hive-jdbc-shaded-1.9.2.jar to download the shaded package.
-
Install the JDBC Driver to the Maven repository.
Run the following command to install the JDBC Driver provided by Serverless Spark to your local Maven repository.
mvn install:install-file \ -Dfile=/download/serverless-spark-kyuubi-hive-jdbc-shaded-1.9.2.jar \ -DgroupId=org.apache.kyuubi \ -DartifactId=kyuubi-hive-jdbc-shaded \ -Dversion=1.9.2-ss \ -Dpackaging=jar -
Modify the
pom.xmlfile.Add the following dependencies to the
pom.xmlfile of your project.<dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.apache.kyuubi</groupId> <artifactId>kyuubi-hive-jdbc-shaded</artifactId> <version>1.9.2-ss</version> </dependency> </dependencies> -
Write the sample Java code.
import org.apache.kyuubi.jdbc.hive.KyuubiStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; public class Main { public static void main(String[] args) throws Exception { String url = "jdbc:hive2://<endpoint>:<port>/;transportMode=http;httpPath=cliservice/token/<token>"; Class.forName("org.apache.kyuubi.jdbc.KyuubiHiveDriver"); Connection conn = DriverManager.getConnection(url); KyuubiStatement stmt = (KyuubiStatement) conn.createStatement(); String sql = "select * from test;"; ResultSet res = stmt.executeQuery(sql); ResultSetMetaData md = res.getMetaData(); String[] columns = new String[md.getColumnCount()]; for (int i = 0; i < columns.length; i++) { columns[i] = md.getColumnName(i + 1); } while (res.next()) { System.out.print("Row " + res.getRow() + "=["); for (int i = 0; i < columns.length; i++) { if (i != 0) { System.out.print(", "); } System.out.print(columns[i] + "='" + res.getObject(i + 1) + "'"); } System.out.println(")]"); } conn.close(); } }
-
View the list of Spark tasks submitted by Kyuubi
You can view the details of Spark tasks that are submitted through Kyuubi on the Kyuubi Application tab of the Job History page. The details include the ID, Name, Application Status, and Started At. This information helps you quickly understand and manage Spark tasks that are submitted by Kyuubi.
-
On the Kyuubi Gateway page, click the name of the target Kyuubi Gateway.
-
In the upper-right corner, click Applications.

On this page, you can view the details of all Spark tasks that are submitted through this Kyuubi instance. The ID (spark-xxxx) is generated by the Spark engine and is identical to the Application ID that is displayed when you connect to the Kyuubi client. It uniquely identifies a task instance.
