Golang
Pinot Client for Golang
Pinot also provides a native go client to query database directly from go application.

Installation

Please follow this Pinot Quickstart link to install and start Pinot batch QuickStart locally.
1
bin/quick-start-batch.sh
Copied!
Check out Client library Github Repo
1
git clone [email protected]:xiangfu0/pinot-client-go.git
2
cd pinot-client-go
Copied!
Build and run the example application to query from Pinot Batch Quickstart
1
go build ./examples/batch-quickstart
2
./batch-quickstart
Copied!

Usage

Create a Pinot Connection

Pinot client could be initialized through:

1. Zookeeper Path.

1
pinotClient := pinot.NewFromZookeeper([]string{"localhost:2123"}, "", "QuickStartCluster")
Copied!

2. A list of broker addresses.

1
pinotClient := pinot.NewFromBrokerList([]string{"localhost:8000"})
Copied!

3. ClientConfig

1
pinotClient := pinot.NewWithConfig(&pinot.ClientConfig{
2
ZkConfig: &pinot.ZookeeperConfig{
3
ZookeeperPath: zkPath,
4
PathPrefix: strings.Join([]string{zkPathPrefix, pinotCluster}, "/"),
5
SessionTimeoutSec: defaultZkSessionTimeoutSec,
6
},
7
ExtraHTTPHeader: map[string]string{
8
"extra-header":"value",
9
},
10
})
Copied!

Query Pinot

Please see this example for your reference.
Code snippet:
1
pinotClient, err := pinot.NewFromZookeeper([]string{"localhost:2123"}, "", "QuickStartCluster")
2
if err != nil {
3
log.Error(err)
4
}
5
brokerResp, err := pinotClient.ExecuteSQL("baseballStats", "select count(*) as cnt, sum(homeRuns) as sum_homeRuns from baseballStats group by teamID limit 10")
6
if err != nil {
7
log.Error(err)
8
}
9
log.Infof("Query Stats: response time - %d ms, scanned docs - %d, total docs - %d", brokerResp.TimeUsedMs, brokerResp.NumDocsScanned, brokerResp.TotalDocs)
Copied!

Response Format

Query Response is defined as the struct of following:
1
type BrokerResponse struct {
2
AggregationResults []*AggregationResult `json:"aggregationResults,omitempty"`
3
SelectionResults *SelectionResults `json:"SelectionResults,omitempty"`
4
ResultTable *ResultTable `json:"resultTable,omitempty"`
5
Exceptions []Exception `json:"exceptions"`
6
TraceInfo map[string]string `json:"traceInfo,omitempty"`
7
NumServersQueried int `json:"numServersQueried"`
8
NumServersResponded int `json:"numServersResponded"`
9
NumSegmentsQueried int `json:"numSegmentsQueried"`
10
NumSegmentsProcessed int `json:"numSegmentsProcessed"`
11
NumSegmentsMatched int `json:"numSegmentsMatched"`
12
NumConsumingSegmentsQueried int `json:"numConsumingSegmentsQueried"`
13
NumDocsScanned int64 `json:"numDocsScanned"`
14
NumEntriesScannedInFilter int64 `json:"numEntriesScannedInFilter"`
15
NumEntriesScannedPostFilter int64 `json:"numEntriesScannedPostFilter"`
16
NumGroupsLimitReached bool `json:"numGroupsLimitReached"`
17
TotalDocs int64 `json:"totalDocs"`
18
TimeUsedMs int `json:"timeUsedMs"`
19
MinConsumingFreshnessTimeMs int64 `json:"minConsumingFreshnessTimeMs"`
20
}
Copied!
Note that AggregationResults and SelectionResults are holders for PQL queries.
Meanwhile ResultTable is the holder for SQL queries. ResultTable is defined as:
1
// ResultTable is a ResultTable
2
type ResultTable struct {
3
DataSchema RespSchema `json:"dataSchema"`
4
Rows [][]interface{} `json:"rows"`
5
}
Copied!
RespSchema is defined as:
1
// RespSchema is response schema
2
type RespSchema struct {
3
ColumnDataTypes []string `json:"columnDataTypes"`
4
ColumnNames []string `json:"columnNames"`
5
}
Copied!
There are multiple functions defined for ResultTable, like:
1
func (r ResultTable) GetRowCount() int
2
func (r ResultTable) GetColumnCount() int
3
func (r ResultTable) GetColumnName(columnIndex int) string
4
func (r ResultTable) GetColumnDataType(columnIndex int) string
5
func (r ResultTable) Get(rowIndex int, columnIndex int) interface{}
6
func (r ResultTable) GetString(rowIndex int, columnIndex int) string
7
func (r ResultTable) GetInt(rowIndex int, columnIndex int) int
8
func (r ResultTable) GetLong(rowIndex int, columnIndex int) int64
9
func (r ResultTable) GetFloat(rowIndex int, columnIndex int) float32
10
func (r ResultTable) GetDouble(rowIndex int, columnIndex int) float64
Copied!
Sample Usage is here
1
// Print Response Schema
2
for c := 0; c < brokerResp.ResultTable.GetColumnCount(); c++ {
3
fmt.Printf("%s(%s)\t", brokerResp.ResultTable.GetColumnName(c), brokerResp.ResultTable.GetColumnDataType(c))
4
}
5
fmt.Println()
6
7
// Print Row Table
8
for r := 0; r < brokerResp.ResultTable.GetRowCount(); r++ {
9
for c := 0; c < brokerResp.ResultTable.GetColumnCount(); c++ {
10
fmt.Printf("%v\t", brokerResp.ResultTable.Get(r, c))
11
}
12
fmt.Println()
13
}
Copied!
Last modified 5mo ago