Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Paimon SchemaChange Python

From Leeroopedia
Revision as of 14:22, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Apache_Paimon_SchemaChange_Python.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Schema Management, DDL Operations
Last Updated 2026-02-08 00:00 GMT

Overview

SchemaChange is an abstract base class defining schema modification operations for Apache Paimon tables with concrete implementations for various DDL operations.

Description

The SchemaChange module provides a comprehensive set of classes for defining and executing schema changes on Apache Paimon tables. It includes implementations for common DDL operations such as adding/dropping columns, renaming columns, updating data types, modifying nullability, and managing table options.

The base SchemaChange class provides static factory methods for creating specific change operations. Each operation type is implemented as a dataclass with JSON serialization support for persistence and API communication. The module supports column positioning with Move operations (first, after, before, last).

Concrete implementations include SetOption/RemoveOption for table configuration, UpdateComment for table documentation, AddColumn with optional positioning, RenameColumn, DropColumn, UpdateColumnType with nullability preservation, UpdateColumnNullability, UpdateColumnComment, UpdateColumnDefaultValue, and UpdateColumnPosition for reordering columns.

Usage

Use SchemaChange classes when implementing ALTER TABLE operations, schema evolution logic, or building DDL command interfaces for Apache Paimon tables. The factory methods provide a convenient API for constructing schema changes programmatically.

Code Reference

Source Location

Signature

class SchemaChange(ABC):
    """Base class for schema change operations."""

    @staticmethod
    def set_option(key: str, value: str) -> "SetOption":
        """Create a set option change."""

    @staticmethod
    def remove_option(key: str) -> "RemoveOption":
        """Create a remove option change."""

    @staticmethod
    def update_comment(comment: Optional[str]) -> "UpdateComment":
        """Create an update comment change."""

    @staticmethod
    def add_column(
        field_name: Union[str, List[str]],
        data_type: DataType,
        comment: Optional[str] = None,
        move: Optional["Move"] = None
    ) -> "AddColumn":
        """Create an add column change."""

    @staticmethod
    def rename_column(field_name: Union[str, List[str]], new_name: str) -> "RenameColumn":
        """Create a rename column change."""

    @staticmethod
    def drop_column(field_name: Union[str, List[str]]) -> "DropColumn":
        """Create a drop column change."""

    @staticmethod
    def update_column_type(
        field_name: Union[str, List[str]],
        new_data_type: DataType,
        keep_nullability: bool = False
    ) -> "UpdateColumnType":
        """Create an update column type change."""

    @staticmethod
    def update_column_nullability(
        field_name: Union[str, List[str]],
        new_nullability: bool
    ) -> "UpdateColumnNullability":
        """Create an update column nullability change."""

    @staticmethod
    def update_column_comment(field_name: Union[str, List[str]], comment: str) -> "UpdateColumnComment":
        """Create an update column comment change."""

class Move:
    """Column positioning operations."""

    @staticmethod
    def first(field_name: str) -> "Move":
        """Move column to first position."""

    @staticmethod
    def after(field_name: str, reference_field_name: str) -> "Move":
        """Move column after another column."""

    @staticmethod
    def before(field_name: str, reference_field_name: str) -> "Move":
        """Move column before another column."""

    @staticmethod
    def last(field_name: str) -> "Move":
        """Move column to last position."""

Import

from pypaimon.schema.schema_change import SchemaChange, Move, AddColumn, DropColumn

I/O Contract

Inputs

Name Type Required Description
field_name str or List[str] Varies Column name or nested path for column operations
data_type DataType Yes (for add_column) Data type for new or updated columns
comment str No Comment for table or column
move Move No Positioning instruction for column placement
key str Yes (for options) Option key for table configuration
value str Yes (for set_option) Option value for table configuration

Outputs

Name Type Description
schema_change SchemaChange subclass Specific schema change operation instance

Usage Examples

from pypaimon.schema.schema_change import SchemaChange, Move
from pypaimon.schema.data_types import AtomicType

# Add a new column at the end
add_col = SchemaChange.add_column(
    field_name="new_column",
    data_type=AtomicType("INT"),
    comment="A new integer column"
)

# Add column with positioning
add_first = SchemaChange.add_column(
    field_name="id",
    data_type=AtomicType("BIGINT"),
    move=Move.first("id")
)

# Rename a column
rename = SchemaChange.rename_column("old_name", "new_name")

# Update column type
update_type = SchemaChange.update_column_type(
    field_name="amount",
    new_data_type=AtomicType("DECIMAL", precision=10, scale=2),
    keep_nullability=True
)

# Set table option
set_opt = SchemaChange.set_option("bucket", "4")

# Drop a column
drop = SchemaChange.drop_column("obsolete_column")

# Update column nullability
nullable = SchemaChange.update_column_nullability("required_field", False)

# Apply changes to table
table.alter(add_col, rename, update_type)

Related Pages

Page Connections

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