-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varbinary bit manipulations #23682
Comments
It would be great if you can send pull requests for the documentation improvements. With regards to the function I think it would be best for @martint to chime in and confirm if this would be okay to implement. If yes, then you could also go ahead and send a PR for that ideally. |
I'd love to contribute! I may be able to work on this in November. Can you point me where are the docs and bitwise implementation, in the meantime? |
Look at BitwiseFunctions.java in io.trino.operator.scalar |
The open question is how these functions are meant to work if the both varbinary have different lengths, i.e. 000011 & 0010100000 |
We should add support for varbinary, but I would start conservatively and disallow varbinaries of different lengths. We can expand later. In particular, we're going to have to look into how SQL does conversions between |
tl;dr: can
bitwise_*
functions be overloaded tovarbinary
types?I wanted to generate an UUIDv4 from the first 128 bits of the output of a SHA256 hash. This requires some bit manipulations according to RFC4122:
To accomplish that with Trino, I managed to do the following:
bitwise_and
andbitwise_or
to reset the affected bits, and then set the desired values.The reason to use 32 bits within a 64-bit integer is to be able to set the MSB, perhaps because hexadecimals are always considered positive? In the commented code below is my attempt to use full 64 bits, which fails because the MSB is set on the integer literals.
This is the result
I wish
bitwise_and
andbitwise_or
were available to varbinary types, so this could have been onlySome more feature requests I surfaced from this exercise:
_
as a separator, to mirror numeric literals. It was just a guess that space was accepted within the string, because it's not included in the docsThe text was updated successfully, but these errors were encountered: