Querying Pinot

Learn how to query Pinot using SQL

DIALECT

Pinot uses Calcite SQL Parser to parse queries and uses MYSQL_ANSI dialect. You can see the grammar here.

Limitations

Pinot does not support Joins or nested Subqueries and we recommend using Presto for queries that span multiple tables. Read Engineering Full SQL support for Pinot at Uber for more info.

No DDL support. Tables can be created via the REST API.

Identifier vs Literal

In Pinot SQL:

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

  • Single quotes(') are used to enclose string literals.

Mis-using those might cause unexpected query results:

E.g.

  • 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

Example Queries

  • Use single quotes for literals and double quotes (optional) for identifiers (column names)

  • If you name the columns as timestamp, date, or other reserved keywords, or the column name includes special characters, you need to use double quotes when you refer to them in the query.

Simple 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: results might not be consistent if column ordered by has same value in multiple rows.

Wild-card match (in WHERE clause only)

To count rows where the column airlineName starts with U

Case-When Statement

Pinot supports the CASE-WHEN-ELSE statement.

Example 1:

Example 2:

UDF

Functions have to be implemented within Pinot. Injecting functions is not yet supported. The example below demonstrate the use of UDFs. More examples in Transform Function in Aggregation Grouping

BYTES column

Pinot supports queries on BYTES column using HEX string. The query response also uses hex string to represent bytes value.

E.g. the query below fetches all the rows for a given UID.

Last updated

Was this helpful?