Returns a hash value computed from one or more input values.
Syntax
Syntax for MaxCompute projects that use the Hive-compatible data type edition:
int hash(<value1>, <value2>[, ...]);
Syntax for MaxCompute projects that do not use the Hive-compatible data type edition:
bigint hash(<value1>, <value2>[, ...]);
Parameters
value1, value2: required. The input values to hash. Parameters can be of different data types.
Supported data types vary by edition:
| Edition | Supported data types |
|---|---|
| Hive-compatible | TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DECIMAL, BOOLEAN, STRING, CHAR, VARCHAR, DATETIME, DATE |
| Non-Hive-compatible | BIGINT, DOUBLE, BOOLEAN, STRING, DATETIME |
Returns
Returns int (Hive-compatible edition) or bigint (non-Hive-compatible editions).
Null or empty string inputs return 0.
Usage notes
-
Two identical inputs always produce the same hash value.
-
Two identical hash values do not guarantee identical inputs — hash collisions can occur.
Examples
Same data types:
-- Returns 66
select hash(0, 2, 4);
Different data types:
-- Returns 97
select hash(0, 'a');
Null and empty string inputs:
-- Returns 0
select hash(0, null);
-- Returns 0
select hash(0, '');
What's next
For other built-in functions, see Other functions.
该文章对您有帮助吗?