-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
71 lines (65 loc) · 2.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"encoding/json"
"fmt"
pinot "github.com/startreedata/pinot-client-go/pinot"
log "github.com/sirupsen/logrus"
)
func main() {
pinotClient, err := pinot.NewFromZookeeper([]string{"localhost:2123"}, "", "QuickStartCluster")
if err != nil {
log.Error(err)
}
table := "baseballStats"
pinotQueries := []string{
"select * from baseballStats limit 10",
"select count(*) as cnt from baseballStats limit 1",
"select count(*) as cnt, sum(homeRuns) as sum_homeRuns from baseballStats limit 1",
"select teamID, count(*) as cnt, sum(homeRuns) as sum_homeRuns from baseballStats group by teamID limit 10",
"select max(league) from baseballStats limit 10",
}
log.Infof("Querying SQL")
for _, query := range pinotQueries {
log.Infof("Trying to query Pinot: %v", query)
brokerResp, err := pinotClient.ExecuteSQL(table, query)
if err != nil {
log.Error(err)
}
printBrokerResp(brokerResp)
}
}
func printBrokerResp(brokerResp *pinot.BrokerResponse) {
log.Infof("Query Stats: response time - %d ms, scanned docs - %d, total docs - %d", brokerResp.TimeUsedMs, brokerResp.NumDocsScanned, brokerResp.TotalDocs)
if brokerResp.Exceptions != nil && len(brokerResp.Exceptions) > 0 {
jsonBytes, _ := json.Marshal(brokerResp.Exceptions)
log.Infof("brokerResp.Exceptions:\n%s\n", jsonBytes)
return
}
if brokerResp.ResultTable != nil {
jsonBytes, _ := json.Marshal(brokerResp.ResultTable)
log.Infof("brokerResp.ResultTable:\n%s\n", jsonBytes)
line := ""
for c := 0; c < brokerResp.ResultTable.GetColumnCount(); c++ {
line += fmt.Sprintf("%s(%s)\t", brokerResp.ResultTable.GetColumnName(c), brokerResp.ResultTable.GetColumnDataType(c))
}
line += "\n"
for r := 0; r < brokerResp.ResultTable.GetRowCount(); r++ {
for c := 0; c < brokerResp.ResultTable.GetColumnCount(); c++ {
line += fmt.Sprintf("%v\t", brokerResp.ResultTable.Get(r, c))
}
line += "\n"
}
log.Infof("ResultTable:\n%s", line)
return
}
if brokerResp.AggregationResults != nil {
jsonBytes, _ := json.Marshal(brokerResp.AggregationResults)
log.Infof("brokerResp.AggregationResults:\n%s\n", jsonBytes)
return
}
if brokerResp.SelectionResults != nil {
jsonBytes, _ := json.Marshal(brokerResp.SelectionResults)
log.Infof("brokerResp.SelectionResults:\n%s\n", jsonBytes)
return
}
}