github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/iterator_mapper.go (about) 1 package query 2 3 import ( 4 "fmt" 5 "math" 6 7 "github.com/influxdata/influxql" 8 ) 9 10 type IteratorMap interface { 11 Value(row *Row) interface{} 12 } 13 14 type FieldMap struct { 15 Index int 16 Type influxql.DataType 17 } 18 19 func (f FieldMap) Value(row *Row) interface{} { 20 v := castToType(row.Values[f.Index], f.Type) 21 if v == NullFloat { 22 // If the value is a null float, then convert it back to NaN 23 // so it is treated as a float for eval. 24 v = math.NaN() 25 } 26 return v 27 } 28 29 type TagMap string 30 31 func (s TagMap) Value(row *Row) interface{} { return row.Series.Tags.Value(string(s)) } 32 33 type NullMap struct{} 34 35 func (NullMap) Value(row *Row) interface{} { return nil } 36 37 func NewIteratorMapper(cur Cursor, driver IteratorMap, fields []IteratorMap, opt IteratorOptions) Iterator { 38 if driver != nil { 39 switch driver := driver.(type) { 40 case FieldMap: 41 switch driver.Type { 42 case influxql.Float: 43 return newFloatIteratorMapper(cur, driver, fields, opt) 44 case influxql.Integer: 45 return newIntegerIteratorMapper(cur, driver, fields, opt) 46 case influxql.Unsigned: 47 return newUnsignedIteratorMapper(cur, driver, fields, opt) 48 case influxql.String, influxql.Tag: 49 return newStringIteratorMapper(cur, driver, fields, opt) 50 case influxql.Boolean: 51 return newBooleanIteratorMapper(cur, driver, fields, opt) 52 default: 53 // The driver doesn't appear to to have a valid driver type. 54 // We should close the cursor and return a blank iterator. 55 // We close the cursor because we own it and have a responsibility 56 // to close it once it is passed into this function. 57 cur.Close() 58 return &nilFloatIterator{} 59 } 60 case TagMap: 61 return newStringIteratorMapper(cur, driver, fields, opt) 62 default: 63 panic(fmt.Sprintf("unable to create iterator mapper with driver expression type: %T", driver)) 64 } 65 } 66 return newFloatIteratorMapper(cur, nil, fields, opt) 67 }