-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multistage query engine (#32)
- Loading branch information
Showing
11 changed files
with
246 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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) | ||
} | ||
pinotClient.UseMultistageEngine(true) | ||
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 distinctCount(league) as unique_league_cnt 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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.