Connecting to a Deephaven Flight SQL server

Flight SQL is a protocol on top of Arrow Flight that exposes SQL-like capabilities.

The Deephaven Flight SQL server exposes Deephaven tables from the global query scope as named tables that can be accessed and queried via the default Flight SQL catalog. It's a built-in part of the Deephaven server and listens on the same port.

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 Deephaven-native clients are the best option.

Examples using anonymous authentication

Each of the following examples demonstrates:

  1. Connecting to an insecure (w/o TLS) Deephaven Flight SQL server on localhost with port 10000.
  2. Using Anonymous authentication.
  3. Executing the SQL command SELECT 42 as Foo. Note, to run a more meaningful query, such as "SELECT * from StockQuotes", you need to have a table "StockQuotes" in the global query scope first.
  4. Printing out the results.

Note

Additional configuration options for TLS and authentication will likely be needed when connecting Flight SQL clients to production servers.

If the Flight SQL client expects to use cookies for authentication, the x-deephaven-auth-cookie-request header must be set to true.

ADBC Flight SQL

Arrow Database Connectivity (ADBC) is an Arrow-first interface for efficiently fetching large datasets from a database. It's a great choice when paired with the Deephaven Flight SQL server given that the Flight protocol itself is Arrow-first.

There are a variety of ADBC client implementations that have Flight SQL drivers.

ADBC Python

The ADBC Python library has a Flight SQL driver, and is simple to use from Python. Installation is as simple as pip install adbc-driver-flightsql pyarrow.

ADBC Java

The ADBC Java library has a Flight SQL driver, and is simple to use from Java. Installation requires a dependency on org.apache.arrow.adbc:adbc-driver-flight-sql.

Other ADBC clients

Any ADBC client that has a Flight SQL driver should work with Deephaven Flight SQL:

Flight SQL JDBC Driver

The Flight SQL JDBC Driver can be used directly from Java, or from other applications that support Java Database Connectivity (JDBC). When already working in the context of JDBC, the Flight SQL JDBC Driver can be used to access the Deephaven Flight SQL server. When the client is not required to use JDBC, it is advisable to use ADBC or the Flight SQL client directly.

Flight SQL Client (Java)

The Flight SQL Client can be used directly from Java. This is a good choice when the user needs explicit control over Flight SQL RPCs or needs direct access to Flight APIs.

Examples using PSK (pre-shared key) authentication

Each of the following examples demonstrates:

  1. Connecting to an insecure (w/o TLS) Deephaven Flight SQL server on localhost with port 10000.
  2. Authenticating with a Pre-shared Key (PSK). The PSK used in the examples is deephaven.
  3. Executing the SQL command SELECT 42 as Foo. Note, to run a more meaningful query, such as "SELECT * from StockQuotes", you need to have a table "StockQuotes" in the global query scope first.
  4. Fetching the query results.
  5. Printing out the results.

ADBC Python

The ADBC Python library has a Flight SQL driver, and is simple to use from Python. Installation is as simple as pip install adbc-driver-flightsql pyarrow.

Python Flight SQL Client

The Python Flight SQL client offers both a DB API 2 interface and an Arrow Flight interface for interacting with Flight SQL. To get started, install the client by running the following command:

This will set up the necessary environment to try out the example.

Tips

Try experimenting with other queries once you have these simple examples running. For example, create some named Deephaven tables on the server via the Web UI:

And execute the Flight SQL commands:

What's next

Open Database Connectivity (ODBC) support via Flight SQL is coming soon.