UDF Builders¶
Foreground UDF execution builders (single-key, batch, and chained operations).
- class aerospike_sdk.aio.operations.udf.UdfFunctionBuilder[source]¶
Bases:
objectFirst step of foreground UDF chaining: choose package and Lua function name.
Produced by
execute_udf()orUdfBuilder.execute_udf(). Callfunction()beforeUdfBuilder.passing()orexecute().Example:
stream = await ( session.execute_udf(key) .function("my_module", "my_func") .execute() )
- function(package, function_name)[source]¶
Select the registered module and function to invoke.
- Parameters:
- Return type:
- Returns:
UdfBuilderfor arguments and execution.- Raises:
ValueError – If
packageorfunction_nameis empty.
- class aerospike_sdk.aio.operations.udf.UdfBuilder[source]¶
Bases:
objectSupply UDF arguments, optional filter, then execute or chain another operation.
After
UdfFunctionBuilder.function(), callpassing()with values passed to Lua (after the implicit record argument). Useexecute_udf()to append another UDF segment, orquery()/ write verbs to switch operation type. Awaitexecute()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.- 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:
- 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 orFilterExpression.- 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:
- 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:
- Returns:
A new
UdfFunctionBuilderto callfunction()again.- Raises:
ValueError – If no keys are provided.
- query(arg1, *more_keys)[source]¶
Close the UDF operation and begin a read
QueryBuildersegment.- Parameters:
arg1 (
Union[Key,List[Key]]) – One key or a list of keys.*more_keys (
Key) – Additional keys whenarg1is a single key.
- Return type:
- Returns:
QueryBuilderfor chaining.
- upsert(arg1, *more_keys)[source]¶
Finalize the UDF operation and start an upsert
WriteSegmentBuilder.- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- insert(arg1, *more_keys)[source]¶
Finalize the UDF operation and start an insert-only write segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- update(arg1, *more_keys)[source]¶
Finalize the UDF operation and start an update-only write segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- replace(arg1, *more_keys)[source]¶
Finalize the UDF operation and start a replace write segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- replace_if_exists(arg1, *more_keys)[source]¶
Finalize the UDF operation and start a replace-if-exists segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- delete(arg1, *more_keys)[source]¶
Finalize the UDF operation and start a delete segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- touch(arg1, *more_keys)[source]¶
Finalize the UDF operation and start a touch segment.
- Return type:
- Returns:
WriteSegmentBuilderfor chaining.
- exists(arg1, *more_keys)[source]¶
Finalize the UDF operation and start an exists-check segment.
- Return type:
- Returns:
WriteSegmentBuilderfor 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 asQueryBuilder.execute().- Return type:
- Returns:
Stream of per-key results and optional
udf_resultfields.
Example:
stream = await ( session.execute_udf(k1, k2) .function("pkg", "fn") .execute() )
- Raises:
ValueError – If no UDF function was selected before execute.