func (ic *IteratorCreator) SeriesKeys(opt influxql.IteratorOptions) (influxql.SeriesList, error) { if ic.SeriesKeysFn != nil { return ic.SeriesKeysFn(opt) } itr, err := ic.CreateIterator(opt) if err != nil { return nil, err } seriesMap := make(map[string]influxql.Series) switch itr := itr.(type) { case influxql.FloatIterator: for p := itr.Next(); p != nil; p = itr.Next() { s := influxql.Series{Name: p.Name, Tags: p.Tags, Aux: influxql.InspectDataTypes(p.Aux)} if series, ok := seriesMap[s.ID()]; ok { s.Combine(&series) } seriesMap[s.ID()] = s } case influxql.IntegerIterator: for p := itr.Next(); p != nil; p = itr.Next() { s := influxql.Series{Name: p.Name, Tags: p.Tags, Aux: influxql.InspectDataTypes(p.Aux)} if series, ok := seriesMap[s.ID()]; ok { s.Combine(&series) } seriesMap[s.ID()] = s } case influxql.StringIterator: for p := itr.Next(); p != nil; p = itr.Next() { s := influxql.Series{Name: p.Name, Tags: p.Tags, Aux: influxql.InspectDataTypes(p.Aux)} if series, ok := seriesMap[s.ID()]; ok { s.Combine(&series) } seriesMap[s.ID()] = s } case influxql.BooleanIterator: for p := itr.Next(); p != nil; p = itr.Next() { s := influxql.Series{Name: p.Name, Tags: p.Tags, Aux: influxql.InspectDataTypes(p.Aux)} if series, ok := seriesMap[s.ID()]; ok { s.Combine(&series) } seriesMap[s.ID()] = s } } seriesList := make([]influxql.Series, 0, len(seriesMap)) for _, s := range seriesMap { seriesList = append(seriesList, s) } return influxql.SeriesList(seriesList), nil }
// Ensure series list can be marshaled into and out of a binary format. func TestSeriesList_MarshalBinary(t *testing.T) { a := []influxql.Series{ {Name: "cpu", Tags: ParseTags("foo=bar"), Aux: []influxql.DataType{influxql.Float, influxql.String}}, {Name: "mem", Aux: []influxql.DataType{influxql.Integer}}, {Name: "disk"}, {}, } // Marshal to binary. buf, err := influxql.SeriesList(a).MarshalBinary() if err != nil { t.Fatal(err) } // Unmarshal back to an object. var other influxql.SeriesList if err := other.UnmarshalBinary(buf); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(other, influxql.SeriesList(a)) { t.Fatalf("unexpected series list: %s", spew.Sdump(other)) } }