Skip to content

The ldh plugin's dataset skill builds a CSV of millions of rows in chunks, keeps mappings to standard SPARQL 1.1, and runs arq from Jena 6.3 - #575

Open
namedgraph wants to merge 2 commits into
developfrom
fix/dataset-skill-large-csv
Open

namedgraph wants to merge 2 commits into
developfrom
fix/dataset-skill-large-csv

Conversation

@namedgraph

@namedgraph namedgraph commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Why

Following ldh:dataset section 4 ("build the dataset standalone") on a real 4.8M-row, 1.9 GB CSV, using atomgraph/csv2rdf and a quad CONSTRUCT run by arq, ran into problems the skill does not cover. The mapping was then run side by side with a one-pass script over the same rows. The two outputs match except for 146 of 110M distinct quads, both differences explained below.

What changes in plugins/ldh/skills/dataset/SKILL.md

  • Ground rules
    • The rule "use standard SPARQL 1.1" now also covers import and ETL mappings: no apf: property functions or afn: functions.
    • It names the regex features XPath lacks and Java has: \b, (?:…), (?U), lookarounds.
  • Section 4, Transform
    • How to substitute $base and $created with sed without breaking "$1" replacements.
    • csv2rdf's behaviour: spaces in column names become %20, empty cells produce no triple, cell ends are trimmed of spaces and control characters, and the default --max-chars-per-column is 4096.
    • The example writes --results=NQ.
  • dct:created: NOW() differs on each chunked run and gives a document several values, so substitute one constant.
  • New subsection, "A CSV too large for one arq run":
    • chunking with awk, adding a row-number column for rows with no natural key
    • output repeated across chunks (16% of quads, harmless once loaded)
    • a mapping sees one row at a time, so values on a document must follow from its key
    • alignment tables passed as a second --data, with the key defaulted by COALESCE(…, ""); an OPTIONAL on an unbound key matched every entry and made the run more than 5× slower
    • splitting a list in a cell with a VALUES index instead of apf:strSplit (tested with Jena 6.3 and qparse --strict)
    • measured throughput: about 1 ms per row, 55 min on 6 workers against 2 min for a one-pass script
  • Pitfalls
    • arq 6.1 still fails on quad CONSTRUCT; 6.3.0 writes it again (checked with the default output, --results=NQ and --results=TriG).
    • Set JENA_HOME explicitly, because a ${JENA_HOME:-…} default keeps a 6.x install from the user's profile.
    • The default pretty TriG writer holds the whole result in memory; --results=NQ streams.

CHANGELOG.md gets a line under 6.6.0 > Changed.

The two differences

  • 32 rows contain a stray backspace (the remains of \beta upstream). csv2rdf trims it from the start of a cell and Python's strip() keeps it, so 3 entities got different names and URLs.
  • 27 gene documents are keyed on a locus code that several different alias tuples share. The script keeps the first title it meets; the mapping gives each document every tuple's title.

Mapping, pre-pass or script (second commit)

The same CSV was converted three ways. All three gave 110,331,470 distinct quads:

Pipeline Wall time CPU time
One CONSTRUCT per row, splitting lists in SPARQL (6 workers) 55 min 7,700 s
Pre-pass (50 s), then 5 CONSTRUCTs (6 workers) 18 min 2,900 s
One-pass script 2 min 110 s

The skill now gives an order of preference:

  1. The mapping, by default.
  2. A pre-pass, then mappings. A short script settles keys across rows, puts each list item on its own row, and writes shared documents once. It mints no URL and maps no vocabulary, and it keeps every input row so row numbers stay stable.
  3. A one-pass script, when run time matters more than keeping the mapping in SPARQL.

The pre-pass output matches the one-pass script's except for the 32 rows csv2rdf trims of a control character. It also removes the duplicate titles that the single mapping gives to 27 documents.

The pitfalls gain one more entry. A docker run -i csv2rdf conversion stalled under parallel load: the container sat idle and Docker could not remove it. The stalled chunk was rerun with the CSV2RDF jar.

🤖 Generated with Claude Code

namedgraph and others added 2 commits November 26, 2026 17:41
…unks, keeps mappings to standard SPARQL 1.1, and runs arq from Jena 6.3

Converting a 4.8M-row, 1.9 GB CSV with the skill's csv2rdf + arq CONSTRUCT path met what it did not
cover: arq holds input and result in memory, so the CSV must be chunked; csv2rdf rows carry no row
number; BIND(NOW()) gives a document a dct:created per chunk; a mapping sees one row at a time, so
values that differ between rows of one key multiply; an OPTIONAL lookup on an unbound key fans out
over the whole alignment table; and splitting a list without apf:strSplit needs a VALUES index.

The ground rule on standard SPARQL 1.1 now covers mappings too and names the regex features XPath
lacks. The Jena pitfall says 6.3 writes quad CONSTRUCT results again, that JENA_HOME must be set
explicitly, and that --results=NQ streams where the default pretty TriG buffers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r from the CONSTRUCT mapping

The same 4.8M-row CSV was converted three ways with the same output (110,331,470 distinct quads): one
mapping per row in 55 minutes, a 50-second pre-pass then five mappings in 18, and a one-pass script
in 2. The skill now orders them: the mapping by default; a pre-pass that settles keys, splits lists and
writes shared documents once, leaving URLs and vocabulary to the mappings; a script when run time
matters more than keeping the mapping in SPARQL. A pitfall covers a stalled docker run -i under
parallel load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant