How can I hash a string to a bigint in presto?

Viewed 5349

I have a long string and I would like to semi-uniquely represent it as a bigint. Ideally I'd just take the hash, but presto hash functions seem to want to return "varbinary", and I can't find a function to convert a varbinary into a bigint.

If I write:

cast(xxhash64(cast('asdf' as varbinary)) as bigint)

I get an error saying I can't cast a varbinary to a bigint.

1 Answers

You can use from_big_endian_64 to convert a 64-bit binary value to a bigint:

presto> SELECT from_big_endian_64(xxhash64(CAST('asdf' AS varbinary)));

        _col0
---------------------
 4708639809588864798
(1 row)
Related