Updated on 2026-11-06 GMT+08:00

Creating a UDTF

This section describes how to register a UDTF with LakeFormation. A UDTF can receive input and return results with multiple rows and columns.

Prerequisites

  • The UDF callable object (function, function class, or class instance) has been prepared and annotated with type annotations.
  • OBS and LakeFormation have been enabled, and the corresponding endpoints, instance IDs, and project IDs have been obtained.

Function Signature

client.create_udtf(
    udtf, /, *,
    database=None,
    name,
    signature=None,
    imports=None,
    runtime_env=None,
    description=None,
    pretty_name=None,
    is_strict=True,
    volatility="VOLATILE",
    is_batch=False,
    batch_size=None,
    cpu_arch=None,
    cpus=None,
    memory=None,
    device_type=None,
    devices=None,
) -> Function

Parameter Description

Parameter

Mandatory (Yes/No)

Type

Default Value

Description

udtf

Yes

Any (location parameter)

-

UDTF callable object (function or callable class).

database

No

str | None

default_database

Name of the target database. If this parameter is set to None, the default database on the client is used.

name

Yes

str

-

Function name. The value must start with a letter and contain 3 to 128 characters, including only letters, digits, and underscores (_).

signature

No

Signature | None

None

Explicit function signature. If this parameter is set to None, it is automatically inferred from UDF annotations.

For more information about the signature, see signature.

imports

No

str | Iterable[str] | None

None

List of file/directory paths or URLs to be included in the UDF package.

runtime_env

No

str | Mapping | None

None

Runtime environment configuration (such as python_version and PyPI dependencies). The value can be a JSON string or dictionary.

For more information about runtime_env, see runtime_env.

description

No

str | None

None

Description of the function.

pretty_name

No

str | None

None

Display name. If the parameter is set to None, the value of name is used.

is_strict

No

bool

True

Whether the function is strict (whether NULL is returned when the input is NULL).

volatility

No

str

VOLATILE

Function volatility. The options are IMMUTABLE, STABLE, and VOLATILE.

is_batch

No

bool

False

Whether to enable the batch processing mode.

batch_size

No

int | None

None

Size of each batch. This parameter is recommended when is_batch is set to True. The value must be a positive integer.

cpu_arch

No

str | None

None

CPU architecture. The value can be arm or x86.

cpus

No

float | None

None

Number of CPU cores. The minimum value is 0.33.

memory

No

int | None

None

Memory size, in MB. The minimum value is 1.

device_type

No

str | None

None

Device type, for example, NPU or GPU.

devices

No

float | None

None

Number of devices. The value must be a positive number.

Return Value

Returns a Function object.

Sample Code

import pyarrow as pa

def split_range(start: int, end: int) -> pa.Table:
    return pa.table({"v": list(range(start, end))})

func = client.create_udtf(
    udf=split_range,
    name="split_range",
    description="Generate a table of integers in the [start, end) range."
)
print(f"UDTF registered: {func.function_name}")