我正在尝试向数据框中添加一列,其中将包含 另一列的哈希 .
我找到了这段文档:
https://spark.apache.org/docs/2.3.0/api/sql/index.html#hash
并尝试了这个:
import org.apache.spark.sql.functions._
val df = spark.read.parquet(...)
val withHashedColumn = df.withColumn("hashed", hash($"my_column"))
但是
hash()
使用的哈希函数是什么? ?是murmur
, sha
, md5
,还有什么?我在此列中得到的值是整数,因此这里的值范围可能是
[-2^(31) ... +2^(31-1)]
.我可以在这里获得长期值(value)吗?我可以得到一个字符串哈希吗?
如何为此指定具体的哈希算法?
我可以使用自定义哈希函数吗?
最佳答案
它是基于 source code 的杂音:
/**
* Calculates the hash code of given columns, and returns the result as an int column.
*
* @group misc_funcs
* @since 2.0.0
*/
@scala.annotation.varargs
def hash(cols: Column*): Column = withExpr {
new Murmur3Hash(cols.map(_.expr))
}
关于scala - spark中的哈希函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634650/