func (d *DummyIn) GetFieldRangeByName(name string, start time.Time, end time.Time) ([]common.Field, error) { var err error var startField common.Field var midField common.Field var endField common.Field startTs := start.UnixNano() endTs := end.UnixNano() if startTs-endTs < 10 || endTs-startTs < 10 { } startField.Name = name startField.Tags = make(map[string]string) startField.Values = make(map[string]interface{}) startField.Values[`time`] = startTs // same TS, emit only one record if startTs == endTs { return []common.Field{startField}, err } endField.Name = name endField.Tags = make(map[string]string) endField.Values = make(map[string]interface{}) endField.Values[`time`] = endTs // very small spread, emit only start and end if startTs-endTs < time.Second.Nanoseconds() || endTs-startTs < time.Second.Nanoseconds() { return []common.Field{startField, endField}, err } midField.Name = name midField.Tags = make(map[string]string) midField.Values = make(map[string]interface{}) midField.Values[`time`] = (startTs + endTs) / 2 return []common.Field{startField, midField, endField}, err }
func (influx *Influx09Input) GetFieldRangeByName(name string, start time.Time, end time.Time) ([]common.Field, error) { var datapoints []common.Field var err error q := client.NewQuery( fmt.Sprintf(`SELECT * FROM "%s" WHERE time > %d AND time < %d`, name, start.UnixNano(), end.UnixNano()), influx.Db, `ns`, ) res, err := influx.Client.Query(q) if res.Error() != nil { err = res.Error() return datapoints, err } for _, result := range res.Results { for _, ser := range result.Series { columns := ser.Columns for _, value := range ser.Values { var f common.Field f.Name = ser.Name f.Tags = ser.Tags f.Values = make(map[string]interface{}) for j, value := range value { // influxdb lib is a bit funny if w, ok := value.(json.Number); ok { // check if it is an int or float a, _ := w.Float64() if a == float64(int64(a)) { f.Values[columns[j]], _ = w.Int64() } else { f.Values[columns[j]] = a } } else { f.Values[columns[j]] = value } } datapoints = append(datapoints, f) } } } return datapoints, err }