promql: export String value

This commit is contained in:
Fabian Reinartz 2016-12-24 11:25:26 +01:00
parent ac5d3bc05e
commit 6315d00942
2 changed files with 17 additions and 17 deletions

View file

@ -54,7 +54,7 @@ type Value interface {
func (Matrix) Type() ValueType { return ValueTypeMatrix } func (Matrix) Type() ValueType { return ValueTypeMatrix }
func (Vector) Type() ValueType { return ValueTypeVector } func (Vector) Type() ValueType { return ValueTypeVector }
func (Scalar) Type() ValueType { return ValueTypeScalar } func (Scalar) Type() ValueType { return ValueTypeScalar }
func (stringVal) Type() ValueType { return ValueTypeString } func (String) Type() ValueType { return ValueTypeString }
// ValueType describes a type of a value. // ValueType describes a type of a value.
type ValueType string type ValueType string
@ -68,13 +68,13 @@ const (
ValueTypeString = "string" ValueTypeString = "string"
) )
type stringVal struct { type String struct {
s string V string
t int64 T int64
} }
func (s stringVal) String() string { func (s String) String() string {
return s.s return s.V
} }
// Scalar is a data point that's explicitly not associated with a metric. // Scalar is a data point that's explicitly not associated with a metric.
@ -678,9 +678,9 @@ func (ev *evaluator) evalMatrix(e Expr) Matrix {
} }
// evalString attempts to evaluate e to a string value and errors otherwise. // evalString attempts to evaluate e to a string value and errors otherwise.
func (ev *evaluator) evalString(e Expr) stringVal { func (ev *evaluator) evalString(e Expr) String {
val := ev.eval(e) val := ev.eval(e)
sv, ok := val.(stringVal) sv, ok := val.(String)
if !ok { if !ok {
ev.errorf("expected string but got %s", documentedType(val.Type())) ev.errorf("expected string but got %s", documentedType(val.Type()))
} }
@ -756,7 +756,7 @@ func (ev *evaluator) eval(expr Expr) Value {
return ev.eval(e.Expr) return ev.eval(e.Expr)
case *StringLiteral: case *StringLiteral:
return stringVal{s: e.Val, t: ev.Timestamp} return String{V: e.Val, T: ev.Timestamp}
case *UnaryExpr: case *UnaryExpr:
se := ev.evalOneOf(e.Expr, ValueTypeScalar, ValueTypeVector) se := ev.evalOneOf(e.Expr, ValueTypeScalar, ValueTypeVector)
@ -1259,7 +1259,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
} }
var valueLabel string var valueLabel string
if op == itemCountValues { if op == itemCountValues {
valueLabel = ev.evalString(param).s valueLabel = ev.evalString(param).V
if !without { if !without {
grouping = append(grouping, valueLabel) grouping = append(grouping, valueLabel)
} }

View file

@ -788,10 +788,10 @@ func funcChanges(ev *evaluator, args Expressions) Value {
func funcLabelReplace(ev *evaluator, args Expressions) Value { func funcLabelReplace(ev *evaluator, args Expressions) Value {
var ( var (
Vector = ev.evalVector(args[0]) Vector = ev.evalVector(args[0])
dst = ev.evalString(args[1]).s dst = ev.evalString(args[1]).V
repl = ev.evalString(args[2]).s repl = ev.evalString(args[2]).V
src = ev.evalString(args[3]).s src = ev.evalString(args[3]).V
regexStr = ev.evalString(args[4]).s regexStr = ev.evalString(args[4]).V
) )
regex, err := regexp.Compile("^(?:" + regexStr + ")$") regex, err := regexp.Compile("^(?:" + regexStr + ")$")