Skip to content

Commit 7174e2b

Browse files
authored
Don't panic on empty var Druid query (#123)
1 parent 0b38b01 commit 7174e2b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pkg/tsdb/druid/column_type.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
)
88

99
func detectColumnType(c *responseColumn, pos int, rows [][]interface{}) {
10+
if len(rows) == 0 {
11+
c.Type = ColumnString
12+
return
13+
}
1014
t := map[columnType]int{"nil": 0}
1115
maxRowsToScan := (len(rows) / 5) + 1
1216
for _, row := range rows[:maxRowsToScan] {

pkg/tsdb/druid/druid.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,11 @@ func (ds *Service) oldExecuteQuery(queryRef string, q druidquerybuilder.Query, s
608608
err := json.Unmarshal(res, &tn)
609609
if err == nil && len(tn) > 0 {
610610
columns := []string{"timestamp"}
611-
for c := range tn[0]["result"].([]interface{})[0].(map[string]interface{}) {
612-
columns = append(columns, c)
611+
results := tn[0]["result"].([]interface{})
612+
if len(results) > 0 {
613+
for c := range results[0].(map[string]interface{}) {
614+
columns = append(columns, c)
615+
}
613616
}
614617
for _, result := range tn {
615618
for _, record := range result["result"].([]interface{}) {

0 commit comments

Comments
 (0)