Repository navigation
feat(autoindex): extract Excel workbooks (.xlsx), one dataset per sheet - #1120
Closed
thomas-villani wants to merge 4 commits into
Closed
thomas-villani wants to merge 4 commits into
thomas-villani wants to merge 4 commits into
Conversation
Motivation: since xerj-org#1114, autoindex recognizes a .pptx but junks it as an unsupported document. Decks are a common carrier of business content (reviews, plans, figures) and, like PDF/DOCX, are exactly what grep cannot read, which is where the document-folder recipe measured XERJ's largest margin over grep (6/7 vs 0/7 on PDF/DOCX-only answers). What it does (extract/pptx.rs, new): - One record per slide: `title` (deck title = first slide title, else the file stem), `slide` (1-based position in p:sldIdLst — the number PowerPoint shows; part names do not change when slides are reordered), `slide_title` (title/ctrTitle placeholder), `body`; a long slide is sectioned like a PDF page (`section`, locator `slide{n}-s{k}`). Falls back to ppt/slides/slideN.xml in numeric order when the presentation part or its rels are unusable. - Text is read shape by shape from DrawingML: `a:p` paragraphs, `a:br` breaks; tables as one line per row with ` | `-joined cells, so a value keeps its row and column (DOCX tables currently lose this). - Speaker notes, reached through the slide's notesSlide relationship, are appended to the body under "Speaker notes:" so both BM25 and the semantic field see them. - Skipped: dt/ftr/hdr/sldNum/sldImg placeholders and `a:fld` field text — boilerplate repeated on every slide. - Matching is on local names, so strict-OOXML namespaces read the same. - Bounds: 32 MiB per part, 256 MiB decompressed per container, 64 MiB of extracted text, and MAX_RECORDS_PER_FILE. Hitting any of them sets `truncated` (reported, not silent). A deck with no text is junk. Wiring: Family::Pptx (as_str "pptx", is_document), sniffed from ppt/presentation.xml in zip_container_kind; dispatch in extract/mod.rs; SourceAndDocs band in both order.rs band functions; full-read family in estimate::exact_scan_bytes; whole-file size cap in scan_file. "pptx" is removed from unsupported_document_advice. Evidence (rust:latest container, cargo 1.98.1, Linux): - 7 new extract::pptx tests (order vs part names, numeric fallback, titles/tables/notes/placeholder skipping, empty slides and decks, sectioning, decompression budget, OPC target resolution) pass; the updated sniff test asserts ppt/presentation.xml -> Family::Pptx. - cargo test -p xerj-autoindex --lib: 1167 passed, 0 failed, 2 ignored. - cargo clippy -p xerj-autoindex --all-targets -- -D warnings: clean. - A deck written by python-pptx (real PowerPoint template parts, slides reordered in sldIdLst) sniffed as Pptx and extracted 3 records in display order with the table rows and speaker notes intact (temporary probe test, not committed). Not covered: a deck saved by PowerPoint itself; an end-to-end `xerj autoindex` run against a server. Charts, SmartArt and images contribute no text. Written by an AI coding agent (Claude Code, Claude Opus 5.5), run and reviewed by Tom Villani (@thomas-villani).
… blob Motivation: under durable preparation (`--no-graph`), `sync_executor` extracts a sealed snapshot blob (`prepared/00000000`) and carries the file's own name only in `Sniffed::logical_name`. The PPTX extractor fell back to `path.file_stem()` for a deck with no title placeholder, so such a deck was titled "00000000" — the xerj-org#722 failure class that `extract_as_document_with_name` and the stub name card already guard against. Fix: `pptx::extract` takes the logical name, and dispatch passes `sn.logical_name` (falling back to `path`), as `code.rs` does. Evidence: new test `an_untitled_deck_is_titled_from_the_logical_name_not_the_blob` sniffs a deck stored as `00000000` with logical name `decks/kickoff.pptx` and extracts it through `extract::extract`. With dispatch passing `path` (the old behaviour) it fails with left: "00000000", right: "kickoff"; with the fix it passes. `cargo test -p xerj-autoindex --lib`: 1170 passed, 0 failed (Linux container); clippy -D warnings and fmt clean.
Motivation: the XLSX extractor reads the same Open Packaging Conventions container as PPTX — a decompression budget across many parts, `.rels` relationship parsing and target resolution. Rather than copy them, move them from `extract/pptx.rs` into `extract/opc.rs`. Changes beyond the move: - `Budget::stream` hands a part to a closure as a bounded reader and charges the budget for the bytes actually pulled through it, so a worksheet can be parsed row by row instead of held whole. `read` is now `stream` + `read_to_end`; its behaviour is unchanged. - `attr` resolves entity references (`normalized_value`) instead of returning the raw bytes, so a sheet named `P&L` (stored `P&L`) or a relationship target with an escaped character reads correctly. A value that fails to unescape is still returned raw. Evidence: the moved `relationship_targets_resolve_like_opc` test and a new `streaming_charges_only_what_was_read_and_flags_a_cap_hit` test in `extract::opc`; every existing `extract::pptx` test passes unchanged.
Motivation: since xerj-org#1114 a `.xlsx` is recognised but junked with "export each sheet as CSV". Spreadsheets are where data-science and business/finance users keep their data, and an exported CSV loses what the workbook knows: which numbers are dates, booleans, and which sheet a row came from. Record model — CSV/SQLite, not DOCX: - Each worksheet is its own group (`RawRecord.group` = sheet name, like a SQLite table), so it clusters into its own data dataset; the same sheet schema in several workbooks (q1.xlsx, q2.xlsx) merges into one. - Each row under the header is one record keyed by the header cells (`sanitize_field_name`, `_2` dedup as in CSV; unheaded columns are `col_<letter>`). Locator `<sheet>!r<row>` uses Excel's own row number. `FieldOrigin::Data`. - Typed values: numbers and booleans as JSON numbers/booleans; formula cells contribute their cached value; error cells and formulas with no cached value are absent. A number whose cell style (`xl/styles.xml` cellXfs -> numFmt) is a date format becomes an ISO-8601 string, so inference elects `date` with real min/max ranges instead of `long` over serials like 45839. Handles the 1900 and 1904 date systems and the fictitious 1900-02-29; time-only formats become `HH:MM:SS`; elapsed durations (`[h]:mm`) and percents stay numbers. Header detection (a sheet is not always a clean table): - The header is the first of the first 20 non-empty rows with >= 2 cells, some text, no numbers/booleans, that is not followed by a wider row of the same kind. Title rows above it ("Q3 Sales Report", "Prepared by | Finance") are skipped; repeated header rows are dropped. - A sheet with no such row (a form, a key/value assumptions tab, notes) is indexed as a document: `title` "<file> — <sheet>", `sheet`, body one line per row with cells joined by ` | `, blank sheet rows as paragraph breaks. One workbook can therefore feed a data dataset and the document dataset; `FileAssignment.assignments` already routes by group. Bounds: workbook/rels/styles/shared strings are held whole under a 64 MiB per-part cap; worksheets are streamed row by row (1 GiB per sheet, 2 GiB per container); a document sheet keeps at most 16 MiB of text. Hitting any cap sets `ExtractStats.truncated`. Wiring: `Family::Xlsx` (not `is_document`: rows are data), sniffed from `xl/workbook.xml`; dispatch passes the logical name for document titles and a 500-row per-sheet cap when sampling (like SQLite's per-table cap, `sample_limit_bytes` -> Some(1)); grouped family in `scan_file`; Data band in both band functions; not timeable in `exact_scan_bytes`. `unsupported_document_advice` drops `xlsx` and now tells `.xlsb`/`.ods` owners to save as `.xlsx`. Known limits: one table per sheet; merged cells not expanded; stored values, not displayed ones (a cell showing 21% is 0.21); a two-column all-text form sheet reads as a table; chart sheets skipped. Evidence (Linux container, cargo 1.98.1): - 17 new `extract::xlsx` tests plus a planner test `workbooks_plan_a_dataset_per_sheet_schema_and_documents_for_form_sheets` (two workbooks -> one `Sales` dataset with `Month` elected `date`, form sheets in the docs dataset, one file assigned to both). - The logical-name title test fails with "00000000 — Notes" when dispatch passes the blob path, and passes with the fix. - `cargo test -p xerj-autoindex --lib`: 1189 passed, 0 failed, 2 ignored. - Workbooks written by openpyxl and pandas extracted as expected.
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @thomas-villani It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written by an AI coding agent (Claude Code, Claude Opus 5.5), run by @thomas-villani, who has reviewed this change.
What this changes, and why
Since #1114, autoindex recognizes a
.xlsxbut junks it with "export each sheet as CSV". Spreadsheets are where data-science and business/finance users keep their data. An exported CSV also loses what the workbook knows: which numbers are dates, which are booleans, and which sheet a row came from.This PR adds
extract/xlsx.rsand aFamily::Xlsx. It follows the CSV/SQLite record model, not the DOCX one: a workbook is tables, not prose.Record shape:
RawRecord.group= sheet name, as a SQLite table. The same sheet schema in several workbooks (e.g.q1.xlsx,q2.xlsx) clusters into one dataset.col_<letter>.FieldOrigin::Data.<sheet>!r<row>, using Excel's own row number.Values keep their stored type:
datewith real min/max ranges, instead oflongover serials like45839. This matters for/_ask(agents:POST /_ask+xerj_planMCP tool — prompt in, validated DSL out #1056), which plans from those ranges.HH:MM:SS. Elapsed durations ([h]:mm) and percents stay numbers.Header detection. Real sheets often have a title above the table.
title"<file> — <sheet>", asheetfield, and a body with one line per row and cells joined by|. Its text stays searchable.FileAssignment.assignmentsalready routes records by group, and this is covered by a planner test.Bounds:
ExtractStats.truncated.Wiring:
Family::Xlsxis not inis_document, because its rows are data.xl/workbook.xml.sample_limit_bytesreturnsSome(1)).scan_file, in the Data band in both band functions, and not timeable inexact_scan_bytes.unsupported_document_advicedropsxlsx, and now tells.xlsband.odsowners to save as.xlsx.Shared helpers (
84a288ba). The OPC container helpers from #1117 move intoextract/opc.rsinstead of being copied. Two changes beyond the move:Budget::streamcharges the budget for the bytes actually read, so worksheets can be streamed.attrnow resolves entity references, so a sheet namedP&L(stored asP&L) reads correctly.Evidence
All of the following ran in a
rust:latestLinux container (cargo 1.98.1). The crate's test build does not compile on Windows; see #1114.That is 1170 on #1117's branch, plus 19 new tests:
extract::xlsxtests:extract::opcstreaming-budget test.workbooks_plan_a_dataset_per_sheet_schema_and_documents_for_form_sheets. It runs two quarterly workbooks plus a README throughbuild_phase_a. The result is oneSalesdataset withMonthelecteddate(from 2026-01-01) andRevenueelecteddouble. The form sheets land in the docs dataset next to the README, andq1.xlsxis assigned to both datasets.Fail-before for the document-title test: under durable preparation the extractor reads a snapshot blob, so the title must come from
Sniffed::logical_name. With dispatch passing the blob path, the test fails:The same bug existed in #1117's deck-title fallback; it is fixed there in
ac108d0e.Real-file check. I wrote workbooks with openpyxl and pandas and ran them through
sniff()andxlsx::extractwith a temporary test that is not committed. Output, trimmed:In this run:
Margin(formatted0.00%) keeps its stored fraction.Lookupsheet is indexed.A column that mixes date-only and date-time strings (
Updated) is safe:coerce_to_dateparses each value's own encoding and normalizes it to RFC 3339.Checks
cargo fmt -p xerj-autoindex -- --check: clean. Only this crate is touched.cargo clippy -p xerj-autoindex --all-targets -- -D warnings: clean on Linux. CI runs it workspace-wide; I ran it on this crate only.cargo build --release -j 32 -p xerj-autoindexfinished (2m 04s, Linux).cargo test -p xerj-autoindex --lib: 1189 passed, 0 failed. The intermediate commit84a288baalone passes theextract::tests (264 passed).landing/llms.txtand the README format lists would gain.pptx/.xlsx. I'll send that as one docs PR after this and feat(autoindex): extract PowerPoint decks (.pptx), one record per slide #1117 land (one-open-PR rule onllms.txt).Not run:
crates/xerj-autoindex/tests/.xerj autoindexrun against a server.Known limits
These are deliberate for a first version:
21%is0.21.Name | John) reads as a table with odd field names. A form with any numeric value is correctly treated as a document..xlsbis still unsupported.Provenance
cellXfs→numFmtIddate styles, and cached<v>beside<f>.🤖 Generated with Claude Code