Help Center/
DataArts Fabric/
Developer Guide/
Data-AI Convergence/
DataArts Fabric DataFrame/
Registering a Scalar UDF Using the DataFrame API/
Explicitly Registering a Scalar UDF
Updated on 2025-09-18 GMT+08:00
Explicitly Registering a Scalar UDF
Explicitly register a Scalar UDF. That is, you need to manually add the registration logic code intrusively in the Python code. For detailed usage, refer to Scalar UDF Explicit Registration Syntax.
- For Scalar Python UDFs, registering a Scalar Python UDF involves registering an original Python function or class into the database. The example code for explicit registration is as follows. For parameter descriptions, refer to Scalar Python UDF Registration Parameters.
- Example of explicitly registering a Python function for a scalar Python UDF
import ibis import ibis_fabric as fabric from ibis_fabric.udf import RegisterType def calculate_product(price: float, quantity: int) -> float: return price * quantity con = ibis.fabric.connect(...) # Explicitly register a UDF directly. udf = con.udf.python.register(calculate_product, database="your-database", register_type=RegisterType.OBS) # Explicitly register a UDF from a file. udf = con.udf.python.register_from_file("your-current-file-path", "calculate_product", database="your-database", register_type=RegisterType.OBS) # Use the UDF. t = con.table(name="your-table", schema="your-schema") expression = t.select(udf(t.price, t.quantity).name("sum column")) print(expression.execute())
- Example of explicitly registering a Python class for a scalar Python UDF
import ibis import ibis_fabric as fabric from ibis_fabric.udf import RegisterType class Hello: def __init__(self, firstname: str, lastname: str): self.firstname = firstname self.lastname = lastname def process(self, location: str) -> str: return f"Hello{self.firstname} {self.lastname}! Welcome to {location}" con = ibis.fabric.connect(...) # Explicitly register a UDF directly. udf = con.udf.python.register(Hello, database="your-database", register_type=RegisterType.OBS) # Explicitly register a UDF from a file. udf = con.udf.python.register_from_file("your-current-file-path", "Hello", database="your-database", register_type=RegisterType.OBS) # Use the UDF. t = con.table(name="your-table", schema="your-schema") expression = t.select(udf(t.city).with_arguments(firstname="Ethan", lastname="Carter")) print(expression.execute())
- Example of explicitly registering a Python function for a scalar Python UDF
- For Scalar Builtin UDFs, registering a Scalar Builtin UDF serves to obtain the handle of an existing function in the database. There is no actual registration operation. The example code for explicit registration is as follows. For parameter descriptions, refer to Scalar Builtin UDF Registration Parameters.
- Example of explicitly registering a Python function for a scalar builtin UDF
import ibis import ibis_fabric as fabric # The power function already exists in the database. def power(a: float, b: float) -> float: ... con = ibis.fabric.connect(...) # Explicitly register a UDF directly. udf = con.udf.builtin.register(power, database="your-database") # Explicitly register a UDF from a file. udf = con.udf.builtin.register_from_file("your-current-file-path", "power", database="your-database") # Use the UDF. t = con.table(name="your-table", schema="your-schema") expression = t.select(udf(t.interest, t.interval).name("yield column")) print(expression.execute())
- Example of explicitly registering a Python class for a scalar builtin UDF
import ibis import ibis_fabric as fabric # The Power class already exists in the database. class Power: def __init__(self, base: float): ... def process(self, exp: float) -> float: ... con = ibis.fabric.connect(...) # Explicitly register a UDF directly. udf = con.udf.builtin.register(Power, database="your-database") # Explicitly register a UDF from a file. udf = con.udf.builtin.register_from_file("your-current-file-path", "Power", database="your-database") # Use the UDF. t = con.table(name="your-table", schema="your-schema") expression = t.select(udf(t.interval).with_arguments(base=2048.0).name("yield column")) print(expression.execute())
- Example of explicitly registering a Python function for a scalar builtin UDF
Parent topic: Registering a Scalar UDF Using the DataFrame API
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot