MCPcopy
hub / github.com/grafana/tempo / execute

Method execute

pkg/traceql/ast_execute.go:846–883  ·  view source on GitHub ↗
(span Span)

Source from the content-addressed store, hash-verified

844}
845
846func (o UnaryOperation) execute(span Span) (Static, error) {
847 static, err := o.Expression.execute(span)
848 if err != nil {
849 return NewStaticNil(), err
850 }
851
852 if o.Op == OpNot {
853 if static.Type != TypeBoolean {
854 return NewStaticNil(), fmt.Errorf("expression (%v) expected a boolean, but got %v", o, static.Type)
855 }
856 b, _ := static.Bool()
857 return NewStaticBool(!b), nil
858 }
859 if o.Op == OpSub {
860 if !static.Type.isNumeric() {
861 return NewStaticNil(), fmt.Errorf("expression (%v) expected a numeric, but got %v", o, static.Type)
862 }
863 switch static.Type {
864 case TypeInt:
865 n, _ := static.Int()
866 return NewStaticInt(-1 * n), nil
867 case TypeFloat:
868 return NewStaticFloat(-1 * static.Float()), nil
869 case TypeDuration:
870 d, _ := static.Duration()
871 return NewStaticDuration(-1 * d), nil
872 }
873 }
874 if o.Op == OpExists {
875 return NewStaticBool(static.Type != TypeNil), nil
876 }
877 if o.Op == OpNotExists {
878 staticNilString := NewStaticString("nil")
879 return NewStaticBool(static.Equals(&staticNilString)), nil
880 }
881
882 return NewStaticNil(), fmt.Errorf("UnaryOperation has invalid operator %v", o.Op)
883}
884
885func (s Static) execute(Span) (Static, error) {
886 return s, nil

Callers 1

newUnaryOperationFunction · 0.95

Calls 13

NewStaticNilFunction · 0.85
NewStaticBoolFunction · 0.85
NewStaticIntFunction · 0.85
NewStaticFloatFunction · 0.85
NewStaticDurationFunction · 0.85
NewStaticStringFunction · 0.85
BoolMethod · 0.80
IntMethod · 0.80
FloatMethod · 0.80
DurationMethod · 0.80
EqualsMethod · 0.80
executeMethod · 0.65

Tested by

no test coverage detected