Core+ Java Fight SQL Client
Flight SQL is a protocol on top of Arrow Flight that exposes SQL-like capabilities. Deephaven Core+ workers provide a built-in Flight SQL server that makes tables in the global query scope available as named tables. These tables can be accessed and queried through the default Flight SQL catalog using standard SQL queries.
Note
SELECT queries are supported; INSERT, UPDATE, and DELETE queries are not currently supported.
While Flight SQL may be an easy jumping-off point, the Flight SQL APIs are not Live Dataframe APIs. If you need to receive real-time updates, the best option is the Deephaven-native clients, such as the Deephaven Core+ Java client.
In Deephaven Community Core, you can connect directly to the Flight SQL server using most standard Flight SQL clients. For details, see the Community Flight SQL guide.
Note
In Deephaven Core+, standard Flight SQL clients do not work out of the box because of enhanced authentication and session management requirements. You can still connect by implementing a small amount of custom code, as described below.
The source code for this guide is available in a ZIP archive.
Prerequisites
This guide assumes:
-
You are using a Linux-based operating system. While the scripts and Java code used should also work on Windows, command syntax and environment setup may differ slightly between platforms.
-
You are familiar with Java and Gradle.
You must have the following to use the Java Flight SQL client:
- Access to a running Deephaven Core+ instance with Flight SQL enabled (Grizzly version 1.20240517.491 or later).
- JDK 17 or newer installed.
- Gradle 7.3 or newer installed.
Set up a Gradle project
To get started, create a new Gradle Java project:
This will generate a basic Java application structure using Gradle, with the package set to io.deephaven.example and Java 17 as the language version.
Configure dependencies and authentication
To use the Core+ Java client, you need access to Deephaven's private Artifactory repository. Obtain your Artifactory username and API key from your administrator. Then, add the following lines to your gradle.properties file (typically located at ${HOME}/.gradle/gradle.properties):
Next, replace the contents of your project's build.gradle file with the following configuration:
Note
Update the dhcVersion and dheVersion variables to match the versions of Deephaven you are connecting to.
Persistent Query setup
This example demonstrates how to connect to a Persistent Query to retrieve data. First, log in to your Deephaven server's web UI, then use the Query Monitor to create a Persistent Query.
- On the Settings tab:
- Name the PQ
FlightSqlTestJavaClientPQ. - Select
Live Query (Script)for the type. - Select a DB Server of
AutoQuery. - Use the Core+ engine.
- Give it a heap size of 1 GB.
-
On the Scheduling tab, select
Disabled. -
On the Script tab, select a Runtime of
Python. The script consists of one line to retrieve theProcessEventLogtable and view theLogEntrycolumn in the order it was written. This table contains events written out by Deephaven workers and can help diagnose issues.
- Save the PQ.
Flight SQL example
Below is a complete example Java program, FlightSqlExample.java, that demonstrates connecting to a Deephaven Core+ server using the Flight SQL protocol and retrieving data from a table via SQL query.
This example covers:
- Creating a Deephaven session and authenticating with the server.
- Ensuring the specified PQ is running.
- Listing available tables in the system catalog.
- Leveraging the FlightClient from your session to create a FlightSqlClient.
- Using the FlightSqlClient to execute SQL queries against Deephaven tables, retrieve results, and print them.
To use this example:
- Update the placeholders in the code (
your-dh-host,your-username,your-password) with your actual Deephaven server details and credentials. - Ensure the PQ name (
FlightSqlTestJavaClientPQ) and table name (pel) match those created in the previous steps. - Place the code in
src/main/java/io/deephaven/example/FlightSqlExample.javawithin your Gradle project. - Build and run the project using Gradle from the project's root directory.
Expand the section below to view the full source code.
FlightSqlExample.java
Sample output
If the example runs successfully, you should see output similar to the following. The system catalog section lists available tables, and the Flight SQL result section displays the first few rows from the queried table.