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

Function newBinaryOperation

pkg/traceql/ast.go:550–580  ·  view source on GitHub ↗
(op Operator, lhs, rhs FieldExpression)

Source from the content-addressed store, hash-verified

548}
549
550func newBinaryOperation(op Operator, lhs, rhs FieldExpression) FieldExpression {
551 binop := &BinaryOperation{
552 Op: op,
553 LHS: lhs,
554 RHS: rhs,
555 }
556
557 if attr, ok := lhs.(Attribute); ok && attr.Intrinsic == IntrinsicTraceID {
558 if static, ok := rhs.(Static); ok {
559 binop.RHS = normalizeTraceIDOperand(static)
560 }
561 }
562 if attr, ok := rhs.(Attribute); ok && attr.Intrinsic == IntrinsicTraceID {
563 if static, ok := lhs.(Static); ok {
564 binop.LHS = normalizeTraceIDOperand(static)
565 }
566 }
567
568 // AST rewrite for simplification
569 if !binop.referencesSpan() && binop.validate() == nil {
570 if simplified, err := binop.execute(nil); err == nil {
571 return simplified
572 }
573 }
574
575 if (op == OpAnd || op == OpOr) && binop.referencesSpan() {
576 binop.b = newBranchPredictor(2, 1000)
577 }
578
579 return binop
580}
581
582// normalizeTraceIDOperand normalizes a Static operand for trace ID
583func normalizeTraceIDOperand(operand Static) Static {

Callers 13

TestAttributesFunction · 0.85
TestReallyLongQueryFunction · 0.85
TestBinOpFunction · 0.85
ParseMethod · 0.85
TestCompareScalesResultsFunction · 0.85

Calls 5

referencesSpanMethod · 0.95
validateMethod · 0.95
executeMethod · 0.95
normalizeTraceIDOperandFunction · 0.85
newBranchPredictorFunction · 0.85