Skip to content

API Reference parrot.tools.dataset_manager.sources.iceberg

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.dataset_manager.sources.iceberg

View source

IcebergSource — DataSource subclass for Apache Iceberg tables.

On registration, prefetch_schema() loads the table metadata via the asyncdb iceberg driver and retrieves column names and types without fetching any rows. Row count estimation is also available for LLM size warnings.

At fetch time, supports DuckDB SQL queries (via driver.query()) or full-table reads (via driver.to_df()). A static helper create_table_from_df() enables the register-as-dataset workflow: write a DataFrame to a new Iceberg table, then register it as a source.

Alias DataSource

Re-exported from parrot.tools.dataset_manager.sources.base.DataSource.

Class IcebergSource

DataSource for Apache Iceberg tables via asyncdb's iceberg driver.

On registration (via DatasetManager.add_iceberg_source), prefetch_schema() loads the table metadata to retrieve column names and types without fetching any rows.

At fetch time, the LLM can provide a DuckDB SQL query (sql=) or omit it to read the full table.

Parameter Type Default Description
table_id str Fully-qualified Iceberg table identifier, e.g. "demo.cities".
name str Dataset name/identifier for this source.
catalog_params Dict[str, Any] asyncdb iceberg driver connection params (uri, warehouse, catalog type, etc.). Always required.
factory str 'pandas' Output factory for asyncdb queries (default "pandas").
credentials Optional[Dict[str, Any]] None Optional credentials dict (passed to asyncdb driver).
dsn Optional[str] None Optional DSN string (not typically used for Iceberg).

Attributes:

Attribute Type Description
cache_key str Stable Redis cache key for this Iceberg source. Format: iceberg:{table_id}

Method IcebergSource.prefetch_schema

Load Iceberg table metadata and retrieve column→type mapping.

Calls driver.load_table(table_id) then driver.schema() to get column names and types without fetching any rows.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Dict mapping column_name → type string.

Raises:

  • RuntimeError — If the table cannot be loaded or schema is unavailable.

Method IcebergSource.prefetch_row_count

Estimate the row count for this Iceberg table.

Uses a DuckDB COUNT(*) query via the iceberg driver. The result is stored in self._row_count_estimate and surfaced to the LLM so it can decide whether to use aggregation queries.

prefetch_row_count() -> Optional[int]

Returns: Optional[int] — Estimated row count, or None if the query fails.

Method IcebergSource.fetch

Execute a query against the Iceberg table and return a DataFrame.

If sql is provided, executes it via driver.query() (DuckDB SQL). Otherwise performs a full-table read via driver.to_df().

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} sql (str, optional): DuckDB SQL statement to execute. The table can be referenced by its table_id. Any additional params are ignored.

Returns: pd.DataFrame — DataFrame with the query results.

Raises:

  • RuntimeError — If the query fails or returns no data.

Method IcebergSource.describe

Return a human-readable description for the LLM guide.

describe() -> str

Returns: str — String describing the Iceberg table, column count, and catalog info.

Method IcebergSource.create_table_from_df

Create a new Iceberg table from a DataFrame and write the data.

Steps:

  1. Create the namespace if it does not already exist.
  2. Infer a PyArrow schema from the DataFrame dtypes.
  3. Create the Iceberg table with the inferred schema.
  4. Write the DataFrame to the table.

create_table_from_df(driver: Any, df: pd.DataFrame, table_id: str, namespace: str = 'default', mode: str = 'append') -> None

Parameter Type Default Description
driver Any Connected asyncdb iceberg driver instance (already inside an async with await driver.connection() block, or a raw connection).
df pd.DataFrame DataFrame to write.
table_id str Fully-qualified target table id, e.g. "demo.cities".
namespace str 'default' Iceberg namespace (catalog namespace) to create the table in. Defaults to "default".
mode str 'append' Write mode for the data write step. One of "append", "overwrite". Defaults to "append".

Raises:

  • RuntimeError — If namespace creation, table creation, or the write fails.

Alias lazy_import

Re-exported from parrot._imports.lazy_import.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally