UltipaDocs
Try Playground
  • Quick Start
  • Procedure Management
  • Parameters and Types
  • Control Flow
  • Data Operations
  • Iterators and Traversal
  • Parallel Execution
  • Built-in Functions
  • Expressions
  • Algorithm Examples
  1. Docs
  2. /
  3. Stored Procedures

Built-in Functions

Complete reference for all procedure-specific built-in functions.

Topology Functions

O(1) lookups from the compute engine's topology.

FunctionReturnDescription
OUT_DEGREE(node)INTEGEROut-degree of a node
IN_DEGREE(node)INTEGERIn-degree of a node
NODE_COUNT()INTEGERTotal number of nodes in the graph
Procedure Body Language
LET deg = OUT_DEGREE(node)      -- O(1) lookup
LET in_deg = IN_DEGREE(node)    -- O(1) lookup
LET n = NODE_COUNT()            -- Total nodes

Requirement: These functions require the compute engine (ALTER GRAPH <graph_name> SET COMPUTE ENABLED). Without it, they return 0.

Neighbor Aggregation Functions

Direct neighbor operations that eliminate per-neighbor interpreter overhead. These are the key optimizations for iterative graph algorithms.

FunctionReturnDescription
SUM_OUT_NEIGHBOR_PROP(node, propName)FLOATSum of outgoing neighbors' property
SUM_IN_NEIGHBOR_PROP(node, propName)FLOATSum of incoming neighbors' property
OUT_NEIGHBOR_SUM(node, propName)FLOATFor each out-neighbor, sums property / out_degree
IN_NEIGHBOR_SUM(node, rankProp, degreeProp)FLOATFor each in-neighbor, sums rankProp / degreeProp
MIN_OUT_NEIGHBOR_PROP(node, propName, initVal)FLOATMinimum of outgoing neighbors' property
MIN_IN_NEIGHBOR_PROP(node, propName, initVal)FLOATMinimum of incoming neighbors' property
MIN_BOTH_NEIGHBOR_PROP(node, propName, initVal)FLOATMinimum across both directions

PageRank contribution (sum of rank/degree from in-neighbors):

Procedure Body Language
LET contrib = IN_NEIGHBOR_SUM(node, 'rank', 'out_degree')

HITS authority update (sum of hub scores from in-neighbors):

Procedure Body Language
LET new_auth = SUM_IN_NEIGHBOR_PROP(node, 'hub')

Connected components (minimum component ID among all neighbors):

Procedure Body Language
LET min_comp = MIN_BOTH_NEIGHBOR_PROP(node, 'component', current_comp)

SSSP relaxation (minimum distance from outgoing neighbors):

Procedure Body Language
LET min_dist = MIN_OUT_NEIGHBOR_PROP(node, 'distance', current_dist)

Slice Property Functions

High-performance per-node value storage backed by contiguous arrays.

FunctionReturnDescription
INIT_SLICE_PROP(name, value)-Initialize all nodes with a value
GET_SLICE_PROP(idx, name)ValueGet value by internal node ID
SET_SLICE_PROP(idx, name, value)-Set value by internal node ID
COPY_SLICE_PROP(src, dst)-Copy all values from source to destination
INIT_OUT_DEGREES(name)-Initialize slice with out-degrees

See Parallel Execution for detailed usage.

Parallel Reduction Functions

Aggregate operations over slice properties with automatic parallelization.

FunctionReturnDescription
SUM_SLICE_PROP(propName)FLOATParallel sum of all values
SUM_SLICE_PROP_SQ(propName)FLOATParallel sum of squares (for L2 norm)
MAX_SLICE_PROP(propName)FLOATParallel maximum
MIN_SLICE_PROP(propName)FLOATParallel minimum
Procedure Body Language
-- L2 normalization
LET norm = SQRT(SUM_SLICE_PROP_SQ('score'))
PARALLEL FOR node IN SCAN() WORKERS 8 {
    LET val = GET_SLICE_PROP(node._internal_id, 'score')
    SET_SLICE_PROP(node._internal_id, 'score', val / norm)
}

-- Get value range
LET max_val = MAX_SLICE_PROP('rank')
LET min_val = MIN_SLICE_PROP('rank')

Set Operations

Hash-based O(n) set operations on lists.

FunctionReturnDescription
INTERSECT(listA, listB)LISTA ∩ B
UNION(listA, listB)LISTA ∪ B
DIFFERENCE(listA, listB)LISTA - B
SIZE(collection)INTEGERSize of list, map, or string
Procedure Body Language
LET friends_a = NEIGHBORS(a, OUT, :KNOWS)
LET friends_b = NEIGHBORS(b, OUT, :KNOWS)

LET common = INTERSECT(friends_a, friends_b)
LET all_friends = UNION(friends_a, friends_b)
LET only_a = DIFFERENCE(friends_a, friends_b)
LET count = SIZE(common)

Common Neighbor Functions

Optimized functions using the topology accelerator.

FunctionReturnDescription
COMMON_NEIGHBORS(nodeA, nodeB)LISTList of common neighbors
COUNT_COMMON_NEIGHBORS(nodeA, nodeB)INTEGERCount of common neighbors
JACCARD_SIMILARITY(nodeA, nodeB)FLOAT|A ∩ B| / |A ∪ B|
ADAMIC_ADAR(nodeA, nodeB)FLOATΣ 1/log(degree(c)) for common neighbors c
Procedure Body Language
LET common = COMMON_NEIGHBORS(node_a, node_b)
LET count = COUNT_COMMON_NEIGHBORS(node_a, node_b)
LET similarity = JACCARD_SIMILARITY(node_a, node_b)
LET aa_score = ADAMIC_ADAR(node_a, node_b)

Map Operations

O(1) lookup map operations for external data integration.

FunctionReturnDescription
LIST_TO_MAP(list, keyIndex)MAPConvert list of lists to map
LIST_TO_GROUPED_MAP(list, keyIndex)MAPGroup entries by key
MAP_GET(map, key [, default])ValueGet value from map

LIST_TO_MAP

Converts a list of lists to a map using the element at keyIndex as the key. Duplicate keys are overwritten (last wins).

Procedure Body Language
-- Input: [[sku, name, price], ...]
LET productMap = LIST_TO_MAP($productData, 0)  -- key by sku (index 0)

LET record = MAP_GET(productMap, 'SKU123')
-- record is [sku, name, price] or NULL

LIST_TO_GROUPED_MAP

Like LIST_TO_MAP but groups all entries with the same key into a list:

Procedure Body Language
-- Input: [[rate_code, rate, date], ...]
LET rateMap = LIST_TO_GROUPED_MAP($rateData, 0)  -- group by rate_code

LET rates = MAP_GET(rateMap, 'PRIME')
-- rates is [[code, rate1, date1], [code, rate2, date2], ...]

MAP_GET

Procedure Body Language
LET value = MAP_GET(myMap, 'key')           -- returns NULL if not found
LET value = MAP_GET(myMap, 'key', 0.0)      -- returns 0.0 if not found

Batch Operations

High-throughput batch operations for data enrichment.

FunctionReturnDescription
BATCH_MAP_TO_SLICE(map, nodePropName, slicePropName, valueIndex)-Batch map lookups by node property
BATCH_SLICE_MAP_TO_SLICE(map, srcSlice, dstSlice, valueIndex)-Batch lookups from slice to slice
Procedure Body Language
-- Enrich all nodes: lookup each node's 'sku' in map, extract price (index 2)
LET productMap = LIST_TO_MAP($productData, 0)
BATCH_MAP_TO_SLICE(productMap, 'sku', 'price', 2)

Batch Persistence

FunctionReturnDescription
BATCH_PERSIST_SLICE(sliceName, propName)-Persist one slice to storage
BATCH_PERSIST_SLICES(s1, p1, s2, p2, ...)-Persist multiple in one pass
BATCH_SLICE_ADD(sliceName, value)-Add constant to all slice values

Batch Insert

FunctionReturnDescription
BATCH_INSERT_NODES(label, dataList)-Bulk insert nodes
BATCH_INSERT_EDGES(edgeType, dataList)-Bulk insert edges

List Operations

FunctionReturnDescription
APPEND(list, item)LISTAppend item to list (also LIST_APPEND)

Type Conversion

FunctionAliasesDescription
TOSTRING(value)TOSTRConvert to string
TOINTEGER(value)TOINTConvert to integer
TOFLOAT(value)TODOUBLEConvert to float

Math Functions

FunctionAliasesDescription
ABS(x)—Absolute value
CEIL(x)CEILINGRound up
FLOOR(x)—Round down
ROUND(x)—Round to nearest
SQRT(x)—Square root
POW(x, y)POWERx raised to power y
MIN(a, b)—Minimum of two values
MAX(a, b)—Maximum of two values

String Functions

FunctionAliasesDescription
SUBSTRING(str, start, len)SUBSTRExtract substring
LENGTH(str)LENString length

Utility Functions

FunctionDescription
COALESCE(a, b, ...)Return first non-NULL value
IF(condition, then, else)Inline conditional
TIMESTAMP_MS()Current time in milliseconds
DATE_DIFF(date1, date2)Difference between dates (also DATEDIFF)
Procedure Body Language
LET name = COALESCE(node.nickname, node.name, 'Unknown')
LET status = IF(score > 0.5, 'high', 'low')
LET now = TIMESTAMP_MS()

Standard GQL Functions

In addition to the procedure-specific functions above, all standard GQL functions are also available inside procedure bodies, such as:

  • String: UPPER, LOWER, TRIM, SPLIT, STARTSWITH, ENDSWITH, CONTAINS
  • Math: LOG, SIN, COS, TAN, RAND
  • Aggregate: COUNT, SUM, AVG
  • Type: TYPEOF, LABELS
  • List: HEAD, TAIL, REVERSE, RANGE
  • Date/Time: DATE, TIME, DATETIME, DURATION

If a function is not recognized as a procedure-specific built-in, it is looked up in the standard GQL function registry. An error is returned if the function name is not found in either.