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 CatalogEnvironment

From Leeroopedia


Knowledge Sources
Domains Catalog Management, Version Control
Last Updated 2026-02-08 00:00 GMT

Overview

CatalogEnvironment encapsulates catalog context including table identifier, UUID, catalog loader, and version management capabilities for snapshot commit operations.

Description

The CatalogEnvironment class provides a context object that carries essential catalog metadata and capabilities needed for table operations. It contains an optional Identifier for the table, a UUID for tracking, a CatalogLoader for accessing the catalog, and a flag indicating whether the catalog supports version management features.

The primary purpose of CatalogEnvironment is to determine the appropriate snapshot commit strategy. When version management is supported and a catalog loader is available, it creates a CatalogSnapshotCommit that uses catalog-level versioning APIs. Otherwise, it falls back to RenamingSnapshotCommit which uses file system rename operations for atomicity.

The class provides utility methods including copy() for creating modified instances with different identifiers while preserving other settings, and empty() for creating a minimal environment without catalog integration. This design enables flexible table management that can adapt to different catalog implementations and their capabilities.

Usage

Use CatalogEnvironment when initializing table instances that need catalog context, determining snapshot commit strategies based on catalog capabilities, or propagating catalog settings across table operations.

Code Reference

Source Location

Signature

class CatalogEnvironment:

    def __init__(
            self,
            identifier: Optional[Identifier] = None,
            uuid: Optional[str] = None,
            catalog_loader: Optional[CatalogLoader] = None,
            supports_version_management: bool = False
    ):
        pass

    def snapshot_commit(self, snapshot_manager) -> Optional[SnapshotCommit]:
        pass

    def copy(self, identifier: Identifier) -> 'CatalogEnvironment':
        pass

    @staticmethod
    def empty() -> 'CatalogEnvironment':
        pass

Import

from pypaimon.catalog.catalog_environment import CatalogEnvironment

I/O Contract

Inputs

Name Type Required Description
identifier Identifier No Table identifier (database.table)
uuid str No Unique identifier for tracking
catalog_loader CatalogLoader No Catalog loader for accessing catalog
supports_version_management bool No Whether catalog supports version management (default: False)
snapshot_manager SnapshotManager Yes Snapshot manager for commit operations

Outputs

Name Type Description
snapshot_commit SnapshotCommit Appropriate snapshot commit implementation
environment CatalogEnvironment New or copied environment instance

Usage Examples

from pypaimon.catalog.catalog_environment import CatalogEnvironment
from pypaimon.common.identifier import Identifier
from pypaimon.catalog.catalog_loader import CatalogLoader

# Create empty environment for file-based operations
env = CatalogEnvironment.empty()

# Create environment with catalog support
identifier = Identifier.create("my_database", "my_table")
catalog_loader = CatalogLoader(...)

env = CatalogEnvironment(
    identifier=identifier,
    uuid="550e8400-e29b-41d4-a716-446655440000",
    catalog_loader=catalog_loader,
    supports_version_management=True
)

# Get appropriate snapshot commit strategy
snapshot_manager = ...  # SnapshotManager instance
commit = env.snapshot_commit(snapshot_manager)
# Returns CatalogSnapshotCommit if version management supported,
# otherwise RenamingSnapshotCommit

# Copy environment with different identifier
new_identifier = Identifier.create("my_database", "another_table")
new_env = env.copy(new_identifier)
# Preserves uuid, catalog_loader, and supports_version_management

# Check if version management is supported
if env.supports_version_management and env.catalog_loader:
    print("Using catalog-based version management")
else:
    print("Using file-based snapshot commits")

# Access environment properties
print(f"Table: {env.identifier.get_full_name()}")
print(f"UUID: {env.uuid}")

Related Pages

Page Connections

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