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 FunctionChange

From Leeroopedia


Knowledge Sources
Domains Catalog Functions, Mutation Operations, Command Pattern
Last Updated 2026-02-08 00:00 GMT

Overview

FunctionChange is a sealed interface representing all possible mutation operations that can be applied to a catalog function, enabling ALTER FUNCTION operations via a command pattern.

Description

FunctionChange defines six concrete change types as inner classes: SetFunctionOption (set a key-value option), RemoveFunctionOption (remove an option by key), UpdateFunctionComment (update or remove the comment), AddDefinition (add a named function definition), UpdateDefinition (update an existing definition), and DropDefinition (remove a definition by name).

All types are JSON-serializable using Jackson's @JsonTypeInfo polymorphic type handling with a discriminator field "action". Static factory methods provide convenient construction (e.g., FunctionChange.setOption(key, value)). An inner Actions class defines the string constants for each action type.

This is part of the catalog function management API. It follows the same change/mutation pattern used elsewhere in Paimon (similar to schema changes for tables), enabling function alterations to be represented as serializable objects for REST API transport and catalog-level processing.

Usage

Use FunctionChange to construct mutation operations for catalog functions, particularly in ALTER FUNCTION statements or REST API requests.

Code Reference

Source Location

Signature

@Public
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "action")
@JsonSubTypes({
    @JsonSubTypes.Type(value = SetFunctionOption.class, name = "setOption"),
    @JsonSubTypes.Type(value = RemoveFunctionOption.class, name = "removeOption"),
    @JsonSubTypes.Type(value = UpdateFunctionComment.class, name = "updateComment"),
    @JsonSubTypes.Type(value = AddDefinition.class, name = "addDefinition"),
    @JsonSubTypes.Type(value = UpdateDefinition.class, name = "updateDefinition"),
    @JsonSubTypes.Type(value = DropDefinition.class, name = "dropDefinition")
})
public interface FunctionChange extends Serializable {

    // Factory methods
    static FunctionChange setOption(String key, String value);
    static FunctionChange removeOption(String key);
    static FunctionChange updateComment(String comment);
    static FunctionChange addDefinition(String name, FunctionDefinition definition);
    static FunctionChange updateDefinition(String name, FunctionDefinition definition);
    static FunctionChange dropDefinition(String name);

    // Inner classes
    final class SetFunctionOption implements FunctionChange {
        private final String key;
        private final String value;
        public String key() { return key; }
        public String value() { return value; }
    }

    final class RemoveFunctionOption implements FunctionChange {
        private final String key;
        public String key() { return key; }
    }

    final class UpdateFunctionComment implements FunctionChange {
        private final String comment;
        public String comment() { return comment; }
    }

    final class AddDefinition implements FunctionChange {
        private final String name;
        private final FunctionDefinition definition;
    }

    final class UpdateDefinition implements FunctionChange {
        private final String name;
        private final FunctionDefinition definition;
    }

    final class DropDefinition implements FunctionChange {
        private final String name;
    }
}

Import

import org.apache.paimon.function.FunctionChange;

I/O Contract

Inputs

Name Type Required Description
key String yes (for set/remove) Option key
value String yes (for set) Option value
comment String no Function comment (null removes comment)
name String yes (for definitions) Definition name
definition FunctionDefinition yes (for add/update) Function definition object

Outputs

Name Type Description
functionChange FunctionChange Immutable change object ready for serialization

Usage Examples

Setting Function Options

import org.apache.paimon.function.FunctionChange;
import java.util.Arrays;
import java.util.List;

// Create function option changes
List<FunctionChange> changes = Arrays.asList(
    FunctionChange.setOption("key1", "value1"),
    FunctionChange.setOption("key2", "value2"),
    FunctionChange.removeOption("old-key"),
    FunctionChange.updateComment("Updated function description")
);

// Apply changes through catalog
catalog.alterFunction(
    Identifier.create("my_db", "my_function"),
    changes
);

Managing Function Definitions

import org.apache.paimon.function.FunctionChange;
import org.apache.paimon.function.FunctionDefinition;
import org.apache.paimon.catalog.Identifier;

// Create function definition
FunctionDefinition definition = new FunctionDefinition(
    "com.example.MyFunction",
    "java",
    null // resources
);

// Add a new definition
List<FunctionChange> changes = Arrays.asList(
    FunctionChange.addDefinition("default", definition)
);

catalog.alterFunction(
    Identifier.create("my_db", "my_function"),
    changes
);

// Update existing definition
FunctionDefinition updatedDefinition = new FunctionDefinition(
    "com.example.MyUpdatedFunction",
    "java",
    null
);

changes = Arrays.asList(
    FunctionChange.updateDefinition("default", updatedDefinition)
);

catalog.alterFunction(
    Identifier.create("my_db", "my_function"),
    changes
);

// Drop a definition
changes = Arrays.asList(
    FunctionChange.dropDefinition("default")
);

catalog.alterFunction(
    Identifier.create("my_db", "my_function"),
    changes
);

JSON Serialization

import org.apache.paimon.function.FunctionChange;
import org.apache.paimon.utils.JsonSerdeUtil;

// Create changes
List<FunctionChange> changes = Arrays.asList(
    FunctionChange.setOption("timeout", "30s"),
    FunctionChange.updateComment("Production function")
);

// Serialize to JSON
String json = JsonSerdeUtil.toJson(changes);
System.out.println(json);

// Deserialize from JSON
List<FunctionChange> deserialized =
    JsonSerdeUtil.fromJson(json, List.class);

Related Pages

Page Connections

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