Utility Functions

util.compress()

Compress data using gzip or deflate.

Syntax: util.compress(data, [algorithm])

Parameters:

Parameter Type Description

data

String

String data to compress

algorithm

String

Optional - "gzip" (default) or "deflate"

Returns: String - Base64-encoded compressed data

APOC Compatible: apoc.util.compress


util.decompress()

Decompress base64-encoded compressed data.

Syntax: util.decompress(data, [algorithm])

Returns: String - Decompressed string

APOC Compatible: apoc.util.decompress

WITH util.compress("Hello World!") AS compressed
RETURN util.decompress(compressed) AS original
// Returns: "Hello World!"

util.md5()

Compute MD5 hash of a value.

Syntax: util.md5(value)

Returns: String - MD5 hash (32 hex characters)

APOC Compatible: apoc.util.md5

RETURN util.md5("hello") AS hash
// Returns: "5d41402abc4b2a76b9719d911017c592"

util.sha1()

Compute SHA-1 hash of a value.

Syntax: util.sha1(value)

Returns: String - SHA-1 hash (40 hex characters)

APOC Compatible: apoc.util.sha1


util.sha256()

Compute SHA-256 hash of a value.

Syntax: util.sha256(value)

Returns: String - SHA-256 hash (64 hex characters)

APOC Compatible: apoc.util.sha256

RETURN util.sha256("hello") AS hash
// Returns: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"

util.sha512()

Compute SHA-512 hash of a value.

Syntax: util.sha512(value)

Returns: String - SHA-512 hash (128 hex characters)

APOC Compatible: apoc.util.sha512


util.sleep()

Pause execution for a specified time.

Syntax: util.sleep(milliseconds)

Returns: Boolean - true after sleep

APOC Compatible: apoc.util.sleep


util.validate()

Validate a condition and throw an error if false.

Syntax: util.validate(predicate, message)

Returns: Boolean - true if validation passes

APOC Compatible: apoc.util.validate

RETURN util.validate(1 > 0, "Value must be positive") AS valid
// Returns: true

RETURN util.validate(false, "This will throw!") AS valid
// Throws: IllegalArgumentException with message "This will throw!"