Skip to main content

@fused.udf

udf(
fn: Optional[Callable] = None,
*,
name: Optional[str] = None,
cache_max_age: Optional[str] = None,
engine: Optional[str] = None,
disk_size_gb: Optional[int] = None,
region: Optional[str] = None,
default_parameters: Optional[Dict[str, Any]] = None,
headers: Optional[Sequence[Union[str, Header]]] = None,
**kwargs: dict[str, Any]
) -> Callable[..., Udf]

A decorator that transforms a function into a Fused UDF.

Parameters

  • name (Optional[str]) – The name of the UDF object. Defaults to the name of the function.

  • cache_max_age (Optional[str]) – The maximum age when returning a result from the cache.

  • engine (Optional[str]) – The execution engine to use ('remote', 'local', 'realtime', or a batch instance type like 'small', 'medium', 'large', 'm5.large', etc.). If not specified (and also not specified when calling the UDF), defaults to 'realtime'.

  • instance_type (Optional[str]) – [Deprecated] Use engine instead. Accepts the same values as engine.

  • disk_size_gb (Optional[int]) – The size of the disk in GB to use for remote execution (only supported for batch instance types).

  • default_parameters (Optional[Dict[str, Any]]) – Parameters to embed in the UDF object, separately from the arguments list of the function. Defaults to None for empty parameters.

  • headers (Optional[Sequence[Union[str, Header]]]) – A list of files to include as modules when running the UDF. For example, when specifying headers=['my_header.py'], inside the UDF function it may be referenced as:

    import my_header
    my_header.my_function()

    Defaults to None for no headers.

Returns

  • Callable[..., Udf] – A callable that represents the transformed UDF.

Examples

Basic UDF:

@fused.udf
def udf(bbox, table_path="s3://fused-asset/infra/building_msft_us"):
...
gdf = table_to_tile(bbox, table=table_path)
return gdf

UDF with a specific engine:

@fused.udf(engine='large')
def udf(bbox):
# Runs on a large batch instance by default
...
return result