Repository navigation
feat(datagrid): add a Map view for results holding a geometry column (#2532) - #2806
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Member
Author
|
Driven end to end against a SQLite database with a The docs page ships without its |
Signed-off-by: Ngô Quốc Đạt <[email protected]>
… feat/spatial-map-view-2532
…he trigger test asserts it runs Claude-Session: https://claude.ai/code/session_01GdkP9Kj2oVdzM5acwU69A3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #2532.
A result holding a geometry column gains a Map segment beside Data, JSON and Chart. Points,
lines and polygons draw over Apple's own tiles, clicking a shape selects its row, and the pane says
what it could not draw and why.
Why AppKit
MKMapViewand not SwiftUIMapMeasured, not preferred. Grepping every MapKit header: MapKit publishes no overlay selection and
no overlay hit-test API at any layer. The only selection API in the framework is
selectAnnotation:/selectedAnnotations/didSelectAnnotationView:(MKMapView.h:201-203,289-294), and it covers annotations only. A click on a polygon or a line can be resolved onlythrough
MKOverlayPathRenderer.pathplusMKOverlayRenderer.point(for:), and the renderer isreachable only via
MKMapView.renderer(for:). SwiftUI'sMapexposes neither its map view nor itsrenderers, so a tagged
MapPolygoncan never report a hit. Two further blockers:MapSelectionismacOS 15+ (
_MapKit_SwiftUI.swiftinterface:848), and SwiftUI'sMapPolygonhas nointeriorPolygonsinitializer (:547), so it cannot draw a polygon with a hole at all.Scale says the same thing. Measured on this machine, adding overlays to a live
MKMapView:MKPolygonper rowMKMultiPolygonA result page holds up to 100,000 rows, so every polygon row goes into one
MKMultiPolygonandevery line row into one
MKMultiPolyline, with the selection as a single extra overlay swapped onclick (0.170 ms measured) and points as clustered annotations.
Privacy, which is the request's premise
Measured: a process showing a fully rendered
MKMapViewholds zero network sockets. Tiles arefetched out of process by
com.apple.geod.xpc. Nothing about a result reaches a third-party tileserver.
The reader
One shared SwiftPM target,
Packages/TableProCore/Sources/TableProGeometry, because the MySQLplugin already contained a second hand-rolled WKB parser that had to agree with it. It reads WKT,
EWKT, WKB, EWKB hex and GeoJSON, and every spelling in its test table came off a live server during
the investigation: PostGIS 3.6.4, MySQL 8.4.11, MariaDB 12.3.3, DuckDB 1.5.4. They disagree with
each other, which is why the table is the specification:
SRID=n;only when the SRID is non-zero, writes XYZ as a barePOINT(1 2 3), XYMas
POINTM(1 2 3)rather than the OGCPOINT M (, and MULTIPOINT bare.MULTIPOINT((1 2),(3 4))and an invalidGEOMETRYCOLLECTION().POINT (1 2).ST_AsEWKTrewrite fails, with the column still typedgeometry, so hex has to read too.The MySQL axis-order trap
MySQL 8.4's
ST_AsTextprints a SRID-4326 point latitude first, andST_GeomFromText('POINT(-122.4194 37.7749)', 4326)fails with "Latitude -122.419400 is out ofrange". But the stored bytes are longitude first, byte-identical on MySQL 8.4.11 and MariaDB
12.3.3:
So TablePro's MySQL geometry text was already correct and needs no reordering. "Make the parser
agree with
ST_AsText" is the plausible-looking change that would move every MySQL point into theSouthern Ocean, and
GeometryWKBParserTests.storageIsLongitudeFirstexists to stop it.SRID handling
4326, 4269 and 4979 draw directly. Web Mercator (3857, 900913, 3785, 102100, 102113) is inverted by
closed form, verified against PROJ 9.8.1 to 1e-9, with no projection library. A column carrying no
SRID draws when every coordinate fits the longitude/latitude envelope, and says so. Anything else is
refused by name, with the remedy:
Mixed SRIDs in one column draw the majority and state the count of the rest. The map never rewrites
the cell: the grid's text stays authoritative.
Coordinates are validated before any shape is built, because
MKMapPoint(coordinate)returns thesentinel
(-1, -1)outside the valid range rather than wrapping, which is garbage outsideMKMapRectWorldand would destroy the extent fold.Shipped alongside, because the feature needs them
geo_pointclassified as.integer.classifyByPatterntestshasSuffix("INT")andGEO_POINTends inINT. Confirmed by compiling and running the real classifier. It drove cellalignment, sort comparators and filter operators for every Elasticsearch
geo_pointcolumn, withor without a map, so it carries its own CHANGELOG entry.
geomcollectionclassified as text. MySQL 8.0.11 renamed the type; measured on 8.4.11, itscatalog reports
geomcollectionfor a column declared either way, and neither spatial list had it.degrees. Two more parser bugs went with it: an empty collection rendered as the invalid
GEOMETRYCOLLECTION(), and a Z or M ordinate desynchronised the cursor.ResultsModeAvailability.modesreturns[]for a query tab with no columns, which hides the switcher and disables all four View menu items
while still ticking the current one. The items carry no key equivalent, so nothing was left to
press. A succeeding non-SELECT does this on every run. The mode now reconciles where rows are
installed.
GridSelectionOwner.resolvewas an if-chain naming.chartas an exception list of one, so afifth mode fell through and silently claimed the data grid's channel. It is now an exhaustive
switch that cannot compile without an answer.
What decides whether Map is offered
The column's values, not its declared type, and this is the review's largest change. The type is
wrong in both directions. Oracle's
SDO_GEOMETRY, Teradata'sST_GEOMETRYand SQL Server'sgeographyall classify.spatialand hand over text no reader can draw, so a type-only gateoffered Map and drew nothing. MongoDB goes the other way: its GeoJSON arrives in a column the app
types
JSON, so a type-only gate never offered Map for the engine whose spatial data is most oftenGeoJSON.
SpatialColumn.columns(in:)now samples up to four values per candidate column. The twodeclarations carry different weight, because they say different things:
.spatialis the engine's own word that the column holds geometry, so it is believed unlessthe values contradict it. An empty result and an all-NULL column both keep the segment, which is
what stops the mode appearing and vanishing as pages load.
JSONsays nothing about geometry, so it earns the segment only by holding a value that reads.The decision is per column and never per value, the rule the MongoDB UUID codec exists for, and it
is taken once where the rows are installed rather than on every status-bar render:
TabDisplayStatecarries the answer and
MainContentCoordinator.installTableRowsis the only writer.Working now, with no plugin release: PostgreSQL/PostGIS, MySQL/MariaDB, MongoDB, Snowflake,
Elasticsearch and ClickHouse. SQL Server, Oracle, DuckDB, SpatiaLite, Teradata, Trino, Spanner,
Cassandra and BigQuery hand geometry over in formats the reader does not cover, so their columns
carry no segment. That sentence is now enforced by the code rather than asserted by the docs, which
is what keeps it from going stale the next time a driver changes its text format.
Two defects found by building it, not by reading it
Both were in this branch and both are fixed here.
A click on a shape never reached the app. An
NSClickGestureRecognizeradded toMKMapViewhas to win an arbitration against MapKit's own pan and zoom recognizers, and it does not: measured,
the action never fired, with and without a delegate answering
shouldRecognizeSimultaneouslyWith.ResultMapSurfaceoverridesmouseUpinstead, which isNSResponder's own path and needs noarbitration, and it calls
superso panning and zooming are untouched. A press that moves more thanthree points is a pan, not a click.
A hole counted as part of its polygon.
CGPath.containsdefaults to the non-zero winding rule,and a polygon's interior rings wind the same way as its exterior, so a click in the middle of a hole
selected a shape that was not under the pointer. Measured:
truefalsetruetruefalsefalseMKPolygonRendererfills with even-odd for the same reason, which is why the hole looks empty onscreen. The hit test now matches what is drawn.
The reason both shipped in the first place is worth naming: the hit test lived inside the
coordinator, where only a running app could reach it. It is now a pure
ResultMapHitTestingwith aheadless suite, and that suite is what caught the hole.
A third followed from them: the status bar refused to report a selection in Map mode, because
reportedSelectionkeyed offshowsColumnControls, which is about column chrome. Map both readsthe selection and sets it, so the count is now gated on a dedicated
reportsRowSelection.What the review changed
Fourteen findings, six of them P1, all fixed.
The iOS target did not compile. The mobile app builds
Plugins/MySQLDriverPlugin/GeometryWKBParser.swift, which now importsTableProGeometry, andTableProMobile/project.ymldid not list that product.TableProGeometrybuilds forgeneric/platform=iOS Simulatoron its own; the mobile app target still stops on the pre-existing@TaskLocalmacro error inside the vendoredoracle-niocheckout, which predates this branch.A map click did not survive the trip to Data mode. The shared selection channel alone is not
enough: the grid remounts and restores the tab's own stored selection over it, which a map click
never wrote. The
.maparm now stores it too, with an empty cell rectangle because a shape names arow and no columns.
Two of the three paths that replace a result skipped the mode reconciliation.
seedBufferFromActiveResultandapplyResultSetSwitchboth wrote the rows straight into theregistry. All three now go through one
installTableRows, which is also where the geometry columnsare decided, so the two answers cannot drift apart.
The selection was one overlay per row. Measured, that is 1.32s at 5,000 rows and 125s at 50,000,
the same curve the base layer avoids, and it made the renderer lookup a linear scan of the selection
on every overlay MapKit draws. The highlight is now one
MKMultiPolygonand oneMKMultiPolyline,told apart from the base layer by identity rather than by class.
Hit-testing ran in the wrong order. The polyline overlay is added after the polygon one, so a
line drawn across a polygon is what the reader is pointing at, and testing polygons first selected
the shape underneath. Point rows now highlight too, marker and cluster both.
Budgets were checked once per row. One row can be a MULTIPOINT or a GEOMETRYCOLLECTION of any
size, so the first row alone could put millions of shapes on the map. The budget is spent shape by
shape, and a row it cuts short is reported as capped as well as drawn.
Nesting had no bound. Every wire format lets a geometry collection nest without limit and each
level is one more stack frame, so a few hundred bytes of nothing but collection headers would
exhaust the stack rather than fail. All three readers and the projector refuse past
SpatialLimits.maximumNestingDepth.The pane blamed the coordinate system for a parse failure.
projectabilitycarries.unsupported(srid: nil)as its own default, so a column where nothing parsed was indistinguishablefrom one whose SRID cannot be projected, and a column of
CIRCULARSTRINGwas told its coordinateswere out of range.
readableRowsis asked first.Three wire formats were read wrong or not at all. ClickHouse writes a
Tuplein parentheses andan
Arrayin square brackets, whichClickHouseTabSeparatedRowDecoderTestsalready pins, so everyRing,PolygonandMultiPolygonwas rejected before parsing. Elasticsearch'sgeo_pointislegally six shapes and only
"lat,lon"was handled; the object, array and geohash forms are readnow, with the axis order that each one actually uses. And
geo_shapevalues were cut off at 10,000characters by the flattener, which made the JSON unparseable, so a geometry is kept whole.
The reconciliation UI test could pass while reconciliation was broken. Its second query opened a
fresh tab with Cmd+T, and a fresh tab starts on Data. It now runs in the tab that was on Map.
Verification
verify.sh build: PASS.swift test --filter TableProGeometryTests: 75 passed, 0 failed.verify.sh testover the affected suites: 102 and 203 executed, all passed.xcodebuild -scheme TableProGeometry -destination 'generic/platform=iOS Simulator': BUILDSUCCEEDED.
verify.sh uitest ResultMapModeUITests: 6 executed, 6 passed. The Map segment appears only with ageometry column, a tab left on Map lands back on Data in the same tab, and clicking a shape
selects its row.
verify.sh plugins(theAllPluginsaggregate) fails only on the pre-existing@TaskLocalmacroerror inside the vendored
oracle-niocheckout. No error touches anything here, andMySQLDriverbuilt alone succeeds with zero errors.
swiftlint lint --strictover every new file, including the package and the plugin, which a barerun does not see.
docs/scripts/check-writing-style.shandcheck-docs-against-source.py: both pass.Screenshot
The docs section ships without its
<Frame>. The feature was driven end to end against a SQLitedatabase with a
POLYGON-declared column, and the capture is attached to this PR: six San Francisconeighbourhoods drawn over Apple Maps in the right places, with
Drawing 6 shapes in SRID 4326.inthe toolbar. A matched light and dark pair at 1560x960 is what
docs/STYLE.mdrequires and what thismachine could not produce, so the page carries prose alone rather than a mismatched image.
Accessibility
MKMapViewreports itself as a single image and publishes no children for overlays (measured), andMapKit has no accessibility API for them. A SwiftUI
accessibilityLabelon the representable is notreadable from the accessibility tree either (measured: empty). The map is therefore supplementary and the data grid stays
the readable representation of spatial rows; the map view carries a summary label, and point
annotations speak for themselves. This is stated in the docs rather than left for a user to discover.
https://claude.ai/code/session_01GdkP9Kj2oVdzM5acwU69A3