JDBC
Pinot offers standard JDBC interface to query the database. This makes it easier to integrate Pinot with other applications such as Tableau.

Installation

You can include the JDBC dependency in your code as follows -
Maven
Gradle
1
<dependency>
2
<groupId>org.apache.pinot</groupId>
3
<artifactId>pinot-jdbc-client</artifactId>
4
<version>0.6.0</version>
5
</dependency>
Copied!
1
include 'org.apache.pinot:pinot-jdbc-client:0.5.0'
Copied!
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.

Usage

Here's an example of how to use the pinot-jdbc-client for querying. The client only requires the controller URL.
1
public static final String DB_URL = "jdbc:pinot://localhost:9000"
2
DriverManager.registerDriver(new PinotDriver());
3
Connection conn = DriverManager.getConnection(DB_URL);
4
Statement statement = conn.createStatement();
5
Integer limitResults = 10;
6
ResultSet rs = statement.executeQuery(String.format("SELECT UPPER(playerName) AS name FROM baseballStats LIMIT %d", limitResults));
7
Set<String> results = new HashSet<>();
8
9
while(rs.next()){
10
String playerName = rs.getString("name");
11
results.add(playerName);
12
}
13
14
conn.close();
Copied!
You can also use PreparedStatements. The placeholder parameters are represented using ? ** (question mark) symbol.
1
Connection conn = DriverManager.getConnection(DB_URL);
2
PreparedStatement statement = conn.prepareStatement("SELECT UPPER(playerName) AS name FROM baseballStats WHERE age = ?");
3
statement.setInt(1, 20);
4
5
ResultSet rs = statement.executeQuery();
6
Set<String> results = new HashSet<>();
7
8
while(rs.next()){
9
String playerName = rs.getString("name");
10
results.add(playerName);
11
}
12
13
conn.close();
Copied!

Limitation

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.
Last modified 1mo ago