githubEdit

Querying Pinot

A practical entry point for querying Pinot.

Pinot queries run through the broker and are written in SQL. This page is the wayfinding layer for people who want to query data, understand which engine to use, and know where to look when a query needs tuning.

How to start

  1. Write the query in Pinot SQL.

  2. Decide whether the single-stage engine is enough or whether you need multi-stage features such as joins and subqueries.

  3. Use query options to control runtime behavior.

  4. Inspect the plan or result shape when you need to debug performance.

SET useMultistageEngine = true;
SELECT city, COUNT(*)
FROM stores
GROUP BY city
LIMIT 10;

What matters most

Pinot SQL uses the Apache Calcite parser with the MYSQL_ANSI dialect. In practice, that means you should pay attention to identifier quoting, literal quoting, and engine-specific capabilities.

If you are debugging a slow or surprising query, the most useful follow-up pages are:

When to use which engine

Single-stage execution is the default path for straightforward filtering, aggregation, and top-K style queries.

Use multi-stage execution when you need features that are not available in single-stage mode, such as:

  • joins

  • subqueries

  • window functions

  • more complex distributed query shapes

As a rule of thumb: use SSE for simple filtering, aggregation, and top-K queries; use MSE when your query shape requires joins, subqueries, window functions, or other advanced relational operators. For a detailed comparison, see SSE vs MSE.

Next step

Read SQL syntax for the query language itself, then move to Query options or Explain plan when you need control or diagnostics.

Identifier vs Literal

In Pinot SQL:

  • Double quotes(") are used to force string identifiers, e.g. column names

  • Single quotes(') are used to enclose string literals. If the string literal also contains a single quote, escape this with a single quote e.g '''Pinot''' to match the string literal 'Pinot'

Misusing those might cause unexpected query results, like the following examples:

  • WHERE a='b' means the predicate on the column a equals to a string literal value 'b'

  • WHERE a="b" means the predicate on the column a equals to the value of the column b

If your column names use reserved keywords (e.g. timestamp or date) or special characters, you will need to use double quotes when referring to them in queries.

Note: Define decimal literals within quotes to preserve precision.

Example Queries

Selection

Aggregation

Grouping on Aggregation

Ordering on Aggregation

Filtering

For performant filtering of IDs in a list, see Filtering with IdSet.

Filtering with NULL predicate

Selection (Projection)

Ordering on Selection

Pagination on Selection

Note that results might not be consistent if the ORDER BY column has the same value in multiple rows.

Wild-card match (in WHERE clause only)

The example below counts rows where the column airlineName starts with U:

Note: REGEXP_LIKE also supports case insensitive search using the i flag as the third parameter.

Case-When Statement

Pinot supports the CASE-WHEN-ELSE statement, as shown in the following two examples:

UDF

Pinot doesn't currently support injecting functions. Functions have to be implemented within Pinot, as shown below:

For more examples, see Transform Function in Aggregation Grouping.

BYTES column

Pinot supports queries on BYTES column using hex strings. The query response also uses hex strings to represent bytes values.

The query below fetches all the rows for a given UID:

Last updated

Was this helpful?