Instructions

Kyuubi currently supports the Trino connection protocol, so we can use Trino-JDBC to connect to the kyuubi server and submit SQL to Spark, Trino and other engines for execution.

Start Kyuubi Trino Server

First we should configure the trino protocol and the service port in the kyuubi.conf

  1. kyuubi.frontend.protocols TRINO
  2. kyuubi.frontend.trino.bind.port 10999 #default port

Install Trino JDBC

Download trino-jdbc-411.jar and add it to the classpath of your Java application.

The driver is also available from Maven Central:

  1. <dependency>
  2. <groupId>io.trino</groupId>
  3. <artifactId>trino-jdbc</artifactId>
  4. <version>411</version>
  5. </dependency>

JDBC URL

When your driver is loaded, registered and configured, you are ready to connect to Trino from your application. The following JDBC URL formats are supported:

  1. jdbc:trino://host:port

Trino JDBC example

  1. String trinoHost = "localhost";
  2. String trinoPort = "10999";
  3. String trinoUser = "default";
  4. String trinoPassword = null;
  5. Connection connection = null;
  6. ResultSet rs = null;
  7. try {
  8. // Create the connection using the JDBC URL
  9. connection = DriverManager.getConnection("jdbc:trino://" + trinoHost + ":" + trinoPort, trinoUser, trinoPassword);
  10. // Do whatever you need to do with the connection
  11. Statement stmt = connection.createStatement();
  12. rs = stmt.executeQuery("SELECT 1");
  13. while (rs.next()) {
  14. // retrieve data from the ResultSet
  15. }
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. } finally {
  19. try {
  20. // Close the connection when you're done with it
  21. if (rs != null) rs.close();
  22. if (connection != null) connection.close();
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }
  26. }

The configuration of the connection parameters can be found in the official trino documentation at: https://trino.io/docs/current/client/jdbc.html#connection-parameters