Hash Functions

This topic describes the hash functions in Graph Lakehouse.

  • HASH32: Returns a 32-bit hash value of a string.
  • MD5: Returns the MD5 checksum as a hexadecimal string.
  • SHA1: Calculates the SHA-1 digest of a value.
  • SHA224: Calculates the SHA-224 digest of a value.
  • SHA256: Calculates the SHA-256 digest of a value.
  • SHA384: Calculates the SHA-384 digest of a value.
  • SHA512: Calculates the SHA-512 digest of a value.

Typographical Conventions

The following list describes the conventions used to document function syntax:

  • CAPS: Although SPARQL is case-insensitive, SPARQL keywords in this section are written in uppercase for readability.
  • [ argument ]: Brackets indicate an optional argument or keyword.
  • |: Means OR. Indicates that you can use one or more of the specified options.

HASH32

This function uses a hash algorithm to encrypt strings and return a 32-bit hash value.

Syntax

HASH32(text)
Argument Type Description
text string The string for which to return a 32-bit hash.

Returns

Type Description
int The 32-bit hash.

MD5

This function returns the MD5 checksum of the specified value as a hexadecimal string.

Syntax

MD5(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to return the MD5 checksum.

Returns

Type Description
string The hexadecimal string.

SHA1

This function calculates the SHA-1 digest of a value.

Syntax

SHA1(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to calculate the SHA-1 digest.

Returns

Type Description
string The SHA-1 digest.

SHA224

This function calculates the SHA-224 digest of a value.

Syntax

SHA224(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to calculate the SHA-224 digest.

Returns

Type Description
string The SHA-224 digest.

SHA256

This function calculates the SHA-256 digest of a value.

Syntax

SHA256(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to calculate the SHA-256 digest.

Returns

Type Description
string The SHA-256 digest.

Example

The example below queries the sample Tickit data set to convert social security and credit card numbers to SHA 256-bit hash values.

SELECT (SHA256(?card) AS ?sha2_card) (SHA256(?ssn) AS ?sha2_ssn)
FROM <http://anzograph.com/tickit>
WHERE {
?person <http://anzograph.com/tickit/ssn> ?ssn ; <http://anzograph.com/tickit/card> ?card . } ORDER BY ?sha2_card LIMIT 10
sha2_card                                          | sha2_ssn
---------------------------------------------------+----------------------------------------------------
000046293f44419e08ddb59b5ce9593c5b14fb80e2e49924d0 | 9cbee8c1c7f8b526ddf6bbe62d5c9ad6c6abdfcc674475a57c
00010cfc90dbc6ce312002ef5072118a772462075b5199caa7 | 7e1f18583d167c6d82fe737650c5aaa3e83350330ed3099f3c
000365bf7e342feaed1a5b2b9ab9d0643570089278af12a242 | 2a79e83495384866ba5520daff432ba3dca6f4a8d18989b0dd
00037e28f93315b2b9a821c93d7261bee1fed421ca7125f0cf | 3ef7706f78662a401e9fa9448d8cbb470f41d65ffbe1b0f8cd
0004740568f42f9eb8ac71a95d672a89895a5331e62d8bd506 | ee48859e41cd3ef64539f0cc09fd377ab18662f6fc31012855
0006406ace683e967a338d41ed04fdcefd8637c50243fa450c | faa394399dea5cc8b56bcb209abe787ec9d2d07d196fa9e270
00091fec35b7b07f881bd56b7a5e96c6da8ceb2f7fc18dc89f | 4fdb3c8afd2281e95cacb16867946ae74fa55f9a8e33143d93
000b33a49dfc953ce1b98de194394dc60498ad94d2d4e168c7 | b822e2758ab80f1866d31981dc883d1b628f1ef90b5ab4ea9a
000b4fa0c93c04a44f230bfb0545d83f9a70ed7e9897d621b3 | ad03804fa16e6de63bcaff1bff1b5754381f80c9d4fb436a05
000b78f1bb238dc1af52bbc30c6947c225274c3d3114e9b9b6 | a28d6b0fe5c2506ce3fd0828cb9d6afd090b68084ea00291f0
10 rows

SHA384

This function calculates the SHA-384 digest of a value.

Syntax

SHA384(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to calculate the SHA-384 digest.

Returns

Type Description
string The SHA-384 digest.

SHA512

This function calculates the SHA-512 digest of a value.

Syntax

SHA512(value)
Argument Type Description
value string, boolean, int, long, float, double, date, time, dateTime The value for which to calculate the SHA-512 digest.

Returns

Type Description
string The SHA-512 digest.