arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Querying Pinot

Learn how to query Pinot using SQL

hashtag
DIALECT

Pinot uses Calcite SQL Parser to parse queries and uses MYSQL_ANSI dialect. You can see the grammar herearrow-up-right.

hashtag
Limitations

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

No DDL support. Tables can be created via the .

hashtag
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

hashtag
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.

hashtag
Simple selection

hashtag
Aggregation

hashtag
Grouping on Aggregation

hashtag
Ordering on Aggregation

hashtag
Filtering

For performant filtering of ids in a list, see .

hashtag
Filtering with NULL predicate

hashtag
Selection (Projection)

hashtag
Ordering on Selection

hashtag
Pagination on Selection

Note: results might not be consistent if column ordered by has same value in multiple rows.

hashtag
Wild-card match (in WHERE clause only)

To count rows where the column airlineName starts with U

hashtag
Case-When Statement

Pinot supports the CASE-WHEN-ELSE statement.

Example 1:

Example 2:

hashtag
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

hashtag
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.

Engineering Full SQL support for Pinot at Uberarrow-up-right
REST APIarrow-up-right
Filtering with IdSetarrow-up-right
Transform Function in Aggregation Groupingarrow-up-right
//default to limit 10
SELECT * 
FROM myTable 

SELECT * 
FROM myTable 
LIMIT 100
SELECT COUNT(*), MAX(foo), SUM(bar) 
FROM myTable
SELECT MIN(foo), MAX(foo), SUM(foo), AVG(foo), bar, baz 
FROM myTable
GROUP BY bar, baz 
LIMIT 50
SELECT MIN(foo), MAX(foo), SUM(foo), AVG(foo), bar, baz 
FROM myTable
GROUP BY bar, baz 
ORDER BY bar, MAX(foo) DESC 
LIMIT 50
SELECT COUNT(*) 
FROM myTable
  WHERE foo = 'foo'
  AND bar BETWEEN 1 AND 20
  OR (baz < 42 AND quux IN ('hello', 'goodbye') AND quuux NOT IN (42, 69))
SELECT COUNT(*) 
FROM myTable
  WHERE foo IS NOT NULL
  AND foo = 'foo'
  AND bar BETWEEN 1 AND 20
  OR (baz < 42 AND quux IN ('hello', 'goodbye') AND quuux NOT IN (42, 69))
SELECT * 
FROM myTable
  WHERE quux < 5
  LIMIT 50
SELECT foo, bar 
FROM myTable
  WHERE baz > 20
  ORDER BY bar DESC
  LIMIT 100
SELECT foo, bar 
FROM myTable
  WHERE baz > 20
  ORDER BY bar DESC
  LIMIT 50, 100
SELECT COUNT(*) 
FROM myTable
  WHERE REGEXP_LIKE(airlineName, '^U.*')
  GROUP BY airlineName LIMIT 10
SELECT
    CASE
      WHEN price > 30 THEN 3
      WHEN price > 20 THEN 2
      WHEN price > 10 THEN 1
      ELSE 0
    END AS price_category
FROM myTable
SELECT
  SUM(
    CASE
      WHEN price > 30 THEN 30
      WHEN price > 20 THEN 20
      WHEN price > 10 THEN 10
      ELSE 0
    END) AS total_cost
FROM myTable
SELECT COUNT(*)
FROM myTable
GROUP BY DATETIMECONVERT(timeColumnName, '1:MILLISECONDS:EPOCH', '1:HOURS:EPOCH', '1:HOURS')
SELECT * 
FROM myTable
WHERE UID = 'c8b3bce0b378fc5ce8067fc271a34892'