Skip to content

Conversation

asauzeau
Copy link

@asauzeau asauzeau commented Sep 9, 2025

Summary

Add AND (&), OR (^) and NOT (~) bitwise operators. See #1386.

'|' token was already used for the merge operator so I chose another token for the not operator, but it's not ideal since it's usually used for XOR operator.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Tests are included.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on
    our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Our CONTRIBUTING.md is a good starting place.
  • If this PR introduces changes to LICENSE-3rdparty.csv, please
    run dd-rust-license-tool write and commit the changes. More details here.
  • For new VRL functions, please also create a sibling PR in Vector to document the new function.

@asauzeau asauzeau requested a review from a team as a code owner September 9, 2025 21:05
Signed-off-by: Antoine Sauzeau <[email protected]>
encode_base64("please encode me")
encode_base64(encode_gzip("please encode me"))
encode_base64(encode_gzip("please encode me"))
15 & 20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition. Did you have a chance to run the fuzzer as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I tested it for about ten minutes and didn't experience any crashes. I'll try to run it longer.

@pront
Copy link
Member

pront commented Sep 10, 2025

'|' token was already used for the merge operator so I chose another token for the not operator, but it's not ideal since it's usually used for XOR operator.

Did you mean you chose ^ for the OR operator? We want to reserve ^ as the XOR operator.

I don't see an easy solution around this. Perhaps we could replace | with something like ++ and then use | for OR but that is a multi-step process. Ideally we would also provide a script for users to update their programs.

@asauzeau
Copy link
Author

Okay indeed, it seems like a good idea to rename the merge operator using ++, so that | can later be reused for the bitwise OR operator, allowing us to keep ^ for the XOR operator.

So I'm I supposed to follow the cycle of this document and for now just “depreciate” the merge operator | and indicate that it will be renamed ++ in a future release?

Ideally we would also provide a script for users to update their programs.

Good idea.

@pront
Copy link
Member

pront commented Sep 12, 2025

So I'm I supposed to follow the cycle of this document and for now just “depreciate” the merge operator | and indicate that it will be renamed ++ in a future release?

Yes, that sounds like a reasonable plan. This reminds me we need a similar policy that lives in the VRL repo. BTW, I mentioned ++ because it seems like a natural fit, but didn't think too hard. There might be an even better option.

@asauzeau
Copy link
Author

BTW, I mentioned ++ because it seems like a natural fit, but didn't think too hard. There might be an even better option.

Initially I had in mind <> as an alternative, but that might be less intuitive. If there are no plans to add increment and decrement operators, I also think we could opt for ++ for the merge operator.

@pront
Copy link
Member

pront commented Sep 15, 2025

Hmm, on one hand ++ seems a natural candidate for those who come from Scala/Haskell, on the other hand, I cannot rule out introducing increment/decrement by 1 later. Let's do <>.

We could also have <<< right-biases merge and >>> left-biased merge.

@sbalmos
Copy link
Contributor

sbalmos commented Sep 27, 2025

Just randomly reviewing the issue list here... Might I suggest .+ for the merge operator instead? This would sort of keep convention with . being the object path accessor. More importantly, <> is a historical alternative for !=, namely in Microsoft languages (SQL Server SQL, VB, etc).

It also occurs to me that the current merge-assign operator, |=, would also need to change, which leads me to suggest .=. That pattern is at least known in a few languages for element/field-level merging. Admittedly it's more well-known in some languages for string concatenation. But precedent is there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants