Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"reflect"
"time"

"cloud.google.com/go/firestore"
Expand Down Expand Up @@ -89,6 +90,26 @@ func (d *Datasource) query(ctx context.Context, pCtx backend.PluginContext, quer
return response
}

func convertInt32To64(ar []int32) []float64 {
newar := make([]float64, len(ar))
var v int32
var i int
for i, v = range ar {
newar[i] = float64(v)
}
return newar
}

func convertInt64To64(ar []int64) []float64 {
newar := make([]float64, len(ar))
var v int64
var i int
for i, v = range ar {
newar[i] = float64(v)
}
return newar
}

func (d *Datasource) queryInternal(ctx context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse {
var response backend.DataResponse

Expand Down Expand Up @@ -149,24 +170,45 @@ func (d *Datasource) queryInternal(ctx context.Context, pCtx backend.PluginConte
if values == nil {
values = []int32{}
}
values = append(values.([]int32), int32(val.(int)))
if reflect.TypeOf(values).Elem().Kind() == reflect.Float64 {
values = append(values.([]float64), val.(float64))
} else {
values = append(values.([]int32), int32(val.(int)))
}
break
case int32:
if values == nil {
values = []int32{}
}
values = append(values.([]int32), val.(int32))
if reflect.TypeOf(values).Elem().Kind() == reflect.Float64 {
values = append(values.([]float64), val.(float64))
} else {
values = append(values.([]int32), val.(int32))
}
break
case int64:
if values == nil {
values = []int64{}
}
values = append(values.([]int64), val.(int64))
if reflect.TypeOf(values).Elem().Kind() == reflect.Float64 {
values = append(values.([]float64), val.(float64))
} else {
values = append(values.([]int64), val.(int64))
}
break
case float64:
if values == nil {
values = []float64{}
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Int {
values = convertInt32To64(values.([]int32))
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Int32 {
values = convertInt32To64(values.([]int32))
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Int64 {
values = convertInt64To64(values.([]int64))
}
values = append(values.([]float64), val.(float64))
break
case time.Time:
Expand All @@ -190,6 +232,20 @@ func (d *Datasource) queryInternal(ctx context.Context, pCtx backend.PluginConte
if values == nil {
values = []string{}
}
if val == nil {
if reflect.TypeOf(values).Elem().Kind() == reflect.Int {
values = append(values.([]int32), 0)
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Int32 {
values = append(values.([]int32), 0)
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Int64 {
values = append(values.([]int64), 0)
}
if reflect.TypeOf(values).Elem().Kind() == reflect.Float64 {
values = append(values.([]float64), 0.0)
}
}
values = append(values.([]string), fmt.Sprintf("%v", val))
}
}
Expand Down