Develop a C++ Client Query

This section of the crash course covers Deephaven Enterprise's client APIs. This guide discusses the C++ client, which allows you to:

  • Create new workers
  • Connect to existing Persistent Queries (PQs)
  • Run queries server-side
  • Fetch and interact with tables
  • And more!

The Enterprise C++ client is built on top of the Community C++ client, giving you access to its rich feature set.

Installation

The C++ client requires building from source. Contact your Deephaven representative to obtain the C++ client source bundle (dhe-cpp-src-<version>.tgz). Ensure the version matches your Deephaven Enterprise server.

Supported operating systems

You can build and use the C++ client with:

  • Ubuntu 22.04 or 24.04
  • RHEL 9

Build the client

The source bundle includes a Dockerized build script. Prerequisites:

  • Docker with buildx installed
  • Root access (or Docker configured for non-root users)

Unpack the source bundle and build:

Install the build bundle

Unpack the generated bundle to your filesystem:

Set up the environment

Before using the C++ client, source the environment script:

For detailed installation instructions, see the C++ client installation guide.

Create a session

The first step when using the C++ client is to create a SessionManager. A SessionManager manages connections to the Deephaven Enterprise Controller and Authentication services. It requires a URL to the server's connection.json file.

Note

This example uses port 8000. Your server may use a different port. Typically, the port is 8123 for servers without Envoy and 8000 for servers with Envoy.

The descriptive_name helps identify your client in server logs. Including the thread ID (via GetTidAsString()) makes it easier to trace operations.

To compile this program, use a command like:

Authenticate

Once a SessionManager is created, authenticate with the server. You can use either password authentication or private key authentication:

Note

The third argument to PasswordAuthentication is the operate_as parameter. Under normal circumstances, pass the same value as the username.

Use the client

Connect to an existing PQ

To connect to a running PQ, use either its name or serial number:

Create a new temporary PQ

To create a new temporary worker, use a PqConfigBuilder:

Run queries and fetch tables

To interact with tables, create a DndTableHandleManager from the DndClient:

Note

The script language must match the PQ's configuration. Use PqConfigBuilder::SetScriptLanguage when creating a new PQ, passing either "groovy" or "python".

Close connections

When finished, close the DndClient and SessionManager objects to release resources:

Caution

Once Close() is called, any subsequent operation on that object results in an error.

Objects are also automatically closed when destroyed, but explicitly closing them ensures prompt resource cleanup.

Complete example

Here's a complete example that connects to a server, creates a temporary PQ, runs a query, and prints the result:

To compile this program, use a command like:

Debugging tips

If you experience connectivity issues, the client may appear to hang for up to 2 minutes (the default gRPC timeout) before reporting an error.

To debug network issues, set the GRPC_VERBOSITY environment variable:

This logs gRPC connection details, including SSL authentication and certificate validation.