mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
Rename remaining all-caps constants in AST layer.
Change-Id: Ibe97e30981969056ffcdb89e63c1468ea1ffa140
This commit is contained in:
parent
895523ad14
commit
cc27fb8aab
112
rules/ast/ast.go
112
rules/ast/ast.go
|
@ -72,10 +72,10 @@ type ExprType int
|
|||
// because sometimes we need to pass around just the type without an object of
|
||||
// that type.
|
||||
const (
|
||||
SCALAR ExprType = iota
|
||||
VECTOR
|
||||
MATRIX
|
||||
STRING
|
||||
ScalarType ExprType = iota
|
||||
VectorType
|
||||
MatrixType
|
||||
StringType
|
||||
)
|
||||
|
||||
// BinOpType is an enum for binary operator types.
|
||||
|
@ -83,26 +83,26 @@ type BinOpType int
|
|||
|
||||
// Possible binary operator types.
|
||||
const (
|
||||
ADD BinOpType = iota
|
||||
SUB
|
||||
MUL
|
||||
DIV
|
||||
MOD
|
||||
Add BinOpType = iota
|
||||
Sub
|
||||
Mul
|
||||
Div
|
||||
Mod
|
||||
NE
|
||||
EQ
|
||||
GT
|
||||
LT
|
||||
GE
|
||||
LE
|
||||
AND
|
||||
OR
|
||||
And
|
||||
Or
|
||||
)
|
||||
|
||||
// shouldDropMetric indicates whether the metric name should be dropped after
|
||||
// applying this operator to a vector.
|
||||
func (opType BinOpType) shouldDropMetric() bool {
|
||||
switch opType {
|
||||
case ADD, SUB, MUL, DIV, MOD:
|
||||
case Add, Sub, Mul, Div, Mod:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
@ -114,11 +114,11 @@ type AggrType int
|
|||
|
||||
// Possible aggregation types.
|
||||
const (
|
||||
SUM AggrType = iota
|
||||
AVG
|
||||
MIN
|
||||
MAX
|
||||
COUNT
|
||||
Sum AggrType = iota
|
||||
Avg
|
||||
Min
|
||||
Max
|
||||
Count
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -274,34 +274,34 @@ type (
|
|||
// Implementations.
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node ScalarLiteral) Type() ExprType { return SCALAR }
|
||||
func (node ScalarLiteral) Type() ExprType { return ScalarType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node ScalarFunctionCall) Type() ExprType { return SCALAR }
|
||||
func (node ScalarFunctionCall) Type() ExprType { return ScalarType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node ScalarArithExpr) Type() ExprType { return SCALAR }
|
||||
func (node ScalarArithExpr) Type() ExprType { return ScalarType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node VectorSelector) Type() ExprType { return VECTOR }
|
||||
func (node VectorSelector) Type() ExprType { return VectorType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node VectorFunctionCall) Type() ExprType { return VECTOR }
|
||||
func (node VectorFunctionCall) Type() ExprType { return VectorType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node VectorAggregation) Type() ExprType { return VECTOR }
|
||||
func (node VectorAggregation) Type() ExprType { return VectorType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node VectorArithExpr) Type() ExprType { return VECTOR }
|
||||
func (node VectorArithExpr) Type() ExprType { return VectorType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node MatrixSelector) Type() ExprType { return MATRIX }
|
||||
func (node MatrixSelector) Type() ExprType { return MatrixType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node StringLiteral) Type() ExprType { return STRING }
|
||||
func (node StringLiteral) Type() ExprType { return StringType }
|
||||
|
||||
// Type implements the Node interface.
|
||||
func (node StringFunctionCall) Type() ExprType { return STRING }
|
||||
func (node StringFunctionCall) Type() ExprType { return StringType }
|
||||
|
||||
// Children implements the Node interface and returns an empty slice.
|
||||
func (node ScalarLiteral) Children() Nodes { return Nodes{} }
|
||||
|
@ -458,9 +458,9 @@ func (node *VectorAggregation) groupedAggregationsToVector(aggregations map[uint
|
|||
vector := Vector{}
|
||||
for _, aggregation := range aggregations {
|
||||
switch node.aggrType {
|
||||
case AVG:
|
||||
case Avg:
|
||||
aggregation.value = aggregation.value / clientmodel.SampleValue(aggregation.groupCount)
|
||||
case COUNT:
|
||||
case Count:
|
||||
aggregation.value = clientmodel.SampleValue(aggregation.groupCount)
|
||||
default:
|
||||
// For other aggregations, we already have the right value.
|
||||
|
@ -488,20 +488,20 @@ func (node *VectorAggregation) Eval(timestamp clientmodel.Timestamp) Vector {
|
|||
}
|
||||
|
||||
switch node.aggrType {
|
||||
case SUM:
|
||||
case Sum:
|
||||
groupedResult.value += sample.Value
|
||||
case AVG:
|
||||
case Avg:
|
||||
groupedResult.value += sample.Value
|
||||
groupedResult.groupCount++
|
||||
case MAX:
|
||||
case Max:
|
||||
if groupedResult.value < sample.Value {
|
||||
groupedResult.value = sample.Value
|
||||
}
|
||||
case MIN:
|
||||
case Min:
|
||||
if groupedResult.value > sample.Value {
|
||||
groupedResult.value = sample.Value
|
||||
}
|
||||
case COUNT:
|
||||
case Count:
|
||||
groupedResult.groupCount++
|
||||
default:
|
||||
panic("Unknown aggregation type")
|
||||
|
@ -626,18 +626,18 @@ func evalScalarBinop(opType BinOpType,
|
|||
lhs clientmodel.SampleValue,
|
||||
rhs clientmodel.SampleValue) clientmodel.SampleValue {
|
||||
switch opType {
|
||||
case ADD:
|
||||
case Add:
|
||||
return lhs + rhs
|
||||
case SUB:
|
||||
case Sub:
|
||||
return lhs - rhs
|
||||
case MUL:
|
||||
case Mul:
|
||||
return lhs * rhs
|
||||
case DIV:
|
||||
case Div:
|
||||
if rhs != 0 {
|
||||
return lhs / rhs
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs)))
|
||||
case MOD:
|
||||
case Mod:
|
||||
if rhs != 0 {
|
||||
return clientmodel.SampleValue(int(lhs) % int(rhs))
|
||||
}
|
||||
|
@ -680,18 +680,18 @@ func evalVectorBinop(opType BinOpType,
|
|||
lhs clientmodel.SampleValue,
|
||||
rhs clientmodel.SampleValue) (clientmodel.SampleValue, bool) {
|
||||
switch opType {
|
||||
case ADD:
|
||||
case Add:
|
||||
return lhs + rhs, true
|
||||
case SUB:
|
||||
case Sub:
|
||||
return lhs - rhs, true
|
||||
case MUL:
|
||||
case Mul:
|
||||
return lhs * rhs, true
|
||||
case DIV:
|
||||
case Div:
|
||||
if rhs != 0 {
|
||||
return lhs / rhs, true
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs))), true
|
||||
case MOD:
|
||||
case Mod:
|
||||
if rhs != 0 {
|
||||
return clientmodel.SampleValue(int(lhs) % int(rhs)), true
|
||||
}
|
||||
|
@ -726,9 +726,9 @@ func evalVectorBinop(opType BinOpType,
|
|||
return lhs, true
|
||||
}
|
||||
return 0, false
|
||||
case AND:
|
||||
case And:
|
||||
return lhs, true
|
||||
case OR:
|
||||
case Or:
|
||||
return lhs, true // TODO: implement OR
|
||||
}
|
||||
panic("Not all enum values enumerated in switch")
|
||||
|
@ -747,7 +747,7 @@ func labelsEqual(labels1, labels2 clientmodel.Metric) bool {
|
|||
// the expression.
|
||||
func (node *VectorArithExpr) Eval(timestamp clientmodel.Timestamp) Vector {
|
||||
result := Vector{}
|
||||
if node.lhs.Type() == SCALAR && node.rhs.Type() == VECTOR {
|
||||
if node.lhs.Type() == ScalarType && node.rhs.Type() == VectorType {
|
||||
lhs := node.lhs.(ScalarNode).Eval(timestamp)
|
||||
rhs := node.rhs.(VectorNode).Eval(timestamp)
|
||||
for _, rhsSample := range rhs {
|
||||
|
@ -761,7 +761,7 @@ func (node *VectorArithExpr) Eval(timestamp clientmodel.Timestamp) Vector {
|
|||
}
|
||||
}
|
||||
return result
|
||||
} else if node.lhs.Type() == VECTOR && node.rhs.Type() == SCALAR {
|
||||
} else if node.lhs.Type() == VectorType && node.rhs.Type() == ScalarType {
|
||||
lhs := node.lhs.(VectorNode).Eval(timestamp)
|
||||
rhs := node.rhs.(ScalarNode).Eval(timestamp)
|
||||
for _, lhsSample := range lhs {
|
||||
|
@ -775,7 +775,7 @@ func (node *VectorArithExpr) Eval(timestamp clientmodel.Timestamp) Vector {
|
|||
}
|
||||
}
|
||||
return result
|
||||
} else if node.lhs.Type() == VECTOR && node.rhs.Type() == VECTOR {
|
||||
} else if node.lhs.Type() == VectorType && node.rhs.Type() == VectorType {
|
||||
lhs := node.lhs.(VectorNode).Eval(timestamp)
|
||||
rhs := node.rhs.(VectorNode).Eval(timestamp)
|
||||
for _, lhsSample := range lhs {
|
||||
|
@ -916,17 +916,17 @@ func NewFunctionCall(function *Function, args Nodes) (Node, error) {
|
|||
return nil, err
|
||||
}
|
||||
switch function.returnType {
|
||||
case SCALAR:
|
||||
case ScalarType:
|
||||
return &ScalarFunctionCall{
|
||||
function: function,
|
||||
args: args,
|
||||
}, nil
|
||||
case VECTOR:
|
||||
case VectorType:
|
||||
return &VectorFunctionCall{
|
||||
function: function,
|
||||
args: args,
|
||||
}, nil
|
||||
case STRING:
|
||||
case StringType:
|
||||
return &StringFunctionCall{
|
||||
function: function,
|
||||
args: args,
|
||||
|
@ -953,17 +953,17 @@ func nodesHaveTypes(nodes Nodes, exprTypes []ExprType) bool {
|
|||
// NewArithExpr returns a (not yet evaluated) expression node (of type
|
||||
// VectorArithExpr or ScalarArithExpr).
|
||||
func NewArithExpr(opType BinOpType, lhs Node, rhs Node) (Node, error) {
|
||||
if !nodesHaveTypes(Nodes{lhs, rhs}, []ExprType{SCALAR, VECTOR}) {
|
||||
if !nodesHaveTypes(Nodes{lhs, rhs}, []ExprType{ScalarType, VectorType}) {
|
||||
return nil, errors.New("binary operands must be of vector or scalar type")
|
||||
}
|
||||
|
||||
if opType == AND || opType == OR {
|
||||
if lhs.Type() == SCALAR || rhs.Type() == SCALAR {
|
||||
if opType == And || opType == Or {
|
||||
if lhs.Type() == ScalarType || rhs.Type() == ScalarType {
|
||||
return nil, errors.New("AND and OR operators may only be used between vectors")
|
||||
}
|
||||
}
|
||||
|
||||
if lhs.Type() == VECTOR || rhs.Type() == VECTOR {
|
||||
if lhs.Type() == VectorType || rhs.Type() == VectorType {
|
||||
return &VectorArithExpr{
|
||||
opType: opType,
|
||||
lhs: lhs,
|
||||
|
|
|
@ -46,19 +46,19 @@ func (function *Function) CheckArgTypes(args []Node) error {
|
|||
for idx, argType := range function.argTypes {
|
||||
invalidType := false
|
||||
var expectedType string
|
||||
if _, ok := args[idx].(ScalarNode); argType == SCALAR && !ok {
|
||||
if _, ok := args[idx].(ScalarNode); argType == ScalarType && !ok {
|
||||
invalidType = true
|
||||
expectedType = "scalar"
|
||||
}
|
||||
if _, ok := args[idx].(VectorNode); argType == VECTOR && !ok {
|
||||
if _, ok := args[idx].(VectorNode); argType == VectorType && !ok {
|
||||
invalidType = true
|
||||
expectedType = "vector"
|
||||
}
|
||||
if _, ok := args[idx].(MatrixNode); argType == MATRIX && !ok {
|
||||
if _, ok := args[idx].(MatrixNode); argType == MatrixType && !ok {
|
||||
invalidType = true
|
||||
expectedType = "matrix"
|
||||
}
|
||||
if _, ok := args[idx].(StringNode); argType == STRING && !ok {
|
||||
if _, ok := args[idx].(StringNode); argType == StringType && !ok {
|
||||
invalidType = true
|
||||
expectedType = "string"
|
||||
}
|
||||
|
@ -409,104 +409,104 @@ func absentImpl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
|||
var functions = map[string]*Function{
|
||||
"abs": {
|
||||
name: "abs",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: absImpl,
|
||||
},
|
||||
"absent": {
|
||||
name: "absent",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: absentImpl,
|
||||
},
|
||||
"avg_over_time": {
|
||||
name: "avg_over_time",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: avgOverTimeImpl,
|
||||
},
|
||||
"bottomk": {
|
||||
name: "bottomk",
|
||||
argTypes: []ExprType{SCALAR, VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{ScalarType, VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: bottomkImpl,
|
||||
},
|
||||
"count_over_time": {
|
||||
name: "count_over_time",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: countOverTimeImpl,
|
||||
},
|
||||
"count_scalar": {
|
||||
name: "count_scalar",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: SCALAR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: ScalarType,
|
||||
callFn: countScalarImpl,
|
||||
},
|
||||
"delta": {
|
||||
name: "delta",
|
||||
argTypes: []ExprType{MATRIX, SCALAR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType, ScalarType},
|
||||
returnType: VectorType,
|
||||
callFn: deltaImpl,
|
||||
},
|
||||
"drop_common_labels": {
|
||||
name: "drop_common_labels",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: dropCommonLabelsImpl,
|
||||
},
|
||||
"max_over_time": {
|
||||
name: "max_over_time",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: maxOverTimeImpl,
|
||||
},
|
||||
"min_over_time": {
|
||||
name: "min_over_time",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: minOverTimeImpl,
|
||||
},
|
||||
"rate": {
|
||||
name: "rate",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: rateImpl,
|
||||
},
|
||||
"scalar": {
|
||||
name: "scalar",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: SCALAR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: ScalarType,
|
||||
callFn: scalarImpl,
|
||||
},
|
||||
"sort": {
|
||||
name: "sort",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: sortImpl,
|
||||
},
|
||||
"sort_desc": {
|
||||
name: "sort_desc",
|
||||
argTypes: []ExprType{VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: sortDescImpl,
|
||||
},
|
||||
"sum_over_time": {
|
||||
name: "sum_over_time",
|
||||
argTypes: []ExprType{MATRIX},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{MatrixType},
|
||||
returnType: VectorType,
|
||||
callFn: sumOverTimeImpl,
|
||||
},
|
||||
"time": {
|
||||
name: "time",
|
||||
argTypes: []ExprType{},
|
||||
returnType: SCALAR,
|
||||
returnType: ScalarType,
|
||||
callFn: timeImpl,
|
||||
},
|
||||
"topk": {
|
||||
name: "topk",
|
||||
argTypes: []ExprType{SCALAR, VECTOR},
|
||||
returnType: VECTOR,
|
||||
argTypes: []ExprType{ScalarType, VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: topkImpl,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
type emptyRangeNode struct{}
|
||||
|
||||
func (node emptyRangeNode) Type() ExprType { return MATRIX }
|
||||
func (node emptyRangeNode) Type() ExprType { return MatrixType }
|
||||
func (node emptyRangeNode) NodeTreeToDotGraph() string { return "" }
|
||||
func (node emptyRangeNode) String() string { return "" }
|
||||
func (node emptyRangeNode) Children() Nodes { return Nodes{} }
|
||||
|
|
|
@ -33,46 +33,46 @@ type OutputFormat int
|
|||
|
||||
// Possible output formats.
|
||||
const (
|
||||
TEXT OutputFormat = iota
|
||||
Text OutputFormat = iota
|
||||
JSON
|
||||
)
|
||||
|
||||
func (opType BinOpType) String() string {
|
||||
opTypeMap := map[BinOpType]string{
|
||||
ADD: "+",
|
||||
SUB: "-",
|
||||
MUL: "*",
|
||||
DIV: "/",
|
||||
MOD: "%",
|
||||
Add: "+",
|
||||
Sub: "-",
|
||||
Mul: "*",
|
||||
Div: "/",
|
||||
Mod: "%",
|
||||
GT: ">",
|
||||
LT: "<",
|
||||
EQ: "==",
|
||||
NE: "!=",
|
||||
GE: ">=",
|
||||
LE: "<=",
|
||||
AND: "AND",
|
||||
OR: "OR",
|
||||
And: "AND",
|
||||
Or: "OR",
|
||||
}
|
||||
return opTypeMap[opType]
|
||||
}
|
||||
|
||||
func (aggrType AggrType) String() string {
|
||||
aggrTypeMap := map[AggrType]string{
|
||||
SUM: "SUM",
|
||||
AVG: "AVG",
|
||||
MIN: "MIN",
|
||||
MAX: "MAX",
|
||||
COUNT: "COUNT",
|
||||
Sum: "SUM",
|
||||
Avg: "AVG",
|
||||
Min: "MIN",
|
||||
Max: "MAX",
|
||||
Count: "COUNT",
|
||||
}
|
||||
return aggrTypeMap[aggrType]
|
||||
}
|
||||
|
||||
func (exprType ExprType) String() string {
|
||||
exprTypeMap := map[ExprType]string{
|
||||
SCALAR: "scalar",
|
||||
VECTOR: "vector",
|
||||
MATRIX: "matrix",
|
||||
STRING: "string",
|
||||
ScalarType: "scalar",
|
||||
VectorType: "vector",
|
||||
MatrixType: "matrix",
|
||||
StringType: "string",
|
||||
}
|
||||
return exprTypeMap[exprType]
|
||||
}
|
||||
|
@ -164,38 +164,38 @@ func EvalToString(node Node, timestamp clientmodel.Timestamp, format OutputForma
|
|||
|
||||
evalTimer := queryStats.GetTimer(stats.InnerEvalTime).Start()
|
||||
switch node.Type() {
|
||||
case SCALAR:
|
||||
case ScalarType:
|
||||
scalar := node.(ScalarNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
switch format {
|
||||
case TEXT:
|
||||
case Text:
|
||||
return fmt.Sprintf("scalar: %v @[%v]", scalar, timestamp)
|
||||
case JSON:
|
||||
return TypedValueToJSON(scalar, "scalar")
|
||||
}
|
||||
case VECTOR:
|
||||
case VectorType:
|
||||
vector := node.(VectorNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
switch format {
|
||||
case TEXT:
|
||||
case Text:
|
||||
return vector.String()
|
||||
case JSON:
|
||||
return TypedValueToJSON(vector, "vector")
|
||||
}
|
||||
case MATRIX:
|
||||
case MatrixType:
|
||||
matrix := node.(MatrixNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
switch format {
|
||||
case TEXT:
|
||||
case Text:
|
||||
return matrix.String()
|
||||
case JSON:
|
||||
return TypedValueToJSON(matrix, "matrix")
|
||||
}
|
||||
case STRING:
|
||||
case StringType:
|
||||
str := node.(StringNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
switch format {
|
||||
case TEXT:
|
||||
case Text:
|
||||
return str
|
||||
case JSON:
|
||||
return TypedValueToJSON(str, "string")
|
||||
|
@ -216,17 +216,17 @@ func EvalToVector(node Node, timestamp clientmodel.Timestamp, storage local.Stor
|
|||
|
||||
evalTimer := queryStats.GetTimer(stats.InnerEvalTime).Start()
|
||||
switch node.Type() {
|
||||
case SCALAR:
|
||||
case ScalarType:
|
||||
scalar := node.(ScalarNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
return Vector{&Sample{Value: scalar}}, nil
|
||||
case VECTOR:
|
||||
case VectorType:
|
||||
vector := node.(VectorNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
return vector, nil
|
||||
case MATRIX:
|
||||
case MatrixType:
|
||||
return nil, errors.New("matrices not supported by EvalToVector")
|
||||
case STRING:
|
||||
case StringType:
|
||||
str := node.(StringNode).Eval(timestamp)
|
||||
evalTimer.Stop()
|
||||
return Vector{
|
||||
|
|
|
@ -69,11 +69,11 @@ func NewVectorAggregation(aggrTypeStr string, vector ast.Node, groupBy clientmod
|
|||
return nil, fmt.Errorf("operand of %v aggregation must be of vector type", aggrTypeStr)
|
||||
}
|
||||
var aggrTypes = map[string]ast.AggrType{
|
||||
"SUM": ast.SUM,
|
||||
"MAX": ast.MAX,
|
||||
"MIN": ast.MIN,
|
||||
"AVG": ast.AVG,
|
||||
"COUNT": ast.COUNT,
|
||||
"SUM": ast.Sum,
|
||||
"MAX": ast.Max,
|
||||
"MIN": ast.Min,
|
||||
"AVG": ast.Avg,
|
||||
"COUNT": ast.Count,
|
||||
}
|
||||
aggrType, ok := aggrTypes[aggrTypeStr]
|
||||
if !ok {
|
||||
|
@ -85,19 +85,19 @@ func NewVectorAggregation(aggrTypeStr string, vector ast.Node, groupBy clientmod
|
|||
// NewArithExpr is a convenience function to create a new AST arithmetic expression.
|
||||
func NewArithExpr(opTypeStr string, lhs ast.Node, rhs ast.Node) (ast.Node, error) {
|
||||
var opTypes = map[string]ast.BinOpType{
|
||||
"+": ast.ADD,
|
||||
"-": ast.SUB,
|
||||
"*": ast.MUL,
|
||||
"/": ast.DIV,
|
||||
"%": ast.MOD,
|
||||
"+": ast.Add,
|
||||
"-": ast.Sub,
|
||||
"*": ast.Mul,
|
||||
"/": ast.Div,
|
||||
"%": ast.Mod,
|
||||
">": ast.GT,
|
||||
"<": ast.LT,
|
||||
"==": ast.EQ,
|
||||
"!=": ast.NE,
|
||||
">=": ast.GE,
|
||||
"<=": ast.LE,
|
||||
"AND": ast.AND,
|
||||
"OR": ast.OR,
|
||||
"AND": ast.And,
|
||||
"OR": ast.Or,
|
||||
}
|
||||
opType, ok := opTypes[opTypeStr]
|
||||
if !ok {
|
||||
|
|
3532
rules/lexer.l.go
3532
rules/lexer.l.go
File diff suppressed because it is too large
Load diff
|
@ -67,7 +67,7 @@ var yyToknames = []string{
|
|||
"WITH",
|
||||
"SUMMARY",
|
||||
"DESCRIPTION",
|
||||
" =",
|
||||
"'='",
|
||||
}
|
||||
var yyStatenames = []string{}
|
||||
|
||||
|
|
|
@ -658,7 +658,7 @@ func TestExpressions(t *testing.T) {
|
|||
t.Errorf("%d. Test should fail, but didn't", i)
|
||||
}
|
||||
failed := false
|
||||
resultStr := ast.EvalToString(testExpr, testEvalTime, ast.TEXT, storage, stats.NewTimerGroup())
|
||||
resultStr := ast.EvalToString(testExpr, testEvalTime, ast.Text, storage, stats.NewTimerGroup())
|
||||
resultLines := strings.Split(resultStr, "\n")
|
||||
|
||||
if len(exprTest.output) != len(resultLines) {
|
||||
|
|
|
@ -54,7 +54,7 @@ func (serv MetricsService) Query(w http.ResponseWriter, r *http.Request) {
|
|||
format = ast.JSON
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
} else {
|
||||
format = ast.TEXT
|
||||
format = ast.Text
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func (serv MetricsService) QueryRange(w http.ResponseWriter, r *http.Request) {
|
|||
fmt.Fprint(w, ast.ErrorToJSON(err))
|
||||
return
|
||||
}
|
||||
if exprNode.Type() != ast.VECTOR {
|
||||
if exprNode.Type() != ast.VectorType {
|
||||
fmt.Fprint(w, ast.ErrorToJSON(errors.New("expression does not evaluate to vector type")))
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue