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.
type (
// ScalarLiteral represents a numeric literal.
// ScalarLiteral represents a numeric selector.
ScalarLiteral struct {
value clientmodel.SampleValue
}
@ -173,8 +173,8 @@ type (
// VectorNode types.
type (
// A VectorLiteral represents a metric name plus labelset.
VectorLiteral struct {
// A VectorSelector represents a metric name plus labelset.
VectorSelector struct {
labels clientmodel.LabelSet
// Fingerprints are populated from labels at query analysis time.
fingerprints clientmodel.Fingerprints
@ -208,9 +208,9 @@ type (
// MatrixNode types.
type (
// A MatrixLiteral represents a metric name plus labelset and
// A MatrixSelector represents a metric name plus labelset and
// timerange.
MatrixLiteral struct {
MatrixSelector struct {
labels clientmodel.LabelSet
// Fingerprints are populated from labels at query
// analysis time.
@ -249,7 +249,7 @@ func (node ScalarFunctionCall) Type() ExprType { return SCALAR }
func (node ScalarArithExpr) Type() ExprType { return SCALAR }
// Type implements the Node interface.
func (node VectorLiteral) Type() ExprType { return VECTOR }
func (node VectorSelector) Type() ExprType { return VECTOR }
// Type implements the Node interface.
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 }
// Type implements the Node interface.
func (node MatrixLiteral) Type() ExprType { return MATRIX }
func (node MatrixSelector) Type() ExprType { return MATRIX }
// Type implements the Node interface.
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} }
// 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
// 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} }
// 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.
func (node StringLiteral) Children() Nodes { return Nodes{} }
@ -305,7 +305,7 @@ func (node StringLiteral) Children() Nodes { return Nodes{} }
// function call.
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.
func (node *ScalarLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) clientmodel.SampleValue {
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
// the literal.
func (node *VectorLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Vector {
// the selector.
func (node *VectorSelector) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Vector {
values, err := view.GetValueAtTime(node.fingerprints, timestamp)
if err != nil {
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
// the literal.
func (node *MatrixLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
// the selector.
func (node *MatrixSelector) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
interval := &metric.Interval{
OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: timestamp,
@ -685,8 +685,8 @@ func (node *MatrixLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapt
}
// EvalBoundaries implements the MatrixNode interface and returns the
// boundary values of the literal.
func (node *MatrixLiteral) EvalBoundaries(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
// boundary values of the selector.
func (node *MatrixSelector) EvalBoundaries(timestamp clientmodel.Timestamp, view *viewAdapter) Matrix {
interval := &metric.Interval{
OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: timestamp,
@ -715,7 +715,7 @@ func (matrix Matrix) Swap(i, j int) {
}
// Eval implements the StringNode interface and returns the value of
// the literal.
// the selector.
func (node *StringLiteral) Eval(timestamp clientmodel.Timestamp, view *viewAdapter) string {
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.
func NewVectorLiteral(labels clientmodel.LabelSet) *VectorLiteral {
return &VectorLiteral{
func NewVectorSelector(labels clientmodel.LabelSet) *VectorSelector {
return &VectorSelector{
labels: labels,
}
}
@ -829,10 +829,10 @@ func NewArithExpr(opType BinOpType, lhs Node, rhs Node) (Node, error) {
}, nil
}
// NewMatrixLiteral returns a (not yet evaluated) MatrixLiteral with
// the given VectorLiteral and Duration.
func NewMatrixLiteral(vector *VectorLiteral, interval time.Duration) *MatrixLiteral {
return &MatrixLiteral{
// NewMatrixSelector returns a (not yet evaluated) MatrixSelector with
// the given VectorSelector and Duration.
func NewMatrixSelector(vector *VectorSelector, interval time.Duration) *MatrixSelector {
return &MatrixSelector{
labels: vector.labels,
interval: interval,
}

View file

@ -110,7 +110,7 @@ func deltaImpl(timestamp clientmodel.Timestamp, view *viewAdapter, args []Node)
}
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)
if sampledInterval == 0 {
// 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)
// 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.
interval := args[0].(*MatrixLiteral).interval
interval := args[0].(*MatrixSelector).interval
for i := range vector {
vector[i].Value /= clientmodel.SampleValue(interval / time.Second)
}

View file

@ -237,8 +237,8 @@ func (node *ScalarArithExpr) NodeTreeToDotGraph() string {
return graph
}
// NodeTreeToDotGraph returns a DOT representation of the vector literal.
func (node *VectorLiteral) NodeTreeToDotGraph() string {
// NodeTreeToDotGraph returns a DOT representation of the vector selector.
func (node *VectorSelector) NodeTreeToDotGraph() string {
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
// literal.
func (node *MatrixLiteral) NodeTreeToDotGraph() string {
// selector.
func (node *MatrixSelector) NodeTreeToDotGraph() string {
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)
}
func (node *VectorLiteral) String() string {
func (node *VectorSelector) String() string {
metricName, ok := node.labels[clientmodel.MetricNameLabel]
if !ok {
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)
}
func (node *MatrixLiteral) String() string {
vectorString := (&VectorLiteral{labels: node.labels}).String()
func (node *MatrixSelector) String() string {
vectorString := (&VectorSelector{labels: node.labels}).String()
intervalString := fmt.Sprintf("[%s]", utility.DurationToString(node.interval))
return vectorString + intervalString
}

View file

@ -25,7 +25,7 @@ import (
)
// 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
// IntervalRangeMap is a set of fingerprints of interval ranges.
@ -41,7 +41,7 @@ type QueryAnalyzer struct {
// - start: query interval start - duration
// - 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.
FullRanges FullRangeMap
// Interval ranges always implicitly span the whole query range.
@ -65,7 +65,7 @@ func NewQueryAnalyzer(storage *metric.TieredStorage) *QueryAnalyzer {
// Visit implements the Visitor interface.
func (analyzer *QueryAnalyzer) Visit(node Node) {
switch n := node.(type) {
case *VectorLiteral:
case *VectorSelector:
fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels)
if err != nil {
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
}
}
case *MatrixLiteral:
case *MatrixSelector:
fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels)
if err != nil {
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
}
func NewMatrix(vector ast.Node, intervalStr string) (ast.MatrixNode, error) {
func NewMatrixSelector(vector ast.Node, intervalStr string) (ast.MatrixNode, error) {
switch vector.(type) {
case *ast.VectorLiteral:
case *ast.VectorSelector:
{
break
}
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)
if err != nil {
return nil, err
}
vectorLiteral := vector.(*ast.VectorLiteral)
return ast.NewMatrixLiteral(vectorLiteral, interval), nil
vectorSelector := vector.(*ast.VectorSelector)
return ast.NewMatrixSelector(vectorSelector, interval), nil
}
func ConsoleLinkForExpression(expr string) string {

View file

@ -116,7 +116,7 @@ label_assign : IDENTIFIER '=' STRING
rule_expr : '(' rule_expr ')'
{ $$ = $2 }
| 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 ')'
{
var err error
@ -132,7 +132,7 @@ rule_expr : '(' rule_expr ')'
| rule_expr '[' DURATION ']'
{
var err error
$$, err = NewMatrix($1, $3)
$$, err = NewMatrixSelector($1, $3)
if err != nil { yylex.Error(err.Error()); return 1 }
}
| AGGR_OP '(' rule_expr ')' grouping_opts extra_labels_opts

View file

@ -245,7 +245,7 @@ out:
c = yyTok2[1] /* unknown char */
}
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
}
@ -342,7 +342,7 @@ yydefault:
Nerrs++
if yyDebug >= 1 {
__yyfmt__.Printf("%s", yyStatname(yystate))
__yyfmt__.Printf("saw %s\n", yyTokname(yychar))
__yyfmt__.Printf(" saw %s\n", yyTokname(yychar))
}
fallthrough
@ -460,7 +460,7 @@ yydefault:
{ yyVAL.ruleNode = yyS[yypt-1].ruleNode }
case 19:
//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:
//line parser.y:121
{
@ -479,7 +479,7 @@ yydefault:
//line parser.y:133
{
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 }
}
case 23: