The JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.

Requirements

To install Python-JayDeBeApi, you can use pip, the Python package manager. Open your command-line interface or terminal and run the following command:

  1. pip install jaydebeapi

If you want to install JayDeBeApi in Jython, you’ll need to ensure that you have either pip or EasyInstall available for Jython. These tools are used to install Python packages, including JayDeBeApi. Or you can get a copy of the source by cloning from the JayDeBeApi GitHub project and install it.

  1. python setup.py install

or if you are using Jython use

  1. jython setup.py install

Preparation

Using the Python-JayDeBeApi package to connect to Kyuubi, you need to install the library and configure the relevant JDBC driver. You can download JDBC driver from maven repository and specify its path in Python. Choose the matching driver kyuubi-hive-jdbc-*.jar package based on the Kyuubi server version. The driver class name is org.apache.kyuubi.jdbc.KyuubiHiveDriver.

Package Repo
kyuubi jdbc driver kyuubi-hive-jdbc-*.jar

Usage

Below is a simple example demonstrating how to use Python-JayDeBeApi to connect to Kyuubi database and execute a query:

  1. import jaydebeapi
  2. # Set JDBC driver path and connection URL
  3. driver = "org.apache.kyuubi.jdbc.KyuubiHiveDriver"
  4. url = "jdbc:kyuubi://host:port/default"
  5. jdbc_driver_path = ["/path/to/kyuubi-hive-jdbc-*.jar"]
  6. # Connect to the database using JayDeBeApi
  7. conn = jaydebeapi.connect(driver, url, ["user", "password"], jdbc_driver_path)
  8. # Create a cursor object
  9. cursor = conn.cursor()
  10. # Execute the SQL query
  11. cursor.execute("SELECT * FROM example_table LIMIT 10")
  12. # Retrieve query results
  13. result_set = cursor.fetchall()
  14. # Process the results
  15. for row in result_set:
  16. print(row)
  17. # Close the cursor and the connection
  18. cursor.close()
  19. conn.close()

Make sure to replace the placeholders (host, port, user, password) with your actual Kyuubi configuration. With the above code, you can connect to Kyuubi and execute SQL queries in Python. Please handle exceptions and errors appropriately in real-world applications.