optimize
Compact and reorganize Iceberg table data files to improve query performance and storage efficiency. Execute maintenance operations using catalog, schema, and table parameters.
Instructions
Optimize an Iceberg table's data files
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| catalog | Yes | catalog name | |
| schema_name | Yes | schema name | |
| table | Yes | The name of the table to optimize |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/trino_client.py:242-262 (handler)The actual implementation of the optimize tool. Compacts small files in an Iceberg table by executing 'ALTER TABLE {catalog}.{schema}.{table} EXECUTE optimize' SQL query and returns a success message.
def optimize(self, catalog: str, schema: str, table: str) -> str: """Optimize an Iceberg table by compacting small files. Args: catalog (str): The catalog name. If None, uses configured default. schema (str): The schema name. If None, uses configured default. table (str): The name of the table to optimize. Returns: str: Success message indicating the table was optimized. Raises: CatalogSchemaError: If either catalog or schema is not specified and not configured. """ catalog = catalog or self.config.catalog schema = schema or self.config.schema if not catalog or not schema: raise CatalogSchemaError query = f"ALTER TABLE {catalog}.{schema}.{table} EXECUTE optimize" self.execute_query(query) return f"Table {catalog}.{schema}.{table} optimized successfully" - src/server.py:141-157 (registration)MCP tool registration for the 'optimize' tool. Uses @mcp.tool decorator with description, defines parameters using Pydantic Field, and delegates execution to client.optimize().
@mcp.tool(description="Optimize an Iceberg table's data files") def optimize( catalog: str = Field(description="catalog name "), schema_name: str = Field(description="schema name "), table: str = Field(description="The name of the table to optimize"), ) -> str: """Optimize an Iceberg table by compacting small files. Args: catalog: catalog name schema_name: schema name table: The name of the table to optimize Returns: str: Confirmation message """ return client.optimize(catalog, schema_name, table) - src/server.py:141-145 (schema)Input schema for the 'optimize' tool. Uses Pydantic Field to define and validate three parameters: catalog, schema_name, and table, each with descriptive help text.
@mcp.tool(description="Optimize an Iceberg table's data files") def optimize( catalog: str = Field(description="catalog name "), schema_name: str = Field(description="schema name "), table: str = Field(description="The name of the table to optimize"),