Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Paimon Function

From Leeroopedia


Knowledge Sources
Domains Functions, Catalog
Last Updated 2026-02-08 00:00 GMT

Overview

Function is the core interface for representing user-defined functions in Apache Paimon's catalog system.

Description

The Function interface defines the contract for function metadata in Paimon's catalog. It provides a comprehensive view of a function including its identification, parameters, behavior characteristics, and implementation definitions. Functions in Paimon can have multiple definitions corresponding to different execution engines or runtime environments.

Functions are identified by name and full qualified name, with an Identifier object providing catalog-level identification. The interface supports optional input and return parameter specifications using DataField lists, allowing for strongly-typed function signatures when available. The deterministic flag indicates whether the function produces the same output for the same inputs, which is crucial for query optimization.

The definitions map allows a single function to have multiple implementations, each identified by a key (such as the target execution engine). This enables polyglot function support where the same logical function can be executed in different environments using appropriate implementations. Functions can also carry arbitrary options for configuration and a comment for documentation.

Usage

Use the Function interface when working with user-defined functions in the catalog. This includes creating, listing, and querying functions. The interface provides all necessary metadata for function execution planning, type checking, and optimization. Implementations typically wrap the various function definition types (SQL, file-based, lambda) with consistent catalog metadata.

Code Reference

Source Location

Signature

public interface Function {
    String name();
    String fullName();
    Identifier identifier();
    Optional<List<DataField>> inputParams();
    Optional<List<DataField>> returnParams();
    boolean isDeterministic();
    Map<String, FunctionDefinition> definitions();
    FunctionDefinition definition(String name);
    String comment();
    Map<String, String> options();
}

Import

import org.apache.paimon.function.Function;

I/O Contract

Inputs

Name Type Required Description
name String Yes Key for retrieving a specific function definition

Outputs

Name Type Description
name String Simple function name
fullName String Fully qualified function name (database.function)
identifier Identifier Catalog identifier for this function
inputParams Optional<List<DataField>> Input parameter specifications (if available)
returnParams Optional<List<DataField>> Return value specifications (if available)
deterministic boolean Whether function output is deterministic
definitions Map<String, FunctionDefinition> All available function definitions
definition FunctionDefinition Specific function definition by name
comment String Function documentation
options Map<String, String> Function configuration options

Usage Examples

// Accessing function metadata
Function func = catalog.getFunction(identifier);
String name = func.name(); // "my_udf"
String fullName = func.fullName(); // "my_db.my_udf"

// Checking function characteristics
if (func.isDeterministic()) {
    // Function can be cached or optimized
    planWithCaching(func);
}

// Retrieving type information
Optional<List<DataField>> inputs = func.inputParams();
if (inputs.isPresent()) {
    List<DataField> params = inputs.get();
    for (DataField param : params) {
        System.out.println(param.name() + ": " + param.type());
    }
}

// Getting function definitions for different engines
Map<String, FunctionDefinition> defs = func.definitions();
FunctionDefinition sparkDef = func.definition("spark");
FunctionDefinition flinkDef = func.definition("flink");

// Using function in query planning
if (defs.containsKey(currentEngine)) {
    FunctionDefinition def = func.definition(currentEngine);
    executeFunction(def);
} else {
    throw new UnsupportedOperationException(
        "Function not available for " + currentEngine
    );
}

// Creating a function implementation
Identifier funcId = Identifier.create("my_db", "add_one");
List<DataField> inputs = Arrays.asList(
    new DataField(0, "value", DataTypes.INT())
);
List<DataField> outputs = Arrays.asList(
    new DataField(0, "result", DataTypes.INT())
);

Map<String, FunctionDefinition> definitions = new HashMap<>();
definitions.put("default", FunctionDefinition.sql("value + 1"));

Function myFunc = new FunctionImpl(
    funcId,
    inputs,
    outputs,
    true, // deterministic
    definitions,
    "Adds one to the input value",
    new HashMap<>()
);

catalog.createFunction(funcId, myFunc, false);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment