Pinot Client for Golang
Pinot provides a native Go client to query the database directly from Go application.
Follow this Pinot quickstart link to install and start Pinot locally.
Check out the client library GitHub repository.
Build and run the example application to query from the Pinot batch quickstart.
Initialize the Pinot client using one of the methods below.
The Go client repository contains an example script.
Note: You need not configure “content-type”
as a header in ExtraHTTPHeader
.
If you require a specialized HTTP client, you have the option to create your own HTTP client and utilize the NewWithConfigAndClient
function to establish a Pinot client that can accommodate a custom HTTP client.
The Go client repository contains an example script.
The Go client repository contains an example script.
Code snippet:
The query response has the following format:
Note that AggregationResults
and SelectionResults
are holders for Pinot query language (PQL) queries.
Meanwhile, ResultTable
is the holder for SQL queries. ResultTable
is defined as:
RespSchema
is defined as:
There are multiple functions defined for ResultTable
, such as the following:
See an example of a function in use here and below:
Pinot offers standard JDBC interface to query the database. This makes it easier to integrate Pinot with other applications such as Tableau.
You can include the JDBC dependency in your code as follows -
You can also compile the JDBC code into a JAR and place the JAR in the Drivers directory of your application.
There is no need to register the driver manually as it will automatically register itself at the startup of the application.
Here's an example of how to use the pinot-jdbc-client
for querying. The client only requires the controller URL.
You can also use PreparedStatements. The placeholder parameters are represented using ?
** (question mark) symbol.
Pinot supports basic HTTP authorization, which can be enabled for your cluster using configuration. To support basic HTTP authorization in your client-side JDBC applications, make sure you are using Pinot JDBC 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 JDBC client.
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 JDBC connector can be added as a parameter to the JDBC Connection URL. The following example enables https and configures a very low timeout of 10ms:
The JDBC client doesn't support INSERT
, DELETE
or UPDATE
statements due to the database limitations. You can only use the client to query the database.
The driver is also not completely ANSI SQL 92 compliant.
If you want to use JDBC driver to integrate Pinot with other applications, do make sure to check JDBC ConnectionMetadata in your code. This will help in determining which features cannot be supported by Pinot since it is an OLAP database.
A lot of times the user wants to query data from an external application instead of using the built-in query explorer. Pinot provides external query client for this purpose. All of the clients have pretty standard interfaces so that the learning curve is minimum.
Currently Pinot provides the following clients
Pinot provides a native java client to execute queries on the cluster. The client makes it easier for user to query data. The client is also tenant-aware and thus is able to redirect the queries to the correct broker.
You can use the client by including the following dependency -
You can also build locally and use it.
Basic authorization for the JDBC client is not supported in Pinot JDBC 0.9.3 release or earlier. The JDBC client has been upgraded to support basic authentication in the Pinot 0.10.0 snapshot, which can currently be built from source.
You will not need to update your Pinot cluster to 0.10.0+ to support basic authentication, only the JDBC and Java client JARs.
Here's an example of how to use the pinot-java-client
to query Pinot.
The client provides a ConnectionFactory
class to create connections to a Pinot cluster. The factory supports the following methods to create a connection -
Zookeeper (Recommended) - Comma-separated list of zookeeper of the cluster. This is the recommended method which can redirect queries to appropriate brokers based on tenant/table.
Broker list - Comma separated list of the brokers in the cluster. This should only be used in standalone setups or for POC, unless you have a load balancer setup for brokers.
Controller URL - (v 0.11.0+) Controller URL. This will use periodic controller API calls to keep the table level broker list updated (hence there might be delay b/w the broker mapping changing and the client state getting updated).
Properties file - You can also put the broker list as brokerList
in a properties file and provide the path to that file to the factory. This should only be used in standalone setups or for POC, unless you have a load balancer setup for brokers.
If your Pinot cluster is running inside Kubernetes and you're trying to connect to it from outside Kubernetes, the Zookeeper method will probably return internal host names that can't be resolved. For Kubernetes deployments, it's therefore recommended to pass in the host-name of a load balancer sitting in front of the brokers.
Here's an example demonstrating all methods of Connection factory -
You can run the query in both blocking as well as async manner. Use
Connection.execute(org.apache.pinot.client.Request)
for blocking queries
Connection.executeAsync(org.apache.pinot.client.Request)
for asynchronous queries that return a future object.
You can also use PreparedStatement
to escape query parameters. We don't store the Prepared Statement in the database and hence it won't increase the subsequent query performance.
Results can be obtained with the various get methods in the first ResultSet, obtained through the getResultSet(int)
method:
If queryFormat pql
is used in the Request
, there are some differences in how the results can be accessed, depending on the query.
In the case of aggregation, each aggregation function is within its own ResultSet. A query with multiple aggregation function will return one result set per aggregation function, as they are computed in parallel.
In case of aggregation with GROUP BY
, there will be as many ResultSets as the number of aggregations, each of which will contain multiple results grouped by a grouping key.
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:
Applications can use this python client library to query Apache Pinot.
Pypi Repo:
Source Code Repo:
Note:
pinotdb version >= 0.3.2 uses the Pinot SQL API (added in Pinot >= 0.3.0) and drops support for PQL API. So this client requires Pinot server version >= 0.3.0 in order to access Pinot.
pinotdb version in 0.2.x uses the Pinot PQL API, which works with pinot version <= 0.3.0, but may miss some new SQL query features added in newer Pinot version.
The db engine connection string is formated like this: pinot://:?controller=://:/
Run below command to start Pinot Batch Quickstart in docker and expose Pinot controller port 9000 and Pinot broker port 8000.
Once pinot batch quickstart is up, you can run the sample code snippet to query Pinot:
Sample Output:
Using parameters:
Run the command below to start Pinot Hybrid Quickstart in docker and expose Pinot controller port 9000 and Pinot broker port 8000.
Below is an example to query against Pinot Quickstart Hybrid:
This section is only applicable for PQL endpoint, which is deprecated and will be deleted soon. For more information about the endpoints, visit .
Pinot supports , 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 bas