Skip to content

feat: detect duckdb spatial columns as geometry - #10592

Open
kirangadhave wants to merge 8 commits into
kg/geometry-pyarrow-adapterfrom
kg/geometry-duckdb-adapter
Open

feat: detect duckdb spatial columns as geometry#10592
kirangadhave wants to merge 8 commits into
kg/geometry-pyarrow-adapterfrom
kg/geometry-duckdb-adapter

Conversation

@kirangadhave

Copy link
Copy Markdown
Member

Summary

Detect DuckDB spatial columns from relation/schema metadata as the geometry semantic type.

GEOMETRY columns 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

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Aug 19, 2026 7:32pm

Request Review

@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label Aug 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kirangadhave kirangadhave added the enhancement New feature or request label Aug 19, 2026
@kirangadhave
kirangadhave marked this pull request as ready for review August 19, 2026 16:52
Copilot AI lite review requested due to automatic review settings August 19, 2026 16:52
@kirangadhave
kirangadhave changed the base branch from main to kg/geometry-pyarrow-adapter August 19, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) as geometry in geometry schema detection.
  • Map DuckDB spatial type strings to geometry in SQL metadata/type mapping and return counts-only stats for geometry SQL 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.

Comment thread tests/_data/test_sql_summaries.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 78.78% 82078 / 104180
🔵 Statements 78.78% 82078 / 104180
🔵 Functions 71.67% 706 / 985
🔵 Branches 79.46% 4975 / 6261
File CoverageNo changed files found.
Generated in workflow #20603 for commit f44366f by the Vitest Coverage Report Action

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread marimo/_server/ai/providers.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants