All Products
Search
Document Center

MaxCompute:HASH

Last Updated:Jul 21, 2023

Returns a hash value that is obtained after a hash operation is performed on value1 and value2.

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 and value2: required. These parameters specify the parameters on which you want to perform a hash operation. The parameters can be of different data types. The data types supported in the Hive-compatible data type edition and non-Hive-compatible data type editions are different.

  • Data types supported in the Hive-compatible data type edition: TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DECIMAL, BOOLEAN, STRING, CHAR, VARCHAR, DATETIME, and DATE.

  • Data types supported in non-Hive-compatible data type editions: BIGINT, DOUBLE, BOOLEAN, STRING, and DATETIME.

Note

If the two input parameters are set to the same value, the returned hash values are the same. However, if the two returned hash values are the same, the values of the two input parameters may not be the same, and a hash collision may occur.

Examples

  • Example 1: Calculate the hash value of the input parameters that are of the same data type. Sample statement:

    -- The return value is 66. 
    select hash(0, 2, 4);
  • Example 2: Calculate the hash value of the input parameters that are of different data types. Sample statement:

    -- The return value is 97. 
    select hash(0, 'a');
  • Example 3: An input parameter is left empty or is set to null. Sample statement:

    -- The return value is 0. 
    select hash(0, null);
    -- The return value is 0. 
    select hash(0, '');

Related functions

For more information, see Other functions.