Skip to content

Add IcebergWriteOperator to write files into Iceberg tables - #77900

Open
vanshtuli-lang wants to merge 2 commits into
apache:mainfrom
vanshtuli-lang:iceberg-write-operator
Open

vanshtuli-lang wants to merge 2 commits into
apache:mainfrom
vanshtuli-lang:iceberg-write-operator

Conversation

@vanshtuli-lang

Copy link
Copy Markdown

The Iceberg provider can read and inspect tables but cannot write them, so Dags that land data in Iceberg keep re-implementing the same @task: build catalog credentials, cast rows to the table schema, replace one slice with a filtered overwrite, handle the empty-day case, and retry commit conflicts. This PR adds that as one tested code path.

IcebergWriteOperator reads Parquet, CSV or newline-delimited JSON from any ObjectStoragePath filesystem (URIs, globs or a list) and commits it to an Iceberg table with pyiceberg inside the worker, so no query engine is needed.

  • Modes: append, overwrite (needs overwrite_filter), dynamic_partition_overwrite, upsert.
  • If overwrite gets no filter (or an always-true one) it refuses to run, so a missing template can never truncate the table.
  • on_empty_source: delete_filtered (default; deletes the filtered slice, and does nothing when there is no filter), skip, fail.
  • extra_columns adds constant columns (templated). The data is then cast to the table schema, and a missing required column fails before any commit. CSV and JSON are parsed with the table's column types, because otherwise pyarrow turns strings like 2026-11-30 into timestamps.
  • Each snapshot summary records airflow.dag_id, run_id, task_id and try_number. XCom gets only {rows_written, snapshot_id, table}.
  • OpenLineage: the source files are the inputs and the table location is the output.

IcebergHook

  • write_table() / delete_rows() / cast_to_schema() hold the write logic, so @task code can reuse it. CommitFailedException is retried with exponential backoff after a table refresh.
  • New optional aws_conn_id: credentials (including assumed-role session tokens) and the region come from an AWS connection and are passed as pyiceberg client.* properties. This is behind a new amazon extra, so there is no hard dependency.
  • Non-REST catalogs already work through "type" in the connection extra (for example glue). This is now documented rather than adding a second key.

Dependencies

  • pyiceberg>=0.11.0 (was 0.8.0). 0.11.0 is the first release whose upsert accepts snapshot_properties. dynamic_partition_overwrite and upsert themselves arrived in 0.9.0.
  • pyarrow is now declared. pyiceberg leaves it optional, but writes need it, and so does the existing get_snapshots().
  • New optional extras: amazon and openlineage.

Not included: table maintenance (compaction, expiry, schema evolution), streaming writes (v1 reads the source into one Arrow table, and the docs say so), and an iceberg:// asset URI. Those can be follow-ups if wanted.

Testing

  • The unit tests run against a real pyiceberg SqlCatalog (SQLite) with a local warehouse, set up through an Airflow connection, without mocking pyiceberg. They cover every write mode, filtered-overwrite and delete refusal, schema casting, commit-conflict retry, the empty-source branches, CSV/JSON typing, glob sources and OpenLineage. The AWS bridge is tested with an autospecced AwsBaseHook.
  • Run locally:
    • breeze testing providers-tests --test-type "Providers[apache.iceberg]" → 91 passed
    • prek run --stage pre-commit → passed
    • prek run --stage manual mypy-providers → passed
    • breeze build-docs apache.iceberg → passed
  • The new system test example_iceberg_write.py has not been run end to end. Locally, the system-test harness did not pick up a connection to a throwaway SQL catalog, so it still needs a run against a real catalog.
  • uv.lock changed, so CI's wider suites were left to CI.

The commit carries a Co-Authored-By: Claude trailer because the contributor's organization requires it on all commits. AI use is also disclosed below.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Claude Opus 5.5)

Generated-by: Claude Code (Claude Opus 5.5) following the guidelines

🤖 Generated with Claude Code

The Iceberg provider can read and inspect tables but not write them, so
Dags landing data in Iceberg re-implement the same task: catalog
credentials, casting to the table schema, replacing one slice with a
filtered overwrite, the empty-day case and commit-conflict retries.
Making that one tested code path removes the copies and makes reruns
safe by default, since an unfiltered overwrite is refused.

Glue catalogs commonly authenticate through an assumed AWS role, so the
hook can now take its credentials from an AWS connection.

Co-Authored-By: Claude <noreply@anthropic.com>
The compatibility tests for Airflow 2.11 and 3.0 run with SQLAlchemy 1.4,
which pyiceberg's SQL catalog does not support, and the new optional
amazon and openlineage extras make Iceberg tests run when those providers
change.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This pull request changes CI files. It changes files that CI uses:

  • dev/breeze/tests/test_selective_checks.py

They do not decide which CI jobs run or on which runners, so its workflow runs are not held for this. A maintainer reviewing the pull request will check the CI change together with the rest of it.


This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant