Ryan Gates
03/24/2026, 2:23 PMRocky
03/24/2026, 2:23 PMpython_envs configuration in your be.conf to point to the location of the Python interpreter (e.g., /opt/Python-3.8/) on each BE node.
* FE Nodes: You do not need to install Python on the FE nodes. However, you must enable the UDF feature globally by setting enable_udf = true in the fe.conf file.
2. Does a Python UDF code change require redeploying either FE or BE?
No, a code change to the UDF logic itself does not require redeploying or restarting the FE or BE nodes.
* Initial Setup: You only need to restart the FE and BE nodes once to apply the initial configuration changes (enable_udf on FE and python_envs on BE).
* Code Updates: To update the logic of an existing UDF, you typically use the following SQL workflow:
1. DROP FUNCTION <function_name>(<arg_types>);
2. CREATE FUNCTION ... with the updated code (either as an inline code block or a link to a new packaged .py.zip file).
* Packaged UDFs: If you are using external files, StarRocks automatically downloads the updated package to the BE nodes when the function is called or created. In StarRocks 4.0, a new BE parameter clear_udf_cache_when_start was introduced to help manage the local cache of these files upon startup, but it is not required for standard code updates.
Summary of Requirements:
* Python Version: 3.8 or later.
* Dependencies: The pyarrow package must be installed in the Python environment on the BE nodes.
* Configuration:
* FE: enable_udf = true in fe.conf.
* BE: python_envs = <path_to_python_home> in be.conf.
If you have more questions about setting up your Python environment for StarRocks, feel free to ask!
References
• sql-reference/sql-functions/Python_UDF.md
• administration/management/BE_configuration.mdRyan Gates
03/24/2026, 2:26 PMRocky
03/24/2026, 2:28 PMnumpy, pandas, etc.).
2. Development Experience
* Java UDF: Requires creating a Maven project, compiling a JAR file, and hosting that JAR on an HTTP server accessible by the StarRocks cluster.
* Python UDF: Supports inline code using the AS $$ ... $$ syntax, allowing you to write logic directly in your SQL statement. It also supports packaged .py.zip files for more complex dependencies.
3. Function Types
* Java UDF: Supports a wide range of types:
* Scalar UDFs (one row in, one row out)
* UDAFs (User-defined Aggregate Functions)
* UDWFs (User-defined Window Functions)
* UDTFs (User-defined Table Functions)
* Python UDF: Currently only supports Scalar UDFs.
4. Performance and Data Processing
* Java UDF: Operates primarily on a row-by-row basis (scalar).
* Python UDF: Supports Vectorized Input via Apache Arrow. By setting input = "arrow", StarRocks can pass batches of data to the Python interpreter, which significantly improves performance compared to row-by-row processing.
5. Deployment and Configuration
* Java UDF: Relies on the JVM. You usually only need to configure the JVM heap size (JAVA_OPTS in be.conf).
* Python UDF: Requires a Python environment on the BE nodes. You must set the python_envs configuration in be.conf and ensure pyarrow is installed in that environment.
Summary Table
Feature | Java UDF | Python UDF
Introduced | v2.2.0 | v3.4.0 (Experimental)
Supported Types | Scalar, UDAF, UDWF, UDTF | Scalar only
Code Definition | External JAR file | Inline (AS $$) or .py.zip
Data Format | Native Java types | Scalar or Arrow (Vectorized)
Ease of Use | Moderate (requires build/deploy) | High (inline scripts)
Primary Use Case | Complex logic, high perf | Data Science, ML, rapid dev
If you were referring to Remote UDFs (External UDFs), the main difference is that Remote UDFs run on a separate server (accessed via RPC/HTTP), whereas Java and Python UDFs run locally on the StarRocks BE nodes.
References
• sql-reference/sql-functions/Python_UDF.md
• sql-reference/sql-functions/JAVA_UDF.md
• sql-reference/sql-functions/README.md
• using_starrocks/jit.md
• sql-reference/sql-functions/hive_bitmap_udf.mdRyan Gates
03/24/2026, 2:32 PMRocky
03/24/2026, 2:32 PMSELECT my_func(column) FROM table), StarRocks applies the function logic to each row individually.
* Input: A single set of arguments from one row.
* Output: A single return value for that same row.
* Analogy: Think of it like the built-in UPPER() or ABS() functions. If you pass 100 rows into UPPER(name), you get 100 uppercase names back.
2. Comparison with Other UDF Types
To understand Scalar UDFs better, it helps to see what they are _not_:
* UDAF (Aggregate): "Many rows in, one row out." (e.g., SUM or COUNT). It takes a whole group of rows and collapses them into a single result.
* UDTF (Table): "One row in, many rows out." (e.g., split). It takes one input and can expand it into multiple rows or columns.
* UDWF (Window): Functions used with an OVER clause, maintaining the row count but allowing access to a frame of rows.
3. Implementation in StarRocks
StarRocks supports Scalar UDFs primarily through Java (stable) and Python (experimental as of v3.4).
Example: Java Scalar UDF
If you wanted a function that adds a prefix to a string, your Java code would look like this:
java
public class AddPrefix {
// The 'evaluate' method defines the "one row in, one row out" logic
public final String evaluate(String input) {
if (input == null) return null;
return "SR_" + input;
}
}
SQL Declaration
Once compiled into a JAR, you register it in StarRocks:
sql
CREATE FUNCTION add_prefix(string)
RETURNS string
PROPERTIES (
"symbol" = "com.starrocks.udf.sample.AddPrefix",
"type" = "StarrocksJar",
"file" = "http://<your_server>/udf.jar"
);
4. Key Benefits
* Row-Level Transformation: Ideal for data masking, custom mathematical formulas, or complex string manipulations that must happen per record.
* Performance: Because they operate row-by-row without needing to buffer large sets of data (unlike aggregates), they are generally memory-efficient.
* Global Scope: In StarRocks (v3.0+), you can create GLOBAL UDFs so they are available across all databases in the cluster.
When to use it: Use a Scalar UDF whenever you need a custom calculation that doesn't change the number of rows in your result set.
References
• sql-reference/sql-functions/JAVA_UDF.md
• sql-reference/sql-functions/Python_UDF.md