Skip to content

fix(plugin-duckdb): render GEOMETRY as WKT and 9 other fixes (#1324)#1329

Merged
datlechin merged 3 commits into
mainfrom
fix/1324-duckdb-geometry-and-cleanup
May 19, 2026
Merged

fix(plugin-duckdb): render GEOMETRY as WKT and 9 other fixes (#1324)#1329
datlechin merged 3 commits into
mainfrom
fix/1324-duckdb-geometry-and-cleanup

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Fixes Add support for rendering geometry type columns (DuckDB Spatial) #1324: DuckDB Spatial GEOMETRY columns now render as WKT (POINT (...), POLYGON (...)) instead of NULL in both the data grid and streaming results. Done by detecting DUCKDB_TYPE_GEOMETRY and extending the existing patchTzColumns query-rewrite to wrap geometry columns with ST_AsText(...); the streaming path now detects unrenderable types upfront and routes through a wrapped query.
  • Fixes a crash and precision-loss in HUGEINT/UHUGEINT formatting. Extracted to a new HugeIntFormatter that does two's-complement and lossless 4-limb decimal conversion for the full 128-bit range. The previous code UInt64(negativeInt64) force-trapped on negative HUGEINT values and Decimal overflowed past ~5.4×10⁹ for UHUGEINT.
  • Eight additional DuckDB plugin bug fixes (see CHANGELOG for the user-facing list and per-bug details in the commit body):
    • streamQuery resource lifecycle: added defer { duckdb_destroy_result }, row cap from PluginRowLimits.emergencyMax, warning on truncation. Streaming path now also picks up TZ and GEOMETRY columns that previously rendered as NULL.
    • SQL injection in allTablesMetadataSQL: schema name is now single-quote-escaped.
    • Data race on _currentSchema: generateCreateTableSQL and qualifiedTableName now route through the locked accessor.
    • ENUM enum_range missing schema qualifier: broke ENUMs outside main; now enum_range(NULL::"schema"."type").
    • patchTzColumns semicolon strip operated on un-trimmed string: now strips from the trimmed version.
    • DATE/TIMESTAMP BC year formatting: -44 rendered as -044, now -0044 (canonical ISO).
    • Blob free pattern: replaced fragile duckdb_free(&mutableBlob.data) with direct duckdb_free(blob.data).
    • patchTzColumns → unified mechanism (_tp_cast alias) that handles both TZ and GEOMETRY.

Verified end-to-end with the repro from the issue: INSTALL spatial; LOAD spatial; CREATE TABLE places (id INT, name VARCHAR, location GEOMETRY); INSERT ... ST_Point/ST_GeomFromText; SELECT *location column now shows WKT (POINT (0 0), POLYGON ((...))) instead of NULL.

Out of scope (proposed follow-up)

The deeper audit surfaced ~20 more bugs that all stem from the legacy duckdb_value_* API the plugin builds on. A proper fix is a full rewrite onto DuckDB's chunk API (duckdb_fetch_chunk / duckdb_data_chunk_get_vector / duckdb_vector_get_validity / logical-type dispatch). That would eliminate extractFallbackValue and patchTzColumns entirely, add a client-side WKBDecoder so we drop the ST_AsText SQL rewrite, and bring native support for INTERVAL, BIGNUM, BIT, ENUM dictionaries, LIST/ARRAY/STRUCT/MAP/UNION, native TIMESTAMP_NS/TIME_NS precision, and DECIMAL width/scale. Tracking that as a follow-up to keep this PR reviewable.

Test plan

  • Run repro from Add support for rendering geometry type columns (DuckDB Spatial) #1324 in the data grid: GEOMETRY column shows WKT, not NULL.
  • SELECT now()::TIMESTAMPTZ AS ts, now()::TIMETZ AS t via streamQuery (data tab streaming path) — TZ values render correctly.
  • SELECT (-170141183460469231731687303715884105728)::HUGEINT — value renders, no crash. SELECT (170141183460469231731687303715884105727)::HUGEINT — full precision.
  • SELECT '999999999999999999999999999999999'::UHUGEINT — full precision, not scientific notation.
  • Connect to a DuckDB file in a schema with apostrophe in the name (CREATE SCHEMA "it's";) and list tables — no error.
  • Create ENUM in non-default schema; query a column of that ENUM type — values render correctly.
  • Result with >5,000,000 rows on the streaming path — caps, logs warning, no OOM.

@datlechin datlechin merged commit 5216e98 into main May 19, 2026
2 checks passed
@datlechin datlechin deleted the fix/1324-duckdb-geometry-and-cleanup branch May 19, 2026 05:25
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.

Add support for rendering geometry type columns (DuckDB Spatial)

1 participant