Skip to content

Commit

Permalink
Fix error when first time chunk in topN is empty (#158)
Browse files Browse the repository at this point in the history
* Fix error when first time chunk in topN is empty

* Add if block in case of type mismatch to avoid kernel panic
  • Loading branch information
WilliamRoyNelson authored Jan 31, 2024
1 parent 34c0579 commit 4500682
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/druid.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,25 @@ func (ds *druidDatasource) executeQuery(queryRef string, q druidquerybuilder.Que
case "topN":
var tn []map[string]interface{}
err := json.Unmarshal(result, &tn)
if err == nil && len(tn) > 0 && len(tn[0]["result"].([]interface{})) > 0 {
columns := []string{"timestamp"}
for c := range tn[0]["result"].([]interface{})[0].(map[string]interface{}) {
columns = append(columns, c)
}
if err == nil && len(tn) > 0 {
var columns []string
for _, result := range tn {
if columns == nil && len(result["result"].([]interface{})) > 0 {
columns = append(columns, "timestamp")
for c := range result["result"].([]interface{})[0].(map[string]interface{}) {
columns = append(columns, c)
}
}
for _, record := range result["result"].([]interface{}) {
var row []interface{}
row = append(row, result["timestamp"])
o := record.(map[string]interface{})
for _, c := range columns[1:] {
row = append(row, o[c])
o, ok := record.(map[string]interface{})
if ok {
for _, c := range columns[1:] {
row = append(row, o[c])
}
r.Rows = append(r.Rows, row)
}
r.Rows = append(r.Rows, row)
}
}
for i, c := range columns {
Expand Down

0 comments on commit 4500682

Please sign in to comment.