Skip to content

feat(table): Adding geometry and geography type + schema plumbing - #984

Merged
zeroshade merged 12 commits into
apache:mainfrom
happydave1:feat/geo-type
May 22, 2026
Merged

zeroshade merged 12 commits into
apache:mainfrom
happydave1:feat/geo-type

Conversation

@happydave1

@happydave1 happydave1 commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Based on #628 and addresses #990

Note that this PR sets up a PR to address #991

@happydave1 happydave1 changed the title Feat/geo type feat(table): Adding geometry and geography type + schema plumbing May 6, 2026
@happydave1
happydave1 marked this pull request as ready for review May 6, 2026 20:30
@happydave1
happydave1 requested a review from zeroshade as a code owner May 6, 2026 20:30

@laskoviymishka laskoviymishka 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.

Direction looks good overall: JSON parsing, partition-spec rejection, null-only defaults, v3 gating, and Substrait pass-through all seem aligned with the spec.

I’d hold this before merge on two things:

  1. SchemaVisitorPerPrimitiveType now has VisitGeometry / VisitGeography, and the visitors implement them, but visitField does not seem to dispatch to them yet. So geo columns still fall through to visitor.Primitive(...), which panics for both Arrow and Substrait conversion. That means SchemaToArrowSchema or Substrait conversion can panic on a geo column today.

  2. The geography default algorithm canonicalization seems to differ from Java. The spec default is spherical; Java treats that as the implicit/default form and emits canonical geography for geography(OGC:CRS84, spherical). This PR appears to re-emit the full form, which may cause cross-client schema fingerprint drift for the same logical type.

The rest looks like smaller cleanups. Once these are addressed, happy to take another pass.

Comment thread schema.go Resolved
Comment thread types.go Resolved
Comment thread types.go Resolved
Comment thread types.go Resolved
Comment thread types.go Resolved
Comment thread table/substrait/substrait.go Resolved
Comment thread transforms.go Resolved
Comment thread transforms_test.go Resolved
Comment thread table/update_schema_test.go Resolved
Comment thread table/metadata_builder_internal_test.go Resolved
Comment thread types.go Outdated
Comment on lines +827 to +835
type EdgeAlgorithm string

const (
EdgeAlgorithmSpherical EdgeAlgorithm = "spherical"
EdgeAlgorithmVincenty EdgeAlgorithm = "vincenty"
EdgeAlgorithmThomas EdgeAlgorithm = "thomas"
EdgeAlgorithmAndoyer EdgeAlgorithm = "andoyer"
EdgeAlgorithmKarney EdgeAlgorithm = "karney"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these exist in geoarrow/geoarrow-go, we should use the constants from there instead of defining them here. See https://github.com/geoarrow/geoarrow-go/blob/main/metadata.go

Comment thread exprs.go Outdated
case UUIDType:
return &boundRef[uuid.UUID]{field: field, acc: acc}
case GeographyType, GeometryType:
return &boundRef[[]byte]{field: field, acc: acc}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread table/arrow_utils.go Resolved
Comment thread table/arrow_utils.go Outdated
Comment on lines +643 to +648
// Passthrough binary for now, adding geoarrow-go support later
if c.useLargeTypes {
return arrow.Field{Type: arrow.BinaryTypes.LargeBinary}
}

return arrow.Field{Type: arrow.BinaryTypes.Binary}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@laskoviymishka laskoviymishka 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.

The previous issues look cleanly addressed: visitor dispatch with the failIfGeoFallsBackToPrimitive regression test, default-algorithm canonicalization mirroring CRS(), exact-count test pinning the duplicate-output formatter, and the v2 metadata test now exercising Commit() on v3 metadata.

The geoarrow-go integration also goes further than what I asked for, happy to see WKB extension types instead of a placeholder.

Two things I’d still ask before merge:

  1. toGeoArrowEdgeInterpolation includes EdgePlanar, which isn’t in the Iceberg V3 spec — only spherical | vincenty | thomas | andoyer | karney. That means a Go writer could emit geography(crs, planar) that Java and PyIceberg won’t accept, which is a cross-client wire bug.
  2. The geoarrow-go pseudo-version pin is fragile if upstream force-pushes. I'm fine with this as-is, but worth @zeroshade to confirm this too.

The rest I left inline are nice-to-haves: Equals regression, substrait style, v2 subtest split, cross-client fixture round-trip.

None of those are blocking for me.

One process note: this removes the public EdgeAlgorithm type, its constants, and ParseEdgeAlgorithm. Downstream impact is basically zero today since geo was new here, but the title probably wants feat(table)!: and a release-notes line for the breaking change.

Once EdgePlanar is dropped and the geoarrow-go pin has a tracking issue, happy to approve.

Comment thread types.go Resolved
Comment thread go.mod
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsevents v0.2.0 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/geoarrow/geoarrow-go v0.0.0-20260403143023-f54751c3e3a1 // indirect

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.

Pseudo-version pin (v0.0.0-20260403143023-f54751c3e3a1) is fragile — an upstream rebase or force-push would break our build.

Worth pinning to a tagged release once geoarrow-go cuts one.
I'm ok with that as is, @zeroshade is this fine for you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it an indirect dep? Shouldn't it be a direct dependency?

That said, the pseudo-version is fine for now in my opinion. I'll bug the geoarrow-go repo and see if I can get them to cut a release soon. We should definitely track an issue to update to a release version when it gets cut.

Comment thread types_test.go Resolved
Comment thread table/substrait/substrait.go Resolved
Comment thread table/metadata_builder_internal_test.go Resolved
Comment thread types_test.go
})
}

func TestGeographyType(t *testing.T) {

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.

Won't block this PR, but worth a follow-up: a Java-emitted JSON fixture for a geo schema with non-default CRS + algorithm, parsed here and re-marshaled byte-compared, would lock down the wire compatibility contract before #991 builds on it. The internal Go round-trips we have today guard against regressions in our own code but not against drift from Java's canonical form.

@happydave1
happydave1 requested a review from laskoviymishka May 13, 2026 08:17

@laskoviymishka laskoviymishka 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.

Both round-2 asks and the three nice-to-haves from this batch landed cleanly: EdgePlanar dropped, Equals canonicalization test added, and the v2 subtest split into separate “type unsupported” and “must default to null” cases.

That’s on top of the bigger fixes from before: visitor dispatch with the failIfGeoFallsBackToPrimitive regression test, default-algorithm canonicalization, and geoarrow-go integration.

At this point, I think we’re one focused pass away from approval.

I found two small things on a final read that I’d like fixed before merge:

  1. The bound-ref geo case at exprs.go:454 handles the construction path, but the downstream dispatch sites weren’t updated: exprs.go:637/799/967 and visitors.go:323. So IsNull(Ref("geom_col")) against an optional geo column can still panic today. Fix should be straightforward: add the geo case next to the existing FixedType / BinaryType arms at each site.

  2. Small canonicalization gap in GeometryTypeOf / GeographyTypeOf: strings.EqualFold compares the raw constructor input, but the validation above does trim + lowercase. So programmatic callers passing whitespace can get a non-canonical zero value back, and Equals against literal GeographyType{} returns false. JSON path is fine because it trims before calling. Should be a one-line fix in each branch.

That’s the full list from me. The Substrait one-liner is already in dialogue — just a gofmt nit, not a blocker. The fixture round-trip test I flagged earlier is clearly follow-up scope.

Once the dispatch coverage and canonicalization fixes are in, I’m happy to approve.

Comment thread table/substrait/substrait.go Resolved
Comment thread exprs.go Outdated
case UUIDType:
return &boundRef[uuid.UUID]{field: field, acc: acc}
case GeographyType, GeometryType:
return &boundRef[[]byte]{field: field, acc: acc}

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.

Found while tracing this — createBoundRef handles geo here, but four downstream dispatch sites that switch on the same Type don't, and they're inconsistent in how they fail.

exprs.go:637 (unary predicate dispatch) — case FixedType, BinaryType doesn't include geo, falls through to panic("unhandled bound reference type: ...") at line 644. IsNull(Ref("geom_col")) on an optional geo column (exactly the case this PR's null-default rule enforces) crashes the process.

exprs.go:799 (literal predicate) and exprs.go:967 (set predicate) — same shape, friendly error on fall-through.

visitors.go:323 (doCmp) — case BinaryType, FixedType falls through to panic(ErrType) at line 332. Metric-evaluation paths hit this.

Two options: (a) add case GeometryType, GeographyType at all four sites, treating geo as []byte like Binary — most useful since IsNull / NotNull / IsIn(null) on geo are semantically valid; (b) reject geo in createBoundRef so all expression paths fail consistently at bind. I'd take (a).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks!

I took option A - it made the most sense to me. Now the downstream dispatch sites should handle the geo-types more consistently.

Comment thread types.go Outdated
return GeographyType{}, fmt.Errorf("invalid algorithm: %w", err)
}
normalizedAlgorithm := string(validatedAlg)
if strings.EqualFold(algorithm, defaultGeographyAlgorithm) {

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.

Canonicalization branches on the raw input, not the validated form. toGeoArrowEdgeInterpolation above trims and lowercases, but strings.EqualFold(algorithm, defaultGeographyAlgorithm) here compares against the raw string — so GeographyTypeOf("srid:4326", "spherical") normalizes to {algorithm: ""} but GeographyTypeOf("srid:4326", " spherical ") keeps {algorithm: "spherical"}. Two semantically identical types whose Equals returns false. JSON path trims before calling so this is invisible there, but Go callers can trip it.

One-line fix — branch on validatedAlg, not algorithm:

if validatedAlg == geoarrow.EdgeInterpolation(defaultGeographyAlgorithm) {
    normalizedAlgorithm = ""
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I will update this!

Comment thread types.go Outdated
if crs == "" {
return GeometryType{}, fmt.Errorf("%w: invalid CRS: (empty string)", ErrInvalidTypeString)
}
if strings.EqualFold(crs, defaultGeoCRS) {

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.

Same shape as the algorithm canonicalization in GeographyTypeOf below — strings.EqualFold(crs, defaultGeoCRS) compares the raw input, so GeometryTypeOf("OGC:CRS84") normalizes to the zero value but GeometryTypeOf(" OGC:CRS84 ") doesn't. Trim at the top of the constructor (crs = strings.TrimSpace(crs)) to make canonicalization tolerant.

@happydave1

Copy link
Copy Markdown
Contributor Author

Thanks for the clear and precise review last round @laskoviymishka. Good catches on all the issues presented.

I have added Geography and Geometry cases to all 4 locations mentioned in the dialogue around the createBoundRef issue.

I have also fixed the canonicalization issue for both GeographyTypeOf and GeometryTypeOf - this was a good catch since we handle algorithm with a strings.TrimSpace as well in toGeoEdgeInterpolation.

Finally, I fixed the Substrait one-liner by making VisitGeometry a multi-line function. This will make it consistent with VisitGeography.

Please let me know what you think, any feedback would be greatly appreciated. Thanks!

@laskoviymishka laskoviymishka 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.

:shipit:, all things covered, let's wait for @zeroshade to stamp

@zeroshade

Copy link
Copy Markdown
Member

I'll take a look at this today for a final pass. Can you resolve the conflicts in the meantime?

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just needs to have the conflicts resolved and then we can merge!

@zeroshade

Copy link
Copy Markdown
Member

I believe if you rebase it should solve the integration test CI issue.

@happydave1

Copy link
Copy Markdown
Contributor Author

I've rebased locally but it seems that origin/main tests are still failing when running make test. Specifically TestTableWriting tests. Correct me if I am wrong but is #1102 maybe related to this?

@zeroshade
zeroshade merged commit 6a4c96e into apache:main May 22, 2026
14 checks passed
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.

4 participants