[pkg/ottl]: add bitwise AND (&) and OR (|) operators#46906
Open
57Ajay wants to merge 1 commit intoopen-telemetry:mainfrom
Open
[pkg/ottl]: add bitwise AND (&) and OR (|) operators#4690657Ajay wants to merge 1 commit intoopen-telemetry:mainfrom
57Ajay wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
e58629c to
0b6d66e
Compare
florianl
approved these changes
Mar 17, 2026
Member
florianl
left a comment
There was a problem hiding this comment.
Works fine here and enables interesting options
Signed-off-by: 57Ajay <57ajay.u@gmail.com>
0b6d66e to
617331f
Compare
Contributor
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Contributor
Author
|
Hey, @edmocosta @TylerHelmuth @evan-bradley @bogdandrutu, a gentle reminder if you have some time can you please review this PR. I would love to hear your feedback on this.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds bitwise AND (
&) and OR (|) as native operators in OTTL math expressions, addressing the first part of #45560.These operators enable bitwise flag manipulation directly in OTTL statements without requiring custom converter functions:
Implementation
Bitwise operators are implemented as grammar-level operators, following the same architecture as the existing arithmetic operators (
+,-,*,/).Grammar changes (
grammar.go):OpBitwiseAndandOpBitwiseOrlexer tokensbitwiseAndTerm,opBitwiseAndTerm,bitwiseOrTerm,opBitwiseOrTermAST nodesmathExpressionto route through the new precedence levelsvaluelookahead to include new tokensEvaluation changes (
math.go):evaluateBitwiseOrTermandevaluateBitwiseAndTermevaluation functionsperformBitwiseOpfor int64-only bitwise executionOperator precedence (highest → lowest):
*/+-&|This matches the precedence in Go, C, Java, and Python.
Type constraints
int64. Usingfloat64,time.Time, ortime.Durationreturns an error:"bitwise operations require int64 operands".Testing
math_test.go): 11 new passing tests covering AND, OR, precedence, paths, parentheses, mixed arithmetic+bitwisemath_test.go): 2 new tests verifying float operand rejectionlexer_test.go): 3 new tests for&,|tokens and combined expressionsparser_test.go): existing ASTs updated for new grammar structuree2e/e2e_test.go): 5 new integration tests through the full parser --> evaluator pipelineotelcontribcol, tested with transform processor + OTLP HTTP receiver + debug exporter, all 6 expressions produced correct resultsScope
This PR implements
&and|only. Remaining bitwise operators (^,~,<<,>>) can follow in subsequent PRs once this approach is validated by code owners.