hash()

Returns a hash value for the input value.

Syntax

hash(source [, mod])

Arguments

  • source: The value to be hashed.
  • mod: An optional modulo value to be applied to the hash result, so that the output value is between 0 and mod - 1

Returns

The hash value of source. If mod is specified, the function returns the hash value modulo the value of mod.

Warning

The function uses the xxhash64 algorithm to calculate the hash for each scalar, but this may change. We therefore only recommend using this function within a single query where all invocations of the function will use the same algorithm.

If you need to persist a combined hash, we recommend using hash_sha256(), hash_sha1(), or hash_md5() and combining the hashes into a single hash with a bitwise operator. 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

You can use the hash() function for sampling data if the values in one of its columns are uniformly distributed. In the following example, StartTime values are uniformly distributed and the function is used to run a query on 10% of the data.

StormEvents 
| where hash(StartTime, 10) == 0
| summarize StormCount = count(), TypeOfStorms = dcount(EventType) by State 
| top 5 by StormCount desc