Documentation ¶
Index ¶
- Constants
- Variables
- func IsAggFunction(name string) bool
- func IsFunction(name string) bool
- func New(start, end int64, stmt string) tsql.Parser
- func SortResultSet(rs *tsql.ResultSet, sorts influxql.SortFields)
- type AggFuncDefine
- type AggHandler
- type Columns
- type Context
- func (c *Context) Aggregations() elastic.Aggregations
- func (c *Context) AttributesCache() map[string]interface{}
- func (c *Context) GetFuncID(call *influxql.Call, deftyp influxql.DataType) string
- func (c *Context) HandleScopeAgg(scope string, aggs elastic.Aggregations, expr influxql.Expr) (interface{}, error)
- func (c *Context) Interval() int64
- func (c *Context) Now() time.Time
- func (c *Context) OriginalTimeUnit() tsql.TimeUnit
- func (c *Context) Range(conv bool) (int64, int64)
- func (c *Context) RowNum() int64
- func (c *Context) TargetTimeUnit() tsql.TimeUnit
- func (c *Context) TimeKey() string
- type FuncFlag
- type PainlessFunction
- type Parser
- func (p *Parser) ParseQuery() ([]tsql.Query, error)
- func (p *Parser) ParseRawQuery() ([]*tsql.Source, *elastic.BoolQuery, *elastic.SearchSource, error)
- func (p *Parser) SetFilter(filter *elastic.BoolQuery) tsql.Parser
- func (p *Parser) SetMaxTimePoints(points int64) tsql.Parser
- func (p *Parser) SetOriginalTimeUnit(unit tsql.TimeUnit) tsql.Parser
- func (p *Parser) SetParams(params map[string]interface{}) tsql.Parser
- func (p *Parser) SetTargetTimeUnit(unit tsql.TimeUnit) tsql.Parser
- func (p *Parser) SetTimeKey(key string) tsql.Parser
- type Query
- func (q *Query) BoolQuery() *elastic.BoolQuery
- func (q *Query) Context() tsql.Context
- func (q *Query) ParseResult(resp *elastic.SearchResult) (*tsql.ResultSet, error)
- func (q *Query) SearchSource() *elastic.SearchSource
- func (q *Query) SetAllColumnsCallback(fn func(start, end int64, sources []*tsql.Source) ([]*tsql.Column, error))
- func (q *Query) Sources() []*tsql.Source
Constants ¶
View Source
const ( FuncFlagNone = FuncFlag(0) FuncFlagSelect = FuncFlag(1 << (iota - 1)) FuncFlagWhere FuncFlagOrderBy )
FuncFlag .
Variables ¶
View Source
var AggFunctions = map[string]*AggFuncDefine{ "max": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "max", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewMaxAggregation().Script(script), nil } return elastic.NewMaxAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Max(id) }, ), }, "min": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "min", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewMinAggregation().Script(script), nil } return elastic.NewMinAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Min(id) }, ), }, "avg": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "avg", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewAvgAggregation().Script(script), nil } return elastic.NewAvgAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Avg(id) }, ), }, "mean": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "mean", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewAvgAggregation().Script(script), nil } return elastic.NewAvgAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Avg(id) }, ), }, "sum": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "sum", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewSumAggregation().Script(script), nil } return elastic.NewSumAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Sum(id) }, ), }, "count": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "count", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewValueCountAggregation().Script(script), nil } return elastic.NewValueCountAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.ValueCount(id) }, ), }, "distinct": { Flag: FuncFlagSelect | FuncFlagOrderBy, New: newUnaryValueAggFunction( "distinct", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewCardinalityAggregation().Script(script), nil } return elastic.NewCardinalityAggregation().Field(field), nil }, func(ctx *Context, id string, aggs elastic.Aggregations) (*elastic.AggregationValueMetric, bool) { return aggs.Cardinality(id) }, ), }, "median": { Flag: FuncFlagSelect, New: newUnaryAggFunction( "median", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewPercentilesAggregation().Percentiles(50).Script(script), nil } return elastic.NewPercentilesAggregation().Percentiles(50).Field(field), nil }, func(ctx *Context, id, field string, call *influxql.Call, aggs elastic.Aggregations) (interface{}, bool) { percents, ok := aggs.Percentiles(id) if !ok || percents == nil { return nil, false } for _, v := range percents.Values { return v, true } return nil, true }, ), }, "percentiles": { Flag: FuncFlagSelect, New: newMultivariateAggFunction( "percentiles", func(ctx *Context, id, field string, params []influxql.Expr, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if len(params) == 0 { return nil, fmt.Errorf("not percent data") } ref, ok, err := getLiteralValue(ctx, params[0]) if !ok || err != nil { return nil, fmt.Errorf("invalid percent type error") } floatPercent, ok := ref.(float64) if !ok { return nil, fmt.Errorf("invalid percent type error") } if floatPercent < 0 || floatPercent > 100 { return nil, errors.New("percent was out of range") } if script != nil { return elastic.NewPercentilesAggregation().Percentiles(floatPercent).Script(script), nil } return elastic.NewPercentilesAggregation().Percentiles(floatPercent).Field(field), nil }, func(ctx *Context, id, field string, params []influxql.Expr, call *influxql.Call, aggs elastic.Aggregations) (interface{}, bool) { percents, ok := aggs.Percentiles(id) if !ok || percents == nil { return nil, false } for _, v := range percents.Values { return v, true } return nil, true }, ), }, "diff": { Flag: FuncFlagSelect, New: newUnaryAggFunction( "diff", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewMinAggregation().Script(script), nil } return elastic.NewMinAggregation().Field(field), nil }, func(ctx *Context, id, field string, call *influxql.Call, aggs elastic.Aggregations) (interface{}, bool) { if next, ok := ctx.attributesCache["next"]; ok { min, _ := aggs.Min(id) if min == nil { return nil, false } if min.Value == nil { return 0, true } if next, ok := next.(elastic.Aggregations); ok { if next, ok := next.Min(id); ok && next != nil && next.Value != nil { return *next.Value - *min.Value, true } } } return 0, true }, ), }, "diffps": { Flag: FuncFlagSelect, New: newUnaryAggFunction( "diffps", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewMinAggregation().Script(script), nil } return elastic.NewMinAggregation().Field(field), nil }, func(ctx *Context, id, field string, call *influxql.Call, aggs elastic.Aggregations) (interface{}, bool) { if next, ok := ctx.attributesCache["next"]; ok { min, _ := aggs.Min(id) if min == nil { return nil, false } if min.Value == nil { return 0, true } if next, ok := next.(elastic.Aggregations); ok { if next, ok := next.Min(id); ok && next != nil && next.Value != nil { if ctx.targetTimeUnit == tsql.UnsetTimeUnit { ctx.targetTimeUnit = tsql.Nanosecond } seconds := float64(ctx.interval*int64(ctx.targetTimeUnit)) / float64(tsql.Second) return (*next.Value - *min.Value) / seconds, true } } } return 0, true }, ), }, "rateps": { Flag: FuncFlagSelect, New: newUnaryAggFunction( "rateps", func(ctx *Context, id, field string, script *elastic.Script, flags ...FuncFlag) (elastic.Aggregation, error) { if script != nil { return elastic.NewSumAggregation().Script(script), nil } return elastic.NewSumAggregation().Field(field), nil }, func(ctx *Context, id, field string, call *influxql.Call, aggs elastic.Aggregations) (interface{}, bool) { sum, _ := aggs.Sum(id) if sum == nil { return nil, false } if sum.Value == nil { return 0, true } if ctx.targetTimeUnit == tsql.UnsetTimeUnit { ctx.targetTimeUnit = tsql.Nanosecond } seconds := float64(ctx.interval*int64(ctx.targetTimeUnit)) / float64(tsql.Second) return *sum.Value / seconds, true }, ), }, "first": newSourceFieldAggFunction("first", tsql.TimestampKey, true), "last": newSourceFieldAggFunction("last", tsql.TimestampKey, false), "value": newSourceFieldAggFunction("value", tsql.TimestampKey, false), }
AggFunctions .
View Source
var PainlessFunctions map[string]*PainlessFunction
PainlessFunctions .
Functions ¶
func SortResultSet ¶
func SortResultSet(rs *tsql.ResultSet, sorts influxql.SortFields)
SortResultSet .
Types ¶
type AggFuncDefine ¶
type AggFuncDefine struct { Flag FuncFlag New func(ctx *Context, id string, call *influxql.Call) (AggHandler, error) }
AggFuncDefine .
type AggHandler ¶
type AggHandler interface { Aggregations(aggs map[string]elastic.Aggregation, flags ...FuncFlag) error Handle(aggs elastic.Aggregations) (interface{}, error) }
AggHandler .
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context .
func (*Context) AttributesCache ¶
AttributeCache .
func (*Context) HandleScopeAgg ¶
func (c *Context) HandleScopeAgg(scope string, aggs elastic.Aggregations, expr influxql.Expr) (interface{}, error)
HandleScopeAgg .
func (*Context) OriginalTimeUnit ¶
OriginalTimeUnit .
type PainlessFunction ¶ added in v1.4.0
type PainlessFunction struct { Name string Objective bool ObjectType string DefaultValue string Convert func(ctx *Context, call *influxql.Call, deftyp influxql.DataType, fields map[string]bool) (string, error) }
PainlessFunction todo .
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser .
func (*Parser) ParseRawQuery ¶
ParseRawQuery .
func (*Parser) SetMaxTimePoints ¶
SetMaxTimePoints .
func (*Parser) SetOriginalTimeUnit ¶
SetOriginalTimeUnit .
func (*Parser) SetTargetTimeUnit ¶
SetTargetTimeUnit .
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query .
func (*Query) ParseResult ¶
ParseResult .
Click to show internal directories.
Click to hide internal directories.