Skip to content

Commit

Permalink
Adding json batch quickstart example
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangfu0 committed Feb 27, 2022
1 parent ebfadb4 commit 6db3ab5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ go build ./examples/batch-quickstart
./batch-quickstart
```

## Pinot Json Index QuickStart

Please follow this [Pinot Quickstart](https://docs.pinot.apache.org/basics/getting-started/running-pinot-locally) link to install and start Pinot json batch quickstart locally.

```
bin/quick-start-json-index-batch.sh
```

Check out Client library Github Repo

```
git clone [email protected]:startreedata/pinot-client-go.git
cd pinot-client-go
```

Build and run the example application to query from Pinot Json Batch Quickstart

```
go build ./examples/json-batch-quickstart
./json-batch-quickstart
```

## Pinot Live Demo cluster

Build and run the example application to query from Pinot Batch Quickstart
Expand Down
59 changes: 59 additions & 0 deletions examples/json-batch-quickstart/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 := "githubEvents"
pinotQueries := []string{
"SELECT * FROM githubEvents LIMIT 5",
"SELECT created_at_timestamp FROM githubEvents LIMIT 5",
"select json_extract_scalar(repo, '$.name', 'STRING'), count(*) from githubEvents where json_match(actor, '\"$.login\"=''LombiqBot''') group by 1 order by 2 desc 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
}
}

0 comments on commit 6db3ab5

Please sign in to comment.