Support Questions

Find answers, ask questions, and share your expertise

Hive: hash function unique values

avatar
Expert Contributor

Hi,

Can someone confirm if the hash function would always result with unique integer value, say even for millions of unique account numbers, and the same number would not repeat again?

1 ACCEPTED SOLUTION

avatar
Expert Contributor

Depends on what arguments you are providing to the hash function. If your argument values are unique, you would most likely get unique value from hash. Keep in mind hive hash function return int (which is 32bit) so you may see -ve numbers as well. You can use something like reflect('java.util.UUID','randomUUID') to generate uniqueID or comeup with some unique code. I would not suggest using hash function, if you want to generate unique ids.

View solution in original post

1 REPLY 1

avatar
Expert Contributor

Depends on what arguments you are providing to the hash function. If your argument values are unique, you would most likely get unique value from hash. Keep in mind hive hash function return int (which is 32bit) so you may see -ve numbers as well. You can use something like reflect('java.util.UUID','randomUUID') to generate uniqueID or comeup with some unique code. I would not suggest using hash function, if you want to generate unique ids.