Metadata-Version: 2.5
Name: icetrace
Version: 0.1.1
Summary: Scan-planning & metadata forensics engine for Apache Iceberg — EXPLAIN ANALYZE for Iceberg metadata without Spark.
Project-URL: Homepage, https://github.com/sanspareilsmyn/icetrace
Project-URL: Repository, https://github.com/sanspareilsmyn/icetrace
Project-URL: Issues, https://github.com/sanspareilsmyn/icetrace/issues
Project-URL: Changelog, https://github.com/sanspareilsmyn/icetrace/blob/main/CHANGELOG.md
Author-email: Sangmin Yoon <sanspareilsmyn@users.noreply.github.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: apache-iceberg,data-engineering,forensics,iceberg,lakehouse,mcp,metadata,query-planning
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Debuggers
Requires-Python: >=3.11
Requires-Dist: mcp>=2.0.0
Requires-Dist: pyarrow>=16.0.0
Requires-Dist: pydantic>=2.7.0
Requires-Dist: pyiceberg[sql-sqlite]>=0.9.0
Requires-Dist: rich>=13.7.0
Requires-Dist: sqlglot>=25.0.0
Requires-Dist: typer>=0.12.0
Provides-Extra: all
Requires-Dist: pyiceberg[gcsfs,glue,hive,s3fs,sql-postgres]>=0.9.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.11.0; extra == 'dev'
Requires-Dist: pyarrow>=16.0.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=8.2.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: gcs
Requires-Dist: pyiceberg[gcsfs]>=0.9.0; extra == 'gcs'
Provides-Extra: glue
Requires-Dist: pyiceberg[glue,s3fs]>=0.9.0; extra == 'glue'
Provides-Extra: hive
Requires-Dist: pyiceberg[hive]>=0.9.0; extra == 'hive'
Provides-Extra: s3
Requires-Dist: pyiceberg[s3fs]>=0.9.0; extra == 's3'
Description-Content-Type: text/markdown

# icetrace

**`EXPLAIN ANALYZE` for Apache Iceberg metadata — find out why your query scanned 100% of files, without Spark.**

[![PyPI](https://img.shields.io/pypi/v/icetrace.svg)](https://pypi.org/project/icetrace/)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)

Your Iceberg table looks healthy — 256 MB files, few snapshots, compaction enabled — yet a selective `WHERE` query still scans 95% of the table.

**Why?** Iceberg skips data silently at 4 metadata stages. When bounds are missing past column #32, truncated at 16 chars, or overlapping after binpack compaction, **no query engine tells you why files weren't pruned.**

`icetrace` reads **only Iceberg metadata** (never Parquet data files, strictly read-only), simulates Iceberg's exact 4-stage pruning pipeline locally, and pinpoints the exact root cause in seconds — from **Cursor**, **Claude Code**, or your terminal.

---

## See It in 5 Seconds (No Credentials Needed)

```bash
uvx icetrace demo
```

```text
Predicate: tenant_id = 'org_prod_us_east_03_0042'

Stage 1  Manifest List     8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)
Stage 2  Partitions        8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)
Stage 3  Column Bounds     8 evaluated ──▶ 0 pruned ──▶ 8 surviving  (0.0%)

Root Cause: TRUNCATED_BOUNDS (8/8 files)
  tenant_id uses Iceberg's default truncate(16). All 8 files share prefix
  'org_prod_us_east', collapsing min/max bounds and disabling data skipping.

Fix:
  ALTER TABLE ... SET TBLPROPERTIES ('write.metadata.metrics.column.tenant_id' = 'full');
  CALL system.rewrite_data_files(table => '...', strategy => 'sort', sort_order => 'tenant_id');
```

```text
Per-Column Pruning Readiness (O(N log N) Sweep-Line Overlap)
  #   Column      Mode          Bounds   Overlap   Trunc%   Grade
  1   event_id    truncate(16)    100%      0.00       0%     A    ✓ well-sorted
  2   tenant_id   truncate(16)    100%      1.00     100%     F    ✗ truncate(16) collision
  3   amount      truncate(16)    100%      0.98       0%     F    ✗ overlapping ranges
 35   trace_key   none              0%         -       0%     F    ✗ past 32-col metrics cutoff
```

---

## Use Inside Cursor or Claude Code (MCP)

Ask your agent directly while your SQL, dbt model, or table DDL is open:

> *"Run `explain_scan` on `prod.events` for `WHERE event_ts >= '2026-11-20' AND tenant_id = 'org_prod_8491'`. Why did Athena scan 180 GB?"*

**Claude Code:**
```bash
claude mcp add --transport stdio --scope user icetrace -- uvx --from "icetrace[glue]" icetrace-mcp
```

**Cursor** (`.cursor/mcp.json` or `~/.cursor/mcp.json`):
```json
{
  "mcpServers": {
    "icetrace": {
      "command": "uvx",
      "args": ["--from", "icetrace[glue]", "icetrace-mcp"],
      "env": {
        "AWS_PROFILE": "${env:AWS_PROFILE}",
        "AWS_REGION": "us-east-1"
      }
    }
  }
}
```

Works with **AWS Glue**, **REST Catalogs** (Polaris, Lakekeeper, Nessie, Unity, S3 Tables), **Hive**, and **SQL** via standard `~/.pyiceberg.yaml` or `ICETRACE_CATALOG_TYPE` env vars.

---

## Install (CLI)

```bash
# Zero-install
uvx icetrace demo

# Homebrew (macOS / Linux)
brew tap sanspareilsmyn/icetrace https://github.com/sanspareilsmyn/icetrace
brew install icetrace

# uv tool (with AWS Glue & S3)
uv tool install "icetrace[glue]"
```

---

## What It Catches

| Command / MCP Tool | What It Proves (Metadata Only) |
|---|---|
| `explain` / `explain_scan` | Exact 4-stage pruning funnel (100% parity with PyIceberg `plan_files()`) + per-file root-cause attribution (`MISSING_METRICS_COL_LIMIT`, `MISSING_METRICS_WRITER`, `TRUNCATED_BOUNDS`, `OVERLAPPING_RANGES`, `SPEC_EVOLUTION_MISMATCH`, `UNPUSHABLE_PREDICATE`). |
| `audit` / `audit_pruning_health` | Per-column bounds coverage, `truncate(N)` prefix collision %, $O(N \log N)$ domain-weighted sweep-line overlap ratio (`0.0` = sorted, `1.0` = full overlap), manifest interleaving, small files, and V2/V3 delete amplification. |
| `diff` / `diff_snapshots` | Pinpoints which snapshot spiked manifests, dropped bounds coverage, or regressed pruning for a query. |
| `inspect` / `inspect_table_layout` | Instant `metadata.json` dump (zero manifest reads): format version, column ordinals & resolved metrics modes, evolved partition specs, sort order, retention properties. |

---

## Safety Guarantees

- **Strictly Read-Only:** Never mutates, compacts, or expires tables (`readOnlyHint: true`, `destructiveHint: false` on all MCP tools).
- **Metadata-Only:** Only reads `metadata.json`, manifest lists, and manifest Avro files — never scans Parquet/ORC data.
- **Bounded Cost:** Enforces `max_manifests` (default `200`) so huge production tables never hang or burn S3 GETs.
- **Local & Zero-Telemetry:** Credentials and metadata never leave your machine.

---

[Roadmap](ROADMAP.md) · [Changelog](CHANGELOG.md) · [Agent Skill](skills/icetrace/SKILL.md) · [Contributing](CONTRIBUTING.md) · Apache-2.0
