AQL Functions

Karango wraps the AQL standard library as Kotlin DSL functions. Each function is type-checked at compile time and emits the matching AQL call at runtime.

Use them inside any query block — FILTER, LET, RETURN, etc. Names match the AQL spec one-to-one (uppercase), so the official AQL reference applies directly.

Numeric

Function Description
ABS(value)Absolute value of a number
CEIL(value)Smallest integer not less than the value
FLOOR(value)Largest integer not greater than the value
ROUND(value)Integer closest to the value
POW(base, exp)Base raised to the given exponent
SQRT(value)Square root of the value
EXP(value)Euler's constant raised to the value
EXP2(value)2 raised to the value
LOG(value)Natural logarithm
LOG2(value)Base-2 logarithm
LOG10(value)Base-10 logarithm
SIN(value)Sine of the value (radians)
COS(value)Cosine of the value (radians)
TAN(value)Tangent of the value (radians)
ASIN(value)Arcsine of the value
ACOS(value)Arccosine of the value
ATAN(value)Arctangent of the value
ATAN2(x, y)Arctangent of y / x
DEGREES(value)Convert radians to degrees
RADIANS(value)Convert degrees to radians
PI()Constant π (3.14159…)
RAND()Pseudo-random number in [0, 1)
RANGE(start, stop) / RANGE(start, stop, step)Array of numbers in a range
SUM(numArray)Sum of array values
AVERAGE(numArray) / AVG(numArray)Arithmetic mean
MEDIAN(numArray)Median value
MIN(array)Smallest array element
MAX(array)Greatest array element
PERCENTILE(numArray, n) / PERCENTILE(numArray, n, method)n-th percentile
STDDEV(value) / STDDEV_POPULATION(value)Population standard deviation
STDDEV_SAMPLE(value)Sample standard deviation
VARIANCE(value) / VARIANCE_POPULATION(value)Population variance
VARIANCE_SAMPLE(value)Sample variance

String

Function Description
LENGTH(expr)Character length of a string
CHAR_LENGTH(expr)Number of characters (not bytes)
CONCAT(first, rest…)Concatenate strings
CONCAT_SEPARATOR(sep, first, rest…)Concatenate strings with a separator
CONTAINS(haystack, needle)Substring contained in another string (case-sensitive)
STARTS_WITH(text, prefix)String starts with a prefix
LIKE(text, search) / LIKE(text, search, caseInsensitive)SQL-style wildcard match
FIND_FIRST(haystack, needle, …)Position of the first occurrence
FIND_LAST(haystack, needle, …)Position of the last occurrence
SUBSTRING(value, offset) / SUBSTRING(value, offset, length)Substring at offset
LEFT(expr, n)N leftmost characters
RIGHT(value, n)N rightmost characters
LOWER(expr)Convert to lower case
UPPER(expr)Convert to upper case
TRIM(subject) / TRIM(subject, chars)Strip whitespace (or chars) from both ends
LTRIM(subject, …)Strip from the start
RTRIM(subject, …)Strip from the end
SPLIT(value, separator, …)Split a string into an array
SOUNDEX(value)Soundex fingerprint of a string
LEVENSHTEIN_DISTANCE(left, right)Edit distance between two strings
ENCODE_URI_COMPONENT(value)URI-encode a string
TO_BASE64(value)Base-64 representation of a string
TO_HEX(value)Hexadecimal representation of a string

Regex

Function Description
REGEX_TEST(text, regex, …)Test whether a regex matches
REGEX_MATCHES(text, regex, …)Return all matches
REGEX_SPLIT(text, regex, …)Split a string by regex

Array

Function Description
COUNT(expr)Number of elements (alias of LENGTH)
COUNT_DISTINCT(anyArray) / COUNT_UNIQUE(anyArray)Number of distinct elements
FIRST(anyArray)First element
LAST(anyArray)Last element
NTH(anyArray, position)Element at a position
POSITION(anyArray, search)Index of a value, or -1
CONTAINS_ARRAY(anyArray, search)Whether a value is in the array
CONTAINS_ARRAY_IDX(anyArray, search)Index of value in the array, or -1
APPEND(anyArray, values, …)Append all elements of one array to another
PUSH(anyArray, value, …)Append a single value
UNSHIFT(anyArray, value, …)Prepend a single value
POP(anyArray)Remove the last element
SHIFT(anyArray)Remove the first element
REMOVE_NTH(anyArray, position)Remove element at a position
REMOVE_VALUE(anyArray, value, …)Remove occurrences of a single value
REMOVE_VALUES(anyArray, values)Remove all occurrences of any of the values
SLICE(anyArray, start, …)Extract a slice
REVERSE(anyArray)Reverse the order of elements
SORTED(anyArray)Sort using default comparison
SORTED_UNIQUE(anyArray)Sort and remove duplicates
UNIQUE(anyArray)Distinct elements (preserves order)
FLATTEN(anyArray, …)Flatten nested arrays
UNION(arr1, arr2, …)Union of arrays (preserves duplicates)
UNION_DISTINCT(arr1, arr2, …)Union of arrays (distinct values)
INTERSECTION(arr1, arr2, …)Values present in all arrays
OUTERSECTION(arr1, arr2, …)Values present in only one array
MINUS(arr1, arr2, …)Difference of arrays

Document

Function Description
DOCUMENT(id)Get a single document by full id
DOCUMENT(collection, id)Get a document from a collection by key
DOCUMENT(cls, id)Get a document and deserialize to a Kotlin class
DOCUMENT(ids) / DOCUMENT(collection, ids)Get multiple documents at once
DOCUMENT(type, collection, ids)Get multiple documents with explicit type
MERGE(doc1, doc2, …)Merge documents into one
UNSET(document, attr1, …)Return a copy of the document without given attributes

Type checks

Function Description
IS_NULL(expr)Value is null
IS_NOT_NULL(expr)Value is not null
IS_BOOL(expr)Value is a boolean
IS_NUMBER(expr)Value is a number
IS_STRING(expr)Value is a string
IS_ARRAY(expr) / IS_LIST(expr)Value is an array
IS_OBJECT(expr) / IS_DOCUMENT(expr)Value is an object / document
IS_DATESTRING(expr)Value is a parseable date string
IS_KEY(expr)Value is a valid document key
TYPENAME(expr)Type name ("null", "bool", "number", …)

Type conversion

Function Description
TO_BOOL(expr)Convert to boolean
TO_NUMBER(expr)Convert to number
TO_STRING(expr)Convert to string
TO_ARRAY(expr) / TO_LIST(expr)Convert to array

JSON

Function Description
JSON_PARSE(expr)Parse a JSON-encoded string into an AQL value
JSON_STRINGIFY(expr)Serialize an AQL value to a JSON string

Hash & tokens

Function Description
MD5(value)MD5 checksum as hex string
SHA1(value)SHA-1 checksum as hex string
SHA512(value)SHA-512 checksum as hex string
RANDOM_TOKEN(length)Random token of the given length
UUID()Universally unique identifier

Logical

Function Description
NOT(expr)Boolean negation

Missing a function you need? AQL has more — wrappers are added as use cases come up. Open an issue or PR on GitHub.