# Querying Pinot

## REST API on the Broker

Pinot can be queried via a broker endpoint as follows. This example assumes broker is running on `localhost:8099`

{% tabs %}
{% tab title="Standard-SQL endpoint" %}
The Pinot REST API can be accessed by invoking `POST` operation with a JSON body containing the parameter `sql` to the `/query/sql` endpoint on a broker.

```java
$ curl -H "Content-Type: application/json" -X POST \
   -d '{"sql":"select foo, count(*) from myTable group by foo limit 100"}' \
   http://localhost:8099/query/sql
```

{% endtab %}

{% tab title="PQL endpoint" %}
{% hint style="warning" %}
Note

This endpoint is deprecated, and will soon be removed. The standard-SQL endpoint is the recommended endpoint.
{% endhint %}

The PQL endpoint can be accessed by invoking `POST` operation with a JSON body containing the parameter `pql` to the `/query` endpoint on a broker.

```java
$ curl -H "Content-Type: application/json" -X POST \
   -d '{"pql":"select count(*) from myTable group by foo top 100"}' \
   http://localhost:8099/query
```

{% endtab %}
{% endtabs %}

## Query Console

Query Console can be used for running ad-hoc queries (checkbox available to query the PQL endpoint). The Query Console can be accessed by entering the `<controller host>:<controller port>` in your browser

![Pinot Query Console](https://2688850955-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtH6nl58DdnZnelPdTc%2F-M-Hx0GdmnEIx4mJEk-e%2F-M-Hzh8tO4Nr5Rk0uZIB%2Fimage.png?alt=media\&token=ac17a88d-cd2e-415b-beb5-58a5dab41fdf)

## pinot-admin

You can also query using the `pinot-admin` scripts. Make sure you follow instructions in [Getting Pinot](https://docs.pinot.apache.org/release-0.4.0/basics/getting-started/running-pinot-locally#getting-pinot) to get Pinot locally, and then

```bash
cd incubator-pinot/pinot-tools/target/pinot-tools-pkg 
bin/pinot-admin.sh PostQuery \
  -queryType sql \
  -brokerPort 8000 \
  -query "select count(*) from baseballStats"
2020/03/04 12:46:33.459 INFO [PostQueryCommand] [main] Executing command: PostQuery -brokerHost localhost -brokerPort 8000 -queryType sql -query select count(*) from baseballStats
2020/03/04 12:46:33.854 INFO [PostQueryCommand] [main] Result: {"resultTable":{"dataSchema":{"columnDataTypes":["LONG"],"columnNames":["count(*)"]},"rows":[[97889]]},"exceptions":[],"numServersQueried":1,"numServersResponded":1,"numSegmentsQueried":1,"numSegmentsProcessed":1,"numSegmentsMatched":1,"numConsumingSegmentsQueried":0,"numDocsScanned":97889,"numEntriesScannedInFilter":0,"numEntriesScannedPostFilter":0,"numGroupsLimitReached":false,"totalDocs":97889,"timeUsedMs":185,"segmentStatistics":[],"traceInfo":{},"minConsumingFreshnessTimeMs":0}
```

## Pinot Clients

Here's a list of the clients available to query Pinot from your application

1. [Java Client](https://docs.pinot.apache.org/users/clients/java)
2. Coming soon - JDBC client
3. [Golang Client](https://docs.pinot.apache.org/release-0.4.0/clients/golang#pinot-client-go)
