Implementation:Apache Paimon FunctionImpl
| Knowledge Sources | |
|---|---|
| Domains | Functions, Catalog |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
FunctionImpl is the concrete implementation of the Function interface, providing a complete function metadata container.
Description
FunctionImpl serves as the standard implementation of the Function interface in Paimon's catalog system. It provides an immutable, value-based representation of function metadata that can be stored, transmitted, and cached efficiently.
The class supports two construction patterns: a full constructor that accepts all function metadata including input parameters, return parameters, deterministic flag, comment, and options; and a simplified constructor that only requires the essential identifier and definitions, using sensible defaults for other fields. The simplified form is useful for basic function registration where detailed type information isn't available or necessary.
All fields are final and stored as instance variables, ensuring thread-safety and immutability. The class properly implements equals and hashCode based on all fields, making it suitable for use in collections and as cache keys. The implementation delegates name and identifier methods to the underlying Identifier object, maintaining consistency with Paimon's naming conventions.
FunctionImpl provides convenient access to function definitions through both a map of all definitions and a method to retrieve a specific definition by name. This supports scenarios where functions have multiple implementations for different execution engines or runtime environments.
Usage
Use FunctionImpl when creating or returning function metadata in catalog implementations. It's the standard way to represent function objects throughout Paimon's codebase. The two constructors allow you to choose between comprehensive metadata (when available) and minimal metadata (for simple use cases).
Code Reference
Source Location
- Repository: Apache_Paimon
- File: paimon-api/src/main/java/org/apache/paimon/function/FunctionImpl.java
Signature
public class FunctionImpl implements Function {
private final Identifier identifier;
@Nullable private final List<DataField> inputParams;
@Nullable private final List<DataField> returnParams;
private final boolean deterministic;
private final Map<String, FunctionDefinition> definitions;
@Nullable private final String comment;
private final Map<String, String> options;
public FunctionImpl(
Identifier identifier,
@Nullable List<DataField> inputParams,
@Nullable List<DataField> returnParams,
boolean deterministic,
Map<String, FunctionDefinition> definitions,
@Nullable String comment,
Map<String, String> options)
public FunctionImpl(
Identifier identifier,
Map<String, FunctionDefinition> definitions)
@Override public String name()
@Override public String fullName()
@Override public Identifier identifier()
@Override public Optional<List<DataField>> inputParams()
@Override public Optional<List<DataField>> returnParams()
@Override public boolean isDeterministic()
@Override public Map<String, FunctionDefinition> definitions()
@Override public FunctionDefinition definition(String name)
@Override public String comment()
@Override public Map<String, String> options()
}
Import
import org.apache.paimon.function.FunctionImpl;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| identifier | Identifier | Yes | Catalog identifier for the function |
| inputParams | List<DataField> | No | Input parameter type specifications |
| returnParams | List<DataField> | No | Return value type specifications |
| deterministic | boolean | No | Whether function is deterministic (defaults to true) |
| definitions | Map<String, FunctionDefinition> | Yes | Function implementation definitions |
| comment | String | No | Function documentation |
| options | Map<String, String> | No | Configuration options (defaults to empty map) |
Outputs
| Name | Type | Description |
|---|---|---|
| function | FunctionImpl | Complete function metadata object |
| name | String | Simple function name |
| fullName | String | Fully qualified function name |
| identifier | Identifier | Function identifier |
| inputParams | Optional<List<DataField>> | Input parameters if specified |
| returnParams | Optional<List<DataField>> | Return parameters if specified |
| deterministic | boolean | Deterministic flag |
| definitions | Map<String, FunctionDefinition> | All function definitions |
| comment | String | Function comment |
| options | Map<String, String> | Configuration options |
Usage Examples
// Creating a simple function with minimal metadata
Identifier funcId = Identifier.create("my_db", "add_one");
Map<String, FunctionDefinition> definitions = new HashMap<>();
definitions.put("default", FunctionDefinition.sql("x + 1"));
FunctionImpl simpleFunc = new FunctionImpl(funcId, definitions);
// Creating a function with complete metadata
List<DataField> inputs = Arrays.asList(
new DataField(0, "value", DataTypes.DOUBLE()),
new DataField(1, "factor", DataTypes.DOUBLE())
);
List<DataField> outputs = Arrays.asList(
new DataField(0, "result", DataTypes.DOUBLE())
);
Map<String, FunctionDefinition> multiDefs = new HashMap<>();
multiDefs.put("sql", FunctionDefinition.sql("value * factor"));
multiDefs.put("java", FunctionDefinition.file(
resources,
"java",
"com.example.Multiply",
"eval"
));
Map<String, String> options = new HashMap<>();
options.put("precision", "double");
options.put("null-handling", "strict");
FunctionImpl complexFunc = new FunctionImpl(
funcId,
inputs,
outputs,
true, // deterministic
multiDefs,
"Multiplies two numbers with configurable precision",
options
);
// Using function metadata
System.out.println(complexFunc.fullName()); // "my_db.multiply"
System.out.println(complexFunc.isDeterministic()); // true
if (complexFunc.inputParams().isPresent()) {
List<DataField> params = complexFunc.inputParams().get();
System.out.println("Inputs: " + params.size());
}
// Accessing function definitions
FunctionDefinition sqlDef = complexFunc.definition("sql");
FunctionDefinition javaDef = complexFunc.definition("java");
// Creating a non-deterministic function (e.g., random number generator)
FunctionImpl randomFunc = new FunctionImpl(
Identifier.create("my_db", "random"),
null,
Arrays.asList(new DataField(0, "value", DataTypes.DOUBLE())),
false, // non-deterministic
Collections.singletonMap("default", FunctionDefinition.sql("RAND()")),
"Generates random number",
Collections.emptyMap()
);
// Catalog integration
catalog.createFunction(funcId, complexFunc, false);
Function retrieved = catalog.getFunction(funcId);
assert retrieved.equals(complexFunc);
// Comparing functions
FunctionImpl func1 = new FunctionImpl(id1, defs1);
FunctionImpl func2 = new FunctionImpl(id1, defs1);
boolean same = func1.equals(func2); // true if all fields match