feat: detect duckdb spatial columns as geometry - #10592
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
Adds DuckDB spatial-type awareness to marimo’s table/SQL typing so DuckDB relations with spatial columns are treated consistently as the geometry semantic type, aligning table rendering (safe placeholders/structs) with SQL stats behavior (counts-only).
Changes:
- Detect DuckDB spatial relation column types (
GEOMETRY,*_2D) asgeometryin geometry schema detection. - Map DuckDB spatial type strings to
geometryin SQL metadata/type mapping and return counts-only stats forgeometrySQL columns. - Expand test coverage for DuckDB geometry detection/rendering and update related snapshots.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/_plugins/ui/_impl/tables/test_geometry.py | Adds DuckDB-focused geometry detection + TableManager behavior tests. |
| tests/_plugins/ui/_impl/tables/test_geometry_fixtures.py | Updates characterization expectation for DuckDB geometry field type. |
| tests/_plugins/ui/_impl/tables/snapshots/false_positives.pandas.json | Updates a pandas false-positive snapshot (binary None serialization). |
| tests/_data/test_sql_summaries.py | Adds geometry SQL stats tests (including DuckDB spatial table). |
| tests/_data/test_get_datasets.py | Updates expectations for DuckDB spatial type-to-data-type mapping. |
| marimo/_plugins/ui/_impl/tables/geometry.py | Implements DuckDB relation schema-based geometry detection. |
| marimo/_data/sql_summaries.py | Adds counts-only stats query/decoding path for geometry columns. |
| marimo/_data/get_datasets.py | Treats DuckDB spatial type strings as geometry instead of unknown. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage Report for ./frontend
File CoverageNo changed files found. |
There was a problem hiding this comment.
2 issues found across 58 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="marimo/_plugins/ui/_impl/tables/pandas_table.py">
<violation number="1">
P2: When a format mapping targets a GeoPandas geometry column, this line formats it before detection, so JSON returns the formatter’s value instead of the safe geometry representation. Skip geometry columns in pandas `apply_formatting`, matching the Narwhals implementation, before deriving `_geometry_columns`.</violation>
</file>
<file name="marimo/_data/models.py">
<violation number="1">
P2: Adding `"geometry"` without regenerating `marimo/_schemas/generated/notifications.yaml` leaves the notification schema stale. Regenerate the checked-in notification schema so `DataTableColumn.type` advertises the new value and the schema consistency test passes.</violation>
</file>
Architecture diagram
sequenceDiagram
participant DuckDB as DuckDB Engine
participant Backend as Backend (Python)
participant Frontend as Frontend (React/TypeScript)
participant DataTable as Data Table UI
participant Charts as Charts Module
participant Vega as Vega Plugin
Note over DuckDB,Frontend: Geometry Column Detection & Rendering Flow
Backend->>Backend: NEW: Detect geometry columns via find_geometry_columns()
alt Backend is DuckDB with spatial extension
Backend->>DuckDB: Query relation schema
DuckDB-->>Backend: Types: GEOMETRY, POINT_2D, LINESTRING_2D, etc.
Backend->>Backend: Map to "geometry" DataType
else Backend is PyArrow with geoarrow metadata
Backend->>Backend: Check ARROW:extension:name metadata
Backend->>Backend: Detect geoarrow.wkb, geoarrow.wkt, geoarrow.*
else Backend is Pandas with GeoSeries
Backend->>Backend: Detect "geometry" dtype from GeoDataFrame
end
Backend->>Backend: Wrap geometry column in GeometryColumnInfo
Note over Backend: Stores encoding (objects/wkb/wkt/other) and external_type
Backend->>Backend: generateColumns() for table
Backend-->>Frontend: Field types with "geometry" for geometry columns
Frontend->>DataTable: Render table with geometry columns
DataTable->>DataTable: NEW: Disable sorting for geometry columns
DataTable->>DataTable: NEW: No filter UI for geometry columns
DataTable->>DataTable: NEW: No format options for geometry columns (formatOptions.geometry = [])
alt Backend produces JSON for table
Backend->>Backend: Format geometry cells with format_geometry_cell()
alt Encoding is "wkb"
Backend->>Backend: Render as "<geometry, {N} B>"
else Encoding is "objects" or "wkt"
Backend->>Backend: Render as WKT string, capped at 512 chars
else Encoding is "other"
Backend->>Backend: Pass through unchanged
end
Backend-->>Frontend: JSON rows with formatted geometry values
else Backend produces IPC for Arrow
Backend->>Backend: NEW: Format geometry in Arrow IPC fallback
Backend-->>Frontend: Arrow IPC bytes with geometry as object strings
end
DataTable->>DataTable: NEW: Apply geometry formatting (no-op in applyFormat)
DataTable->>DataTable: Render geometry icon (MapPinIcon) with cyan color
DataTable->>DataTable: Show "<geometry, N B>" or WKT string in cells
DataTable->>DataTable: NEW: No sort buttons on geometry column headers
DataTable->>DataTable: NEW: No filter dropdown for geometry columns
alt Column summary requested
DataTable->>Charts: Request column chart spec
Charts-->>DataTable: null (NEW: geometry columns produce no chart)
DataTable->>DataTable: Show counts-only stats (total, nulls)
end
alt User views in Vega plugin
Vega->>Vega: NEW: getVegaFieldTypes() maps "geometry" to "string"
Vega->>Vega: Parse geometry values as WKT strings
Vega->>Vega: Render as nominal (categorical) field
end
alt User uses SQL renderer
Backend->>Backend: NEW: SQL stats for geometry returns only total + nulls
Backend-->>Frontend: ColumnStats with unique=null
Frontend->>Frontend: Render geometry column info with MapPinIcon
end
alt User applies filters or sort
Backend->>Backend: NEW: Filter conditions on geometry columns are ignored
Backend->>Backend: NEW: Sort on geometry columns is ignored
Backend-->>Frontend: Filter/sort skipped, warning logged
end
alt User searches table
Backend->>Backend: NEW: Search skips geometry columns
Backend-->>Frontend: Search results exclude geometry matches
end
Note over Backend,Frontend: Shapely serialization (unified)
Backend->>Backend: NEW: enc_hook handles shapely objects without geopandas
Backend-->>Frontend: WKT string representation
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
cc68555 to
79a2da6
Compare
Summary
Detect DuckDB spatial columns from relation/schema metadata as the
geometrysemantic type.GEOMETRYcolumns render safely as WKB placeholders in table JSON, while fixed-layout spatial types (POINT_2D,LINESTRING_2D,POLYGON_2D,BOX_2D) are typed as geometry without value sniffing.SQL metadata now maps DuckDB spatial type strings to
geometry, and geometry SQL stats return counts-only fields (total/nulls). This keeps table and SQL paths consistent for DuckDB spatial data.No frontend changes. Stacked on #10558.
Important
Do not ship in a marimo release until PRs 5-6 of the geometry stack merge.
Closes MO-7325
Made with Cursor