问题描述
理想情况下,我正在寻找SHA512 / SHA256哈希,类似于什么样的哈希算法sha()函数在linkedin中为Pig提供了datafu UDF。
HASH
函数(自Hive 0.11开始)使用类似于):
我离题了。您可以查看 HASH
来源。
如果您想在Hive中使用SHAxxx,那么您可以使用Apache 类和Hive内置反映
函数(我希望这会起作用):
SELECT反射('org.apache.commons.codec.digest.DigestUtils','sha256Hex','your_string')
What kind of hashing algorithm is used in the built-in HASH() function?
I'm ideally looking for a SHA512/SHA256 hash, similar to what the SHA() function offers within the linkedin datafu UDFs for Pig.
HASH
function (as of Hive 0.11) uses algorithm similar to java.util.List#hashCode.
Its code looks like this:
int hashCode = 0; // Hive HASH uses 0 as the seed, List#hashCode uses 1. I don't know why.
for (Object item: items) {
hashCode = hashCode * 31 + (item == null ? 0 : item.hashCode());
}
Basically it's a classic hash algorithm as recommended in the book Effective Java.To quote a great man (and a great book):
I digress. You can look at the HASH
source here.
If you want to use SHAxxx in Hive then you can use Apache DigestUtils class and Hive built-in reflect
function (I hope that'll work):
SELECT reflect('org.apache.commons.codec.digest.DigestUtils', 'sha256Hex', 'your_string')
这篇关于Hive的内置HASH()函数使用了什么样的散列算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!