Functions
User-defined functions (Functions) extend the SQL computation capabilities of Lakehouse, allowing you to create reusable functions tailored to your business needs and call them in SQL queries just like built-in functions.
Function Types
Lakehouse supports two types of user-defined functions:
SQL Function
Functions defined using SQL expressions and executed inside the Lakehouse engine.
- Scalar functions: Process one or more columns from an input row and return a single result value per row.
- Table functions: Accept one or more input parameters and return a result set with multiple rows and columns.
SQL Functions are well-suited for simple computation logic such as formatting, conditional evaluation, and mathematical operations.
External Function
Custom functions written in Python or Java and executed in a remote function compute service (Alibaba Cloud FC, Tencent Cloud SCF, AWS Lambda).
- UDF (User-Defined Function): Returns a single value per row.
- UDAF (User-Defined Aggregate Function): Aggregates multiple rows and returns a single value (Java only).
- UDTF (User-Defined Table Function): Returns a result set with multiple rows and columns (Java only).
External Functions are suited for calling external services (such as LLMs or image recognition APIs) or implementing complex business logic.
Function Comparison
| Dimension | SQL Function | External Function |
|---|---|---|
| Development language | SQL | Python 3.10 / Java 8 |
| Execution location | Inside the Lakehouse engine | Remote function compute service |
| Use cases | Simple computation, formatting, conditional logic | Complex logic, AI model calls, unstructured data processing |
| Performance | High (local execution) | Subject to network latency |
| Dependency management | None | Dependencies must be packaged and uploaded |
| Supported types | Scalar function, table function | UDF, UDAF (Java), UDTF (Java) |
Quick Start
Create a SQL Scalar Function
Create a SQL Table Function
Create an External Function
Function Permissions
| Permission | Description |
|---|---|
CREATE FUNCTION | Create a function under a Schema |
ALTER FUNCTION | Modify function properties |
USE FUNCTION | Call the function in SQL |
DROP FUNCTION | Delete the function |
READ METADATA | View function metadata |
