Rename {Scalar,Vector}Literal to {Scalar,Vector}Selector.

Change-Id: Ie92301f47f5f49f30b3a62c365e377108982b080
This commit is contained in:
Julius Volz 2014-02-22 22:29:32 +01:00
parent a8d4a7ce48
commit 3f226c9724
7 changed files with 49 additions and 49 deletions

View file

@ -148,7 +148,7 @@ type StringNode interface {
// ScalarNode types. // ScalarNode types.
type ( type (
// ScalarLiteral represents a numeric literal. // ScalarLiteral represents a numeric selector.
ScalarLiteral struct { ScalarLiteral struct {
value clientmodel.SampleValue value clientmodel.SampleValue
} }
@ -173,8 +173,8 @@ type (
// VectorNode types. // VectorNode types.
type ( type (
// A VectorLiteral represents a metric name plus labelset. // A VectorSelector represents a metric name plus labelset.
VectorLiteral struct { VectorSelector struct {
labels clientmodel.LabelSet labels clientmodel.LabelSet
// Fingerprints are populated from labels at query analysis time. // Fingerprints are populated from labels at query analysis time.
fingerprints clientmodel.Fingerprints fingerprints clientmodel.Fingerprints
@ -208,9 +208,9 @@ type (
// MatrixNode types. // MatrixNode types.
type ( type (
// A MatrixLiteral represents a metric name plus labelset and // A MatrixSelector represents a metric name plus labelset and
// timerange. // timerange.
MatrixLiteral struct { MatrixSelector struct {
labels clientmodel.LabelSet labels clientmodel.LabelSet
// Fingerprints are populated from labels at query // Fingerprints are populated from labels at query
// analysis time. // analysis time.
@ -249,7 +249,7 @@ func (node ScalarFunctionCall) Type() ExprType { return SCALAR }
func (node ScalarArithExpr) Type() ExprType { return SCALAR } func (node ScalarArithExpr) Type() ExprType { return SCALAR }
// Type implements the Node interface. // Type implements the Node interface.
func (node VectorLiteral) Type() ExprType { return VECTOR } func (node VectorSelector) Type() ExprType { return VECTOR }
// Type implements the Node interface. // Type implements the Node interface.
func (node VectorFunctionCall) Type() ExprType { return VECTOR } func (node VectorFunctionCall) Type() ExprType { return VECTOR }
@ -261,7 +261,7 @@ func (node VectorAggregation) Type() ExprType { return VECTOR }
func (node VectorArithExpr) Type() ExprType { return VECTOR } func (node VectorArithExpr) Type() ExprType { return VECTOR }
// Type implements the Node interface. // Type implements the Node interface.
func (node MatrixLiteral) Type() ExprType { return MATRIX } func (node MatrixSelector) Type() ExprType { return MATRIX }
// Type implements the Node interface. // Type implements the Node interface.
func (node StringLiteral) Type() ExprType { return STRING } func (node StringLiteral) Type() ExprType { return STRING }
@ -281,7 +281,7 @@ func (node ScalarFunctionCall) Children() Nodes { return node.args }
func (node ScalarArithExpr) Children() Nodes { return Nodes{node.lhs, node.rhs} } func (node ScalarArithExpr) Children() Nodes { return Nodes{node.lhs, node.rhs} }
// Children implements the Node interface and returns an empty slice. // Children implements the Node interface and returns an empty slice.
func (node VectorLiteral) Children() Nodes { return Nodes{} } func (node VectorSelector) Children() Nodes { return Nodes{} }
// Children implements the Node interface and returns the args of the // Children implements the Node interface and returns the args of the
// function call. // function call.
@ -296,7 +296,7 @@ func (node VectorAggregation) Children() Nodes { return Nodes{node.vector} }
func (node VectorArithExpr) Children() Nodes { return Nodes{node.lhs, node.rhs} } func (node VectorArithExpr) Children() Nodes { return Nodes{node.lhs, node.rhs} }
// Children implements the Node interface and returns an empty slice. // Children implements the Node interface and returns an empty slice.
func (node MatrixLiteral) Children() Nodes { return Nodes{} } func (node MatrixSelector) Children() Nodes { return Nodes{} }
// Children implements the Node interface and returns an empty slice. // Children implements the Node interface and returns an empty slice.
func (node StringLiteral) Children() Nodes { return Nodes{} } func (node StringLiteral) Children() Nodes { return Nodes{} }
@ -305,7 +305,7 @@ func (node StringLiteral) Children() Nodes { return Nodes{} }
// function call. // function call.
func (node StringFunctionCall) Children() Nodes { return node.args } func (node StringFunctionCall) Children() Nodes { return node.args }
// Eval implements the ScalarNode interface and returns the literal // Eval implements the ScalarNode interface and returns the selector
// value. // value.
func (node *ScalarLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) clientmodel.SampleValue { func (node *ScalarLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) clientmodel.SampleValue {
return node.value return node.value
@ -496,8 +496,8 @@ func (node *VectorAggregation) Eval(timestamp clientmodel.Timestamp, view *viewA
} }
// Eval implements the VectorNode interface and returns the value of // Eval implements the VectorNode interface and returns the value of
// the literal. // the selector.
func (node *VectorLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Vector { func (node *VectorSelector) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Vector {
values, err := view.GetValueAtTime(node.fingerprints, timestamp) values, err := view.GetValueAtTime(node.fingerprints, timestamp)
if err != nil { if err != nil {
glog.Error("Unable to get vector values: ", err) glog.Error("Unable to get vector values: ", err)
@ -670,8 +670,8 @@ func (node *VectorArithExpr) Eval(timestamp clientmodel.Timestamp, view *viewAda
} }
// Eval implements the MatrixNode interface and returns the value of // Eval implements the MatrixNode interface and returns the value of
// the literal. // the selector.
func (node *MatrixLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix { func (node *MatrixSelector) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
interval := &metric.Interval{ interval := &metric.Interval{
OldestInclusive: timestamp.Add(-node.interval), OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: timestamp, NewestInclusive: timestamp,
@ -685,8 +685,8 @@ func (node *MatrixLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapt
} }
// EvalBoundaries implements the MatrixNode interface and returns the // EvalBoundaries implements the MatrixNode interface and returns the
// boundary values of the literal. // boundary values of the selector.
func (node *MatrixLiteral) EvalBoundaries(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix { func (node *MatrixSelector) EvalBoundaries(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
interval := &metric.Interval{ interval := &metric.Interval{
OldestInclusive: timestamp.Add(-node.interval), OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: timestamp, NewestInclusive: timestamp,
@ -715,7 +715,7 @@ func (matrix Matrix) Swap(i, j int) {
} }
// Eval implements the StringNode interface and returns the value of // Eval implements the StringNode interface and returns the value of
// the literal. // the selector.
func (node *StringLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) string { func (node *StringLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) string {
return node.str return node.str
} }
@ -736,10 +736,10 @@ func NewScalarLiteral(value clientmodel.SampleValue) *ScalarLiteral {
} }
} }
// NewVectorLiteral returns a (not yet evaluated) VectorLiteral with // NewVectorSelector returns a (not yet evaluated) VectorSelector with
// the given LabelSet. // the given LabelSet.
func NewVectorLiteral(labels clientmodel.LabelSet) *VectorLiteral { func NewVectorSelector(labels clientmodel.LabelSet) *VectorSelector {
return &VectorLiteral{ return &VectorSelector{
labels: labels, labels: labels,
} }
} }
@ -829,10 +829,10 @@ func NewArithExpr(opType BinOpType, lhs Node, rhs Node) (Node, error) {
}, nil }, nil
} }
// NewMatrixLiteral returns a (not yet evaluated) MatrixLiteral with // NewMatrixSelector returns a (not yet evaluated) MatrixSelector with
// the given VectorLiteral and Duration. // the given VectorSelector and Duration.
func NewMatrixLiteral(vector *VectorLiteral, interval time.Duration) *MatrixLiteral { func NewMatrixSelector(vector *VectorSelector, interval time.Duration) *MatrixSelector {
return &MatrixLiteral{ return &MatrixSelector{
labels: vector.labels, labels: vector.labels,
interval: interval, interval: interval,
} }

View file

@ -110,7 +110,7 @@ func deltaImpl(timestamp clientmodel.Timestamp, view *viewAdapter, args []Node)
} }
resultValue := lastValue - samples.Values[0].Value + counterCorrection resultValue := lastValue - samples.Values[0].Value + counterCorrection
targetInterval := args[0].(*MatrixLiteral).interval targetInterval := args[0].(*MatrixSelector).interval
sampledInterval := samples.Values[len(samples.Values)-1].Timestamp.Sub(samples.Values[0].Timestamp) sampledInterval := samples.Values[len(samples.Values)-1].Timestamp.Sub(samples.Values[0].Timestamp)
if sampledInterval == 0 { if sampledInterval == 0 {
// Only found one sample. Cannot compute a rate from this. // Only found one sample. Cannot compute a rate from this.
@ -143,9 +143,9 @@ func rateImpl(timestamp clientmodel.Timestamp, view *viewAdapter, args []Node) i
vector := deltaImpl(timestamp, view, args).(Vector) vector := deltaImpl(timestamp, view, args).(Vector)
// TODO: could be other type of MatrixNode in the future (right now, only // TODO: could be other type of MatrixNode in the future (right now, only
// MatrixLiteral exists). Find a better way of getting the duration of a // MatrixSelector exists). Find a better way of getting the duration of a
// matrix, such as looking at the samples themselves. // matrix, such as looking at the samples themselves.
interval := args[0].(*MatrixLiteral).interval interval := args[0].(*MatrixSelector).interval
for i := range vector { for i := range vector {
vector[i].Value /= clientmodel.SampleValue(interval / time.Second) vector[i].Value /= clientmodel.SampleValue(interval / time.Second)
} }

View file

@ -237,8 +237,8 @@ func (node *ScalarArithExpr) NodeTreeToDotGraph() string {
return graph return graph
} }
// NodeTreeToDotGraph returns a DOT representation of the vector literal. // NodeTreeToDotGraph returns a DOT representation of the vector selector.
func (node *VectorLiteral) NodeTreeToDotGraph() string { func (node *VectorSelector) NodeTreeToDotGraph() string {
return fmt.Sprintf("%#p[label=\"%s\"];\n", node, node) return fmt.Sprintf("%#p[label=\"%s\"];\n", node, node)
} }
@ -280,8 +280,8 @@ func (node *VectorArithExpr) NodeTreeToDotGraph() string {
} }
// NodeTreeToDotGraph returns a DOT representation of the matrix // NodeTreeToDotGraph returns a DOT representation of the matrix
// literal. // selector.
func (node *MatrixLiteral) NodeTreeToDotGraph() string { func (node *MatrixSelector) NodeTreeToDotGraph() string {
return fmt.Sprintf("%#p[label=\"%s\"];\n", node, node) return fmt.Sprintf("%#p[label=\"%s\"];\n", node, node)
} }
@ -319,7 +319,7 @@ func (node *ScalarArithExpr) String() string {
return fmt.Sprintf("(%s %s %s)", node.lhs, node.opType, node.rhs) return fmt.Sprintf("(%s %s %s)", node.lhs, node.opType, node.rhs)
} }
func (node *VectorLiteral) String() string { func (node *VectorSelector) String() string {
metricName, ok := node.labels[clientmodel.MetricNameLabel] metricName, ok := node.labels[clientmodel.MetricNameLabel]
if !ok { if !ok {
panic("Tried to print vector without metric name") panic("Tried to print vector without metric name")
@ -356,8 +356,8 @@ func (node *VectorArithExpr) String() string {
return fmt.Sprintf("(%s %s %s)", node.lhs, node.opType, node.rhs) return fmt.Sprintf("(%s %s %s)", node.lhs, node.opType, node.rhs)
} }
func (node *MatrixLiteral) String() string { func (node *MatrixSelector) String() string {
vectorString := (&VectorLiteral{labels: node.labels}).String() vectorString := (&VectorSelector{labels: node.labels}).String()
intervalString := fmt.Sprintf("[%s]", utility.DurationToString(node.interval)) intervalString := fmt.Sprintf("[%s]", utility.DurationToString(node.interval))
return vectorString + intervalString return vectorString + intervalString
} }

View file

@ -25,7 +25,7 @@ import (
) )
// FullRangeMap maps the fingerprint of a full range to the duration // FullRangeMap maps the fingerprint of a full range to the duration
// of the matrix literal it resulted from. // of the matrix selector it resulted from.
type FullRangeMap map[clientmodel.Fingerprint]time.Duration type FullRangeMap map[clientmodel.Fingerprint]time.Duration
// IntervalRangeMap is a set of fingerprints of interval ranges. // IntervalRangeMap is a set of fingerprints of interval ranges.
@ -41,7 +41,7 @@ type QueryAnalyzer struct {
// - start: query interval start - duration // - start: query interval start - duration
// - end: query interval end // - end: query interval end
// //
// This is because full ranges can only result from matrix literals (like // This is because full ranges can only result from matrix selectors (like
// "foo[5m]"), which have said time-spanning behavior during a ranged query. // "foo[5m]"), which have said time-spanning behavior during a ranged query.
FullRanges FullRangeMap FullRanges FullRangeMap
// Interval ranges always implicitly span the whole query range. // Interval ranges always implicitly span the whole query range.
@ -65,7 +65,7 @@ func NewQueryAnalyzer(storage *metric.TieredStorage) *QueryAnalyzer {
// Visit implements the Visitor interface. // Visit implements the Visitor interface.
func (analyzer *QueryAnalyzer) Visit(node Node) { func (analyzer *QueryAnalyzer) Visit(node Node) {
switch n := node.(type) { switch n := node.(type) {
case *VectorLiteral: case *VectorSelector:
fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels) fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels)
if err != nil { if err != nil {
glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err) glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err)
@ -79,7 +79,7 @@ func (analyzer *QueryAnalyzer) Visit(node Node) {
analyzer.IntervalRanges[*fingerprint] = true analyzer.IntervalRanges[*fingerprint] = true
} }
} }
case *MatrixLiteral: case *MatrixSelector:
fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels) fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels)
if err != nil { if err != nil {
glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err) glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err)

View file

@ -99,21 +99,21 @@ func NewArithExpr(opTypeStr string, lhs ast.Node, rhs ast.Node) (ast.Node, error
return expr, nil return expr, nil
} }
func NewMatrix(vector ast.Node, intervalStr string) (ast.MatrixNode, error) { func NewMatrixSelector(vector ast.Node, intervalStr string) (ast.MatrixNode, error) {
switch vector.(type) { switch vector.(type) {
case *ast.VectorLiteral: case *ast.VectorSelector:
{ {
break break
} }
default: default:
return nil, fmt.Errorf("Intervals are currently only supported for vector literals.") return nil, fmt.Errorf("Intervals are currently only supported for vector selectors.")
} }
interval, err := utility.StringToDuration(intervalStr) interval, err := utility.StringToDuration(intervalStr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
vectorLiteral := vector.(*ast.VectorLiteral) vectorSelector := vector.(*ast.VectorSelector)
return ast.NewMatrixLiteral(vectorLiteral, interval), nil return ast.NewMatrixSelector(vectorSelector, interval), nil
} }
func ConsoleLinkForExpression(expr string) string { func ConsoleLinkForExpression(expr string) string {

View file

@ -116,7 +116,7 @@ label_assign : IDENTIFIER '=' STRING
rule_expr : '(' rule_expr ')' rule_expr : '(' rule_expr ')'
{ $$ = $2 } { $$ = $2 }
| IDENTIFIER rule_labels | IDENTIFIER rule_labels
{ $2[clientmodel.MetricNameLabel] = clientmodel.LabelValue($1); $$ = ast.NewVectorLiteral($2) } { $2[clientmodel.MetricNameLabel] = clientmodel.LabelValue($1); $$ = ast.NewVectorSelector($2) }
| IDENTIFIER '(' func_arg_list ')' | IDENTIFIER '(' func_arg_list ')'
{ {
var err error var err error
@ -132,7 +132,7 @@ rule_expr : '(' rule_expr ')'
| rule_expr '[' DURATION ']' | rule_expr '[' DURATION ']'
{ {
var err error var err error
$$, err = NewMatrix($1, $3) $$, err = NewMatrixSelector($1, $3)
if err != nil { yylex.Error(err.Error()); return 1 } if err != nil { yylex.Error(err.Error()); return 1 }
} }
| AGGR_OP '(' rule_expr ')' grouping_opts extra_labels_opts | AGGR_OP '(' rule_expr ')' grouping_opts extra_labels_opts

View file

@ -245,7 +245,7 @@ out:
c = yyTok2[1] /* unknown char */ c = yyTok2[1] /* unknown char */
} }
if yyDebug >= 3 { if yyDebug >= 3 {
__yyfmt__.Printf("lex %U %s\n", uint(char), yyTokname(c)) __yyfmt__.Printf("lex %s(%d)\n", yyTokname(c), uint(char))
} }
return c return c
} }
@ -342,7 +342,7 @@ yydefault:
Nerrs++ Nerrs++
if yyDebug >= 1 { if yyDebug >= 1 {
__yyfmt__.Printf("%s", yyStatname(yystate)) __yyfmt__.Printf("%s", yyStatname(yystate))
__yyfmt__.Printf("saw %s\n", yyTokname(yychar)) __yyfmt__.Printf(" saw %s\n", yyTokname(yychar))
} }
fallthrough fallthrough
@ -460,7 +460,7 @@ yydefault:
{ yyVAL.ruleNode = yyS[yypt-1].ruleNode } { yyVAL.ruleNode = yyS[yypt-1].ruleNode }
case 19: case 19:
//line parser.y:119 //line parser.y:119
{ yyS[yypt-0].labelSet[clientmodel.MetricNameLabel] = clientmodel.LabelValue(yyS[yypt-1].str); yyVAL.ruleNode = ast.NewVectorLiteral(yyS[yypt-0].labelSet) } { yyS[yypt-0].labelSet[clientmodel.MetricNameLabel] = clientmodel.LabelValue(yyS[yypt-1].str); yyVAL.ruleNode = ast.NewVectorSelector(yyS[yypt-0].labelSet) }
case 20: case 20:
//line parser.y:121 //line parser.y:121
{ {
@ -479,7 +479,7 @@ yydefault:
//line parser.y:133 //line parser.y:133
{ {
var err error var err error
yyVAL.ruleNode, err = NewMatrix(yyS[yypt-3].ruleNode, yyS[yypt-1].str) yyVAL.ruleNode, err = NewMatrixSelector(yyS[yypt-3].ruleNode, yyS[yypt-1].str)
if err != nil { yylex.Error(err.Error()); return 1 } if err != nil { yylex.Error(err.Error()); return 1 }
} }
case 23: case 23: