Connecting to StarTree Cloud via Java
Pinot provides a native Java client to execute queries on the cluster. The client is tenant-aware, and able to direct queries to the correct broker.
Prerequisite
You can use the client by installing and including Maven
or Gradle
.
For information on how to install Maven, visit Installing Apache Maven.
Example of how to including the Maven dependency to use the client:
For information on how to install Gradle, visit Gradle Build Tool Installation.
Example of how to including the Gradle dependency to use the client:
Usage
Here’s an example of how to use the pinot-java-client
to query Pinot.
Connection Factory
The client provides a ConnectionFactory
class to create connections to a Pinot cluster. To create a connection, include a comma-separated list of the brokers in the cluster. For example, ("broker-1:1234", "broker-2:1234", ...);
Query methods
Query using one of the following methods:
- For blocking queries, use the following request format:
Connection.execute(org.apache.pinot.client.Request)
- For asynchronous queries that return a future object, use the following request format:
Connection.executeAsync(org.apache.pinot.client.Request)
To escape query parameters, you can use the PreparedStatement
(which isn’t stored, so won’t decrease the subsequent query performance).
Result set
Access results using various get
methods on the first ResultSet
with the getResultSet(int)
method.
Authentication
Pinot supports basic HTTP authorization, which can be enabled for your cluster using configuration. To support basic HTTP authorization in your client-side Java applications, make sure you are using Pinot Java Client 0.10.0+ or building from the latest Pinot snapshot. The following code snippet shows you how to connect to and query a Pinot cluster that has basic HTTP authorization enabled when using the Java client.
Configuring client time-out
The following timeouts can be set:
- brokerConnectTimeoutMs (default 2000)
- brokerReadTimeoutMs (default 60000)
- brokerHandshakeTimeoutMs (default 2000)
- controllerConnectTimeoutMs (default 2000)
- controllerReadTimeoutMs (default 60000)
- controllerHandshakeTimeoutMs (default 2000)
Timeouts for the Java connector can be added as a connection properties. The following example configures a very low timeout of 10ms:
Obtaining Username and Password
You can cenerate an API token in the Data Portal or using the REST API. Then, obtain the username and password from the service token
Th username and password are used to authorize your API requests.
Finding Your Broker URL
To find the correct Broker URL for your table in StarTree Cloud:
- Access the Data Portal.
- Click on Tables.
- Select the specific table you want to query.
- From the browser address bar, copy the URL to your Pinot cluster. For example, if the URL shown is
https://dp.1abcde6.cp.s7e.startree.cloud/tables
, then the Broker URL for the table will bebroker.pinot.1abcde6.cp.s7e.startree.cloud
.