Skip to content

Implement DuckDB-based converter - #198

Closed
ivorbosloper wants to merge 19 commits into
mainfrom
duckdb_converter
Closed

ivorbosloper wants to merge 19 commits into
mainfrom
duckdb_converter

Conversation

@ivorbosloper

@ivorbosloper ivorbosloper commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

Adds a DuckDB-based converter for datasets that are too large for the GeoDataFrame-based codepath. The dataset with the largest dataframe (Japan) no longer needs a 128GB+ machine; it converts on a laptop, bounded by DuckDB's external processing, and runs in well under 30 minutes.

The implementation has moved to vecorel-cli (DuckDBBaseConverter, GeoParquet.postprocess(), Hilbert helpers); this PR keeps only the thin fiboa subclass and the jp dataset using it. The outputs of the two codepaths are comparable by construction — same schema, data types, nullability, row order (CRS-derived Hilbert grid with stable tie-breaking), collection and GeoParquet metadata (incl. CRS), and file packaging — verified by tests/test_convert_parity.py, which converts jp through both codepaths and compares the results.

⚠️ Merge order: requires vecorel-cli 0.2.18 (vecorel/cli#29) on PyPI first. After the release, run pixi update to refresh pixi.lock — CI stays red until then.

Also drops the redundant sources from the HR converter, which vecorel-cli 0.2.18 rejects because sources silently overrides the variants.

🤖 Generated with Claude Code

@m-mohr

m-mohr commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

You can set KV_METADATA in DuckDB? That's awesome and resolves the primary issue we had on our list! Will test later, thanks! Maybe it makes sense to jump on a call for the metadata discussion.

@ivorbosloper

Copy link
Copy Markdown
Collaborator Author

You can set KV_METADATA in DuckDB? That's awesome and resolves the primary issue we had on our list! Will test later, thanks! Maybe it makes sense to jump on a call for the metadata discussion.

Yes. I first tried the python API, but that doesn't expose the Metadata option. Would be great to have a call on the metadata details, you wrote the vecorel-parquet logic and seem well informed...

@ivorbosloper

ivorbosloper commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

I'm still stuck on fiboa validation:

fiboa validate jptest.parquet     
fiboa CLI 0.20.1 - Validator

Validating jptest.parquet: INVALID
 - geometry: Nullability differs, is True but must be False
 - id: Nullability differs, is True but must be False

As I understand it, the validator takes the parquet schema and checks it with the fiboa schema (see implementation ). The fiboa schema is built from the extensions (and is correct in this case), but the parquet schema is implicitly created by duckdb (with TO 'file.parquet' (FORMAT parquet)) based on the resultset of the query.

Can I force this to a 'non-null' result? I've tried Casting with ::VARCHAR NOT NULL, but that's not the correct syntax.

Maybe related to duckdb/duckdb#13949

@ivorbosloper

ivorbosloper commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

I think duckdb parquet writer doesn't support setting the nullability derived from the resultset.

$ duckdb
D CREATE TABLE test(id varchar not null);
D insert into test values ('A'), ('B');
D COPY (select * from test) to '/tmp/test.parquet' (FORMAT PARQUET);
D exit

$ parquet-dump-schema /tmp/test.parquet 
required group field_id=-1 duckdb_schema {
  optional binary field_id=-1 id (String);
}

same for COPY test to '/tmp/test.parquet' (FORMAT PARQUET)

@m-mohr

m-mohr commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

For me that sounds like a bug in duckdb. Is there an open issue for it, otherwise maybe open one?

@ivorbosloper

Copy link
Copy Markdown
Collaborator Author

For me that sounds like a bug in duckdb. Is there an open issue for it, otherwise maybe open one?

Is "Non-nullability" a property of a query result column? Maybe this information is lost. But at least it's a feature request..

@m-mohr
m-mohr force-pushed the duckdb_converter branch 2 times, most recently from 3f0dd95 to c524142 Compare December 10, 2025 10:58
@ivorbosloper
ivorbosloper marked this pull request as ready for review February 11, 2026 10:05
@ivorbosloper
ivorbosloper requested a review from m-mohr February 11, 2026 10:05
Comment thread fiboa_cli/conversion/duckdb.py Outdated
@ivorbosloper
ivorbosloper requested a review from m-mohr May 15, 2026 09:40
@m-mohr

m-mohr commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@ivorbosloper In which state is this PR? Was the collection-level metadata and column schema ever solved? Is this generating valid fiboa/vecorel files?

@m-mohr

m-mohr commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Updated PR to work with new duckdb implementation in vecorel-cli, needs a release of vecorel-cli first.

The new vecorel-cli fails when a required property (here crop:code)
has no values. LT 2024 ships an empty crop_code column next to a
populated crop_name, so the name is the best available code. Reading
v1.3 of the inventory also adds the 2025 edition.

Ported from Ivor's publish-portolan branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ivorbosloper

Copy link
Copy Markdown
Collaborator Author

Superseded. The converter now lands in two places: FiboaDuckDBBaseConverter in #272 (rebased on #266, with the JP converter that uses it in #273), and the generic version m-mohr moved upstream in vecorel/cli#29. Once vecorel/cli#29 is released, fiboa's copy goes away and #273 imports the upstream class. Closing this one so the three of them do not compete.

@m-mohr
m-mohr deleted the duckdb_converter branch September 17, 2026 18:19
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.

2 participants