hash()hash()
返回输入值的哈希值。Returns a hash value for the input value.
语法Syntax
hash(
source [,
mod ])
hash(
source [,
mod ])
参数Arguments
- source :要进行哈希处理的值。source : The value to be hashed.
- mod:一个可选模块值,在应用于哈希结果后输出值将在
0
到 mod - 1 之间mod : An optional module value to be applied to the hash result, so that the output value is between0
and mod - 1
返回Returns
给定标量的哈希值,对给定 mod 值(如果已指定)取模。The hash value of the given scalar, modulo the given mod value (if specified).
警告
用于计算哈希的算法是 xxhash。The algorithm used to calculate the hash is xxhash.
此算法将来可能会更改,唯一的保证是:在单个查询中,对这个方法的所有调用都使用相同的算法。This algorithm might change in the future, and the only guarantee is that within a single query all invocations of this method use the same algorithm.
因此,建议不要将 hash()
的结果存储在表中。Consequently, you are advised not to store the results of hash()
in a table. 如果需要持久化哈希值,请改用 hash_sha256() 或 hash_md5()。If persisting hash values is required, use hash_sha256() or hash_md5() instead. 请注意,计算这些函数比 hash()
更复杂。Note that these functions are more complex to calculate than hash()
).
示例Examples
hash("World") // 1846988464401551951
hash("World", 100) // 51 (1846988464401551951 % 100)
hash(datetime("2015-01-01")) // 1380966698541616202
下面的示例使用哈希函数对 10% 的数据运行查询。假设值是均匀分布的(在本示例中,值为 StartTime 值),则使用哈希函数对数据采样很有帮助。The following example uses the hash function to run a query on 10% of the data, It is helpful to use the hash function for sampling the data when assuming the value is uniformly distributed (In this example StartTime value)
StormEvents
| where hash(StartTime, 10) == 0
| summarize StormCount = count(), TypeOfStorms = dcount(EventType) by State
| top 5 by StormCount desc