HASH
Calculates a hash value for value1, value2, and so on.
Command format
If your MaxCompute project is in Hive-compatible mode, use the following format.
int hash(<value1>, <value2>[, ...]);If your MaxCompute project is not in Hive-compatible mode, use the following format.
bigint hash(<value1>, <value2>[, ...]);
Parameters
value1, value2, ...: Required. The input parameters for which a hash value is calculated. These parameters can have different data types. The supported data types vary depending on whether your project is in Hive-compatible mode:
Hive-compatible mode: TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DECIMAL, BOOLEAN, STRING, CHAR, VARCHAR, DATETIME, and DATE.
Non-Hive-compatible mode: BIGINT, DOUBLE, BOOLEAN, STRING, and DATETIME.
The same input values always produce the same hash value. However, the same hash value does not guarantee that the input values are the same, because hash collisions can occur.
Usage examples
Example 1: Calculate the hash value for input parameters that have the same data type.
--Returns 66. select hash(0L, 2L, 4L);Example 2: Calculate the hash value for input parameters that have different data types. This example is for Hive-compatible mode. For non-Hive-compatible mode, use the BIGINT type for integers.
--Returns 97. select hash(0L, 'a');Example 3: One of the input parameters is empty or NULL.
--Returns 0. select hash(0L, null); --Returns 0. select hash(0L, '');
Related functions
The HASH function is classified as a miscellaneous function. For more functions for other business scenarios, see Other functions.