Skip to content

kdb Insights Java SDK Query API

The Java SDK includes a Query API that allows you to extract data from kdb Insights Enterprise over IPC. You can download it from the kdb Insights Nexus registry.

The primary class used for querying data from the kdb Insights Enterprise is the DataAccessClient class.

Below is a description of the methods available in the DataAccessClient class:

Constructors

DataAccessClient()

If you use this constructor, the components are built using data from environment variables that must be supplied to the process that is using the SDK.

Sample

import kx.insights.dataaccess.DataAccessClient;
...
DataAccessClient dac = new DataAccessClient();

DataAccessClient(HttpsConfigRequestor configRequestor, SSLContextManager sslManager, QConnectionFactory qConnectionFactory, DataAccessTokenFactory credentialsFactory)

With this constructor you must supply all of the dependencies of the DataAccessClient.

Sample

import kx.insights.dataaccess.DataAccessClient;
import kx.insights.dataaccess.DataAccessTokenFactory;
...
String configUrl = "$KXI_CONFIG_URL";
HttpsConfigRequestor configRequestor = new HttpsConfigRequestor(configUrl);
SSLContextManager sslManager = new SSLContextManager();
QConnectionFactory qConnectionFactory = new QConnectionFactory();
InsightsDataAccessTokenFactory credFactory = new InsightsDataAccessTokenFactory(configUrl);
credFactory.setClientIdAndSecret(clientId, clientSecret);
DataAccessClient dac = new DataAccessClient(configRequestor, sslManager, qConnectionFactory, credFactory);

connect

DataAccessClient.connect()

This is called to establish a connection to the kdb Insights Enterprise.

Note

It must be called before any requests can be called. Calling these methods before calling connect() results in an exception being thrown.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();

getMeta

DataAccessClient.getMeta()

This returns the result of the getMeta() call. This is returned as an object, and will need to be parsed by the caller. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
dac.getMeta();

getData

DataAccessClient.getData(String table, Timestamp startTS, Timestamp endTS)

Returns the result of the getData call on the specified table for the specified time range. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
Timestamp oneHourAgo = new Timestamp(System.currenttimemillis() - 3600000);
Timestamp now = new Timestamp(System.currenttimemillis());
Object result = dac.getData("trace", oneHourAgo, now);

DataAccessClient.getData(Map argsMap)

Returns the result of the getData call on the specified parameters. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
HashMap<String, Object> getDataArgs = new HashMap();
getDataArgs.put("startTS", startTime);
getDataArgs.put("endTS", endTime);
getDataArgs.put("table", "trace");
Object result = dac.getData(getDataArgs);

ping

DataAccessClient.ping()

Runs the ping command. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
boolean pingResult = dac.ping(); //Should always be true

isConnected

DataAccessClient.isConnected()

Returns true if the client is connected. Otherwise returns false.

Sample

DataAccessClient dac = new DataAccessClient();
...
if(!dac.isConnected())
{
    dac.connect();
}

Environment variables

These are the environment variables that are used by the basic form of the DataAccessClient() constructor.

variable required details
KXI_CONFIG_URL Mandatory Authenticated SDK client URL
KXI_QUERY_USER Conditional The Keycloak client that is used to generate bearer tokens to log in for query. Must be set if KXI_QUERY_TOKEN is not.
KXI_QUERY_SECRET Conditional The Keycloak client secret that is used to generate bearer tokens for query. Must be set if KXI_QUERY_TOKEN is not.
KXI_QUERY_TOKEN Conditional A bearer token used for authentication when making queries. If this is set, then KXI_QUERY_USER and KXI_QUERY_SECRET are ignored.