vanshtuli-lang opened a new pull request, #77900:
URL: https://github.com/apache/airflow/pull/77900
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?
- [X] Yes — Claude Code (Claude Opus 5.5)
Generated-by: Claude Code (Claude Opus 5.5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]