UDF Builders

Foreground UDF execution builders (single-key, batch, and chained operations).

class aerospike_sdk.aio.operations.udf.UdfFunctionBuilder[source]

Bases: object

First step of foreground UDF chaining: choose package and Lua function name.

Produced by execute_udf() or UdfBuilder.execute_udf(). Call function() before UdfBuilder.passing() or execute().

Example:

stream = await (
    session.execute_udf(key)
        .function("my_module", "my_func")
        .execute()
)
__init__(qb)[source]
function(package, function_name)[source]

Select the registered module and function to invoke.

Parameters:
  • package (str) – Server-side module name (no .lua suffix).

  • function_name (str) – Lua function symbol exported by the module.

Return type:

UdfBuilder

Returns:

UdfBuilder for arguments and execution.

Raises:

ValueError – If package or function_name is empty.

class aerospike_sdk.aio.operations.udf.UdfBuilder[source]

Bases: object

Supply UDF arguments, optional filter, then execute or chain another operation.

After UdfFunctionBuilder.function(), call passing() with values passed to Lua (after the implicit record argument). Use execute_udf() to append another UDF segment, or query() / write verbs to switch operation type. Await execute() to run the accumulated chain.

Example:

stream = await (
    session.execute_udf(key)
        .function("my_pkg", "my_func")
        .passing(1, "x")
        .execute()
)

See also

execute_udf(): Entry point.

__init__(qb)[source]
passing(*args)[source]

Set positional arguments forwarded to the Lua function.

The Aerospike server automatically passes the record as the first argument to the UDF; values provided here follow it.

Parameters:

*args (Any) – Values serialized by the async client (scalars, lists, maps, bytes).

Return type:

UdfBuilder

Returns:

This builder for chaining.

Example::

builder.passing(“binName”, 42)

where(expression)[source]
Overloads:
  • self, expression (str) → UdfBuilder

  • self, expression (FilterExpression) → UdfBuilder

Apply a filter expression so the UDF runs only when the predicate matches.

Parameters:

expression (Union[str, FilterExpression]) – AEL string or FilterExpression.

Returns:

This builder for chaining.

See also

QueryBuilder.where(): Same AEL for reads.

respond_all_keys()[source]

For batch UDF, emit a row per requested key (including not-found).

Return type:

UdfBuilder

Returns:

This builder for chaining.

See also

QueryBuilder.respond_all_keys(): Same flag for reads.

execute_udf(*keys)[source]

Finalize this UDF operation and start another on keys.

Parameters:

*keys (Key) – One or more keys for the next UDF segment.

Return type:

UdfFunctionBuilder

Returns:

A new UdfFunctionBuilder to call function() again.

Raises:

ValueError – If no keys are provided.

query(arg1, *more_keys)[source]

Close the UDF operation and begin a read QueryBuilder segment.

Parameters:
  • arg1 (Union[Key, List[Key]]) – One key or a list of keys.

  • *more_keys (Key) – Additional keys when arg1 is a single key.

Return type:

QueryBuilder

Returns:

QueryBuilder for chaining.

upsert(arg1, *more_keys)[source]

Finalize the UDF operation and start an upsert WriteSegmentBuilder.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

insert(arg1, *more_keys)[source]

Finalize the UDF operation and start an insert-only write segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

update(arg1, *more_keys)[source]

Finalize the UDF operation and start an update-only write segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

replace(arg1, *more_keys)[source]

Finalize the UDF operation and start a replace write segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

replace_if_exists(arg1, *more_keys)[source]

Finalize the UDF operation and start a replace-if-exists segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

delete(arg1, *more_keys)[source]

Finalize the UDF operation and start a delete segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

touch(arg1, *more_keys)[source]

Finalize the UDF operation and start a touch segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

exists(arg1, *more_keys)[source]

Finalize the UDF operation and start an exists-check segment.

Return type:

WriteSegmentBuilder

Returns:

WriteSegmentBuilder for chaining.

async execute(on_error=None)[source]

Run the current builder state and return a RecordStream.

Requires function() to have been called for the pending UDF operation.

Parameters:

on_error (Union[ErrorStrategy, Callable[[Key, int, AerospikeError], None], None]) – Same as QueryBuilder.execute().

Return type:

RecordStream

Returns:

Stream of per-key results and optional udf_result fields.

Example:

stream = await (
    session.execute_udf(k1, k2)
        .function("pkg", "fn")
        .execute()
)
Raises:

ValueError – If no UDF function was selected before execute.