2017-08-15 19:24:22 +00:00
|
|
|
package query
|
2016-11-23 20:32:42 +00:00
|
|
|
|
2018-03-01 20:12:22 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxql"
|
|
|
|
)
|
2016-11-23 20:32:42 +00:00
|
|
|
|
2017-02-13 22:23:10 +00:00
|
|
|
type IteratorMap interface {
|
2018-03-01 20:12:22 +00:00
|
|
|
Value(row *Row) interface{}
|
2017-02-13 22:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type FieldMap int
|
|
|
|
|
2018-03-01 20:12:22 +00:00
|
|
|
func (i FieldMap) Value(row *Row) interface{} { return row.Values[i] }
|
2017-02-13 22:23:10 +00:00
|
|
|
|
|
|
|
type TagMap string
|
|
|
|
|
2018-03-01 20:12:22 +00:00
|
|
|
func (s TagMap) Value(row *Row) interface{} { return row.Series.Tags.Value(string(s)) }
|
2017-02-13 22:23:10 +00:00
|
|
|
|
2017-02-28 21:40:43 +00:00
|
|
|
type NullMap struct{}
|
|
|
|
|
2018-03-01 20:12:22 +00:00
|
|
|
func (NullMap) Value(row *Row) interface{} { return nil }
|
2017-02-28 21:40:43 +00:00
|
|
|
|
2018-03-01 20:12:22 +00:00
|
|
|
func NewIteratorMapper(cur Cursor, driver IteratorMap, fields []IteratorMap, opt IteratorOptions) Iterator {
|
2017-02-28 21:40:43 +00:00
|
|
|
if driver != nil {
|
|
|
|
switch driver := driver.(type) {
|
|
|
|
case FieldMap:
|
2018-03-01 20:12:22 +00:00
|
|
|
switch typ := cur.Columns()[int(driver)].Type; typ {
|
|
|
|
case influxql.Float:
|
|
|
|
return newFloatIteratorMapper(cur, driver, fields, opt)
|
|
|
|
case influxql.Integer:
|
|
|
|
return newIntegerIteratorMapper(cur, driver, fields, opt)
|
|
|
|
case influxql.Unsigned:
|
|
|
|
return newUnsignedIteratorMapper(cur, driver, fields, opt)
|
|
|
|
case influxql.String:
|
|
|
|
return newStringIteratorMapper(cur, driver, fields, opt)
|
|
|
|
case influxql.Boolean:
|
|
|
|
return newBooleanIteratorMapper(cur, driver, fields, opt)
|
2017-02-28 21:40:43 +00:00
|
|
|
default:
|
2018-03-01 20:12:22 +00:00
|
|
|
panic(fmt.Sprintf("unable to map iterator type: %s", typ))
|
2017-02-28 21:40:43 +00:00
|
|
|
}
|
|
|
|
case TagMap:
|
2018-03-01 20:12:22 +00:00
|
|
|
return newStringIteratorMapper(cur, driver, fields, opt)
|
2017-02-28 21:40:43 +00:00
|
|
|
default:
|
2018-03-01 20:12:22 +00:00
|
|
|
panic(fmt.Sprintf("unable to create iterator mapper with driver expression type: %T", driver))
|
2017-02-28 21:40:43 +00:00
|
|
|
}
|
2016-11-23 20:32:42 +00:00
|
|
|
}
|
2018-03-01 20:12:22 +00:00
|
|
|
return newFloatIteratorMapper(cur, nil, fields, opt)
|
2016-11-23 20:32:42 +00:00
|
|
|
}
|