-
Notifications
You must be signed in to change notification settings - Fork 3
/
scalar_expr.go
45 lines (38 loc) · 959 Bytes
/
scalar_expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package traceql
// ScalarExpr is a scalar expression.
type ScalarExpr interface {
scalarExpr()
TypedExpr
}
func (*BinaryScalarExpr) scalarExpr() {}
func (*AggregateScalarExpr) scalarExpr() {}
func (*Static) scalarExpr() {}
// BinaryScalarExpr is a binary operation between two scalar expressions.
type BinaryScalarExpr struct {
Left ScalarExpr
Op BinaryOp
Right ScalarExpr
}
// ValueType returns value type of expression.
func (s *BinaryScalarExpr) ValueType() StaticType {
if s.Op.IsBoolean() {
return TypeBool
}
t := s.Left.ValueType()
if t != TypeAttribute {
return t
}
return s.Right.ValueType()
}
// AggregateScalarExpr is an aggregate function.
type AggregateScalarExpr struct {
Op AggregateOp
Field FieldExpr // nilable
}
// ValueType returns value type of expression.
func (s *AggregateScalarExpr) ValueType() StaticType {
if s.Op == AggregateOpCount {
return TypeInt
}
return s.Field.ValueType()
}