Built-in Functions Reference¶
Reference documentation for all built-in Cypher functions in CongraphDB.
Overview¶
CongraphDB supports a comprehensive set of built-in functions organized by category:
- String Functions - Text manipulation and formatting
- Aggregation Functions - Data summarization and grouping
- List Functions - List and collection operations
- Math Functions - Mathematical calculations
- Path Functions - Graph path operations
- Temporal Functions - Date and time handling
Function Registry¶
Functions are registered in src/query/evaluator/registry.rs and implemented in src/query/functions/.
Function Trait¶
All functions implement the Function trait:
pub trait Function: Send + Sync {
fn name(&self) -> &str;
fn return_type(&self, arg_types: &[LogicalType]) -> Option<LogicalType>;
fn eval(&self, args: Vec<Value>) -> Result<Value>;
}
String Functions¶
Located in src/query/functions/string.rs.
toString(value)¶
Converts a value to its string representation.
Arguments: value - Any value
Returns: STRING
toLower(string)¶
Converts a string to lowercase.
Arguments: string - STRING
Returns: STRING
toUpper(string)¶
Converts a string to uppercase.
Arguments: string - STRING
Returns: STRING
substring(string, start, length)¶
Extracts a substring from a string.
Arguments:
- string - STRING
- start - INTEGER (0-indexed)
- length - INTEGER
Returns: STRING
trim(string)¶
Removes leading and trailing whitespace.
Arguments: string - STRING
Returns: STRING
replace(string, search, replace)¶
Replaces occurrences of a substring.
Arguments:
- string - STRING
- search - STRING
- replace - STRING
Returns: STRING
split(string, delimiter)¶
Splits a string into a list of substrings.
Arguments:
- string - STRING
- delimiter - STRING
Returns: LIST<STRING>
Aggregation Functions¶
Located in src/query/functions/aggregation.rs.
COUNT(* or expr)¶
Counts the number of rows or non-null values.
MATCH (u:User)
RETURN COUNT(*) AS total_users
MATCH (u:User)
WHERE u.age > 25
RETURN COUNT(u.name) AS named_users
Arguments: * or any expression
Returns: INTEGER
SUM(expr)¶
Returns the sum of numeric values.
Arguments: expr - Numeric expression
Returns: FLOAT or INTEGER
AVG(expr)¶
Returns the average of numeric values.
Arguments: expr - Numeric expression
Returns: FLOAT
MIN(expr)¶
Returns the minimum value.
Arguments: expr - Any comparable expression
Returns: Same type as input
MAX(expr)¶
Returns the maximum value.
Arguments: expr - Any comparable expression
Returns: Same type as input
COLLECT(expr)¶
Collects values into a list.
Arguments: expr - Any expression
Returns: LIST<T> where T is the expression type
List Functions¶
Located in src/query/functions/list_fn.rs.
SIZE(list)¶
Returns the number of elements in a list.
Arguments: list - LIST
Returns: INTEGER
KEYS(node)¶
Returns property names of a node.
Arguments: node - NODE
Returns: LIST<STRING>
LABELS(node)¶
Returns labels of a node.
Arguments: node - NODE
Returns: LIST<STRING>
RANGE(start, end, step)¶
Generates a list of values in a range.
RETURN range(0, 10) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
RETURN range(0, 10, 2) // [0, 2, 4, 6, 8, 10]
Arguments:
- start - INTEGER
- end - INTEGER
- step - INTEGER (optional, default 1)
Returns: LIST<INTEGER>
Math Functions¶
Located in src/query/functions/math.rs.
ABS(value)¶
Returns the absolute value.
Arguments: value - Numeric
Returns: Same type as input
CEIL(value)¶
Rounds up to the nearest integer.
Arguments: value - Numeric
Returns: FLOAT
FLOOR(value)¶
Rounds down to the nearest integer.
Arguments: value - Numeric
Returns: FLOAT
ROUND(value)¶
Rounds to the nearest integer.
Arguments: value - Numeric
Returns: FLOAT
SQRT(value)¶
Returns the square root.
Arguments: value - Numeric (non-negative)
Returns: FLOAT
LOG(value)¶
Returns the natural logarithm.
Arguments: value - Numeric (positive)
Returns: FLOAT
EXP(value)¶
Returns e raised to the power of the value.
Arguments: value - Numeric
Returns: FLOAT
POW(base, exponent)¶
Raises a number to a power.
Arguments:
- base - Numeric
- exponent - Numeric
Returns: FLOAT
Path Functions¶
Located in src/query/functions/path.rs.
shortestPath(start, end, relationship_types, direction) (planned)¶
Finds the shortest path between two nodes.
allShortestPaths(start, end, relationship_types, direction) (planned)¶
Finds all shortest paths between two nodes.
Temporal Functions¶
Located in src/query/functions/temporal.rs.
DATE(string) (planned)¶
Parses a date string.
DATETIME(string) (planned)¶
Parses a datetime string.
TIMESTAMP() (planned)¶
Returns the current Unix timestamp.
DURATION(amount, unit) (planned)¶
Creates a duration.
Custom Functions¶
Custom functions can be registered through the Rust API:
See Also¶
- Query Execution — How functions are executed
- Binder — Function type checking
- Operators — Physical operators