github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/iterator_mapper_test.go (about) 1 package query_test 2 3 import ( 4 "testing" 5 6 "github.com/davecgh/go-spew/spew" 7 "github.com/influxdata/influxdb/v2/influxql/query" 8 "github.com/influxdata/influxdb/v2/pkg/deep" 9 "github.com/influxdata/influxql" 10 ) 11 12 func TestIteratorMapper(t *testing.T) { 13 cur := query.RowCursor([]query.Row{ 14 { 15 Time: 0, 16 Series: query.Series{ 17 Name: "cpu", 18 Tags: ParseTags("host=A"), 19 }, 20 Values: []interface{}{float64(1), "a"}, 21 }, 22 { 23 Time: 5, 24 Series: query.Series{ 25 Name: "cpu", 26 Tags: ParseTags("host=A"), 27 }, 28 Values: []interface{}{float64(3), "c"}, 29 }, 30 { 31 Time: 2, 32 Series: query.Series{ 33 Name: "cpu", 34 Tags: ParseTags("host=B"), 35 }, 36 Values: []interface{}{float64(2), "b"}, 37 }, 38 { 39 Time: 8, 40 Series: query.Series{ 41 Name: "cpu", 42 Tags: ParseTags("host=B"), 43 }, 44 Values: []interface{}{float64(8), "h"}, 45 }, 46 }, []influxql.VarRef{ 47 {Val: "val1", Type: influxql.Float}, 48 {Val: "val2", Type: influxql.String}, 49 }) 50 51 opt := query.IteratorOptions{ 52 Ascending: true, 53 Aux: []influxql.VarRef{ 54 {Val: "val1", Type: influxql.Float}, 55 {Val: "val2", Type: influxql.String}, 56 }, 57 Dimensions: []string{"host"}, 58 } 59 itr := query.NewIteratorMapper(cur, nil, []query.IteratorMap{ 60 query.FieldMap{Index: 0}, 61 query.FieldMap{Index: 1}, 62 query.TagMap("host"), 63 }, opt) 64 if a, err := Iterators([]query.Iterator{itr}).ReadAll(); err != nil { 65 t.Fatalf("unexpected error: %s", err) 66 } else if !deep.Equal(a, [][]query.Point{ 67 {&query.FloatPoint{Name: "cpu", Tags: ParseTags("host=A"), Time: 0, Aux: []interface{}{float64(1), "a", "A"}}}, 68 {&query.FloatPoint{Name: "cpu", Tags: ParseTags("host=A"), Time: 5, Aux: []interface{}{float64(3), "c", "A"}}}, 69 {&query.FloatPoint{Name: "cpu", Tags: ParseTags("host=B"), Time: 2, Aux: []interface{}{float64(2), "b", "B"}}}, 70 {&query.FloatPoint{Name: "cpu", Tags: ParseTags("host=B"), Time: 8, Aux: []interface{}{float64(8), "h", "B"}}}, 71 }) { 72 t.Errorf("unexpected points: %s", spew.Sdump(a)) 73 } 74 }