Skip to content

feat(parquet/pqarrow): Read support for extension types / geo - #969

Merged
zeroshade merged 5 commits into
apache:mainfrom
C-Loftus:geoReadSupport
Jul 24, 2026
Merged

zeroshade merged 5 commits into
apache:mainfrom
C-Loftus:geoReadSupport

Conversation

@C-Loftus

@C-Loftus C-Loftus commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

In #960 I implemented write support for extension types by mapping a logical type to its underlying primitive/arrow type. In the case of geometry this allows the logical geometry type to be mapped to byte array for storage.

This PR implements the read path for that by adding the parquet type to arrow type functionality. For example, a user can read a parquet with a geometry column and with this change, the reader will try to map it to the designated associated arrow extension type.

What changes are included in this PR?

An extension type can implement this interface to designate which arrow type should be used when reading it from parquet.

type ExtensionParquetLogicalType interface {
	ArrowTypeFromParquet(logical schema.LogicalType, storageType arrow.DataType) (arrow.ExtensionType, error)
}

The read path will try to iterate through all the extension types, see if there are any matches where the type implements ArrowTypeFromParquet and gives us something to map it to in arrow. If so we use that for reading.

Are these changes tested?

Yes

Are there any user-facing changes?

Yes. Readers can now support arbitrary extension types as long as they are registered properly in the extension type registry.

@C-Loftus
C-Loftus requested a review from zeroshade as a code owner July 21, 2026 12:30
Comment thread parquet/pqarrow/schema.go
Comment on lines +541 to +543
case schema.GeometryLogicalType,
schema.GeographyLogicalType:
return arrowExtensionFromParquetLogicalType(logical, arrow.BinaryTypes.Binary)

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.

Is there a way I can allow it to efficiently check either Binary or LargeBinary to allow decoding either 32 bit or 64 bit wkb values? I think at the moment this will only handle reading 32 bit. I can also just add a second case here in case the first arrowExtensionFromParquetLogicalType(logical, arrow.BinaryTypes.Binary) call returns no mapping? (i.e. try again with arrowExtensionFromParquetLogicalType(logical, arrow.BinaryTypes.LargeBinary)?)

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.

I don't think there's a way for it to tell from the logical type whether or not it should use Binary or LargeBinary (or BinaryView). The difference is solely whether or not there happens to be more than 2GB worth of data in a single record batch. So even if you were to add a second case here, it's likely not a useful thing (all extension types that support Binary should also support LargeBinary and vice versa).

The better solution here, like the usage of String instead of LargeString above, is to ensure that we properly promote to LargeBinary if necessary, but that can be a follow-up

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

Using your testGeometryType add a round trip test that uses it (and the interface) to write and then read back the registered extension type while making sure the StoreSchema option is false

Comment thread parquet/pqarrow/schema.go
Comment on lines +541 to +543
case schema.GeometryLogicalType,
schema.GeographyLogicalType:
return arrowExtensionFromParquetLogicalType(logical, 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.

I don't think there's a way for it to tell from the logical type whether or not it should use Binary or LargeBinary (or BinaryView). The difference is solely whether or not there happens to be more than 2GB worth of data in a single record batch. So even if you were to add a second case here, it's likely not a useful thing (all extension types that support Binary should also support LargeBinary and vice versa).

The better solution here, like the usage of String instead of LargeString above, is to ensure that we properly promote to LargeBinary if necessary, but that can be a follow-up

@C-Loftus
C-Loftus requested a review from zeroshade July 21, 2026 17:56
@C-Loftus

Copy link
Copy Markdown
Contributor Author

Believe I have addressed feedback by adding the round trip test and ensuring WithStoreSchema is never called, thus using c.props.storeSchema = false by default

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

Thanks for adding the read path — the round-trip-without-stored-schema test is exactly what was needed, and scoping to byte-array (matching GeometryLogicalType/GeographyLogicalType.IsApplicable, which are ByteArray-only) is correct.

I'm requesting changes on two points that interact badly:

  1. Resolution over the registry is non-deterministic (sync.Map-backed enumeration).
  2. An error from any single registered extension aborts the whole schema conversion.

Together they mean a read can non-deterministically succeed or fail depending on map iteration order. Details inline, plus a naming/API note and a test-coverage gap.

Happy to pair on direction — either a deterministic ordering (name-sorted snapshot + first match) or an explicit logical-type -> extension registration, rather than "ask every registered type".

Comment thread arrow/datatype_extension.go Resolved
Comment thread parquet/pqarrow/schema.go
Comment on lines +135 to +137
type ExtensionParquetLogicalType interface {
ArrowTypeFromParquet(logical schema.LogicalType, storageType arrow.DataType) (arrow.ExtensionType, error)
}

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.

Naming/symmetry nit on exported API: the write side is ExtensionCustomParquetType.ParquetLogicalType() and this read side is ExtensionParquetLogicalType.ArrowTypeFromParquet(). A round-trippable extension has to implement both, and the two interface names are easy to confuse. Consider a symmetric pair (e.g. ...ToParquet / ...FromParquet) or folding both directions into a single interface. Harder to change once released.

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.

I agree with this comment ideally although isn't ExtensionCustomParquetType already in the public API so it would not be possible to change that? As such I think I am a bit stumped on how to name this with breaking existing extension type resolution.

i.e. to my understanding I don't think I could change it to be a symmetric pair since there is already a ParquetLogicalType() function which doesn't have a clear symmetric parallel. Feel free to suggest any name if I am overlooking a good option.

https://github.com/apache/arrow-go/blob/main/parquet/pqarrow/schema.go#L128

Comment thread parquet/pqarrow/schema.go Resolved
Comment thread parquet/pqarrow/schema.go Resolved
Comment thread parquet/pqarrow/schema.go Resolved
@C-Loftus

Copy link
Copy Markdown
Contributor Author

Ok believe I have addressed feedback. Thanks for the review!

  • I will defer to you on the interface naming. feat(parquet/pqarrow): Read support for extension types / geo #969 (comment) in light of the currently exported pre-existing public interface methods.
  • I have changed the registration type lookup to be FindRegisteredExtensionType which is both lexicographically deterministic and returns one item. If this is overkill I can revert or change as you prefer.

@C-Loftus
C-Loftus requested a review from zeroshade July 22, 2026 18:24

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

Thanks for the thorough revision — this addresses both of my blocking concerns.

  • Resolution is now deterministic via the name-sorted FindRegisteredExtensionType, and TestFindRegisteredExtensionType registers the higher name first so the tie-break is actually exercised rather than passing by registration order.
  • A single extension's error no longer aborts the whole FromParquet: "not mine" is (nil, nil) and continues, the first error is deferred and only surfaced when nothing matches, and TestFromParquetGeospatialRegisteredExtensionContinuesAfterConverterError proves that a failing type which sorts first doesn't block a later valid one.
  • The Binary fallback for unregistered geometry/geography is now covered and the behavior change is locked in.

Built the branch locally: the new tests pass, go vet is clean, and -race is clean on both arrow and parquet/pqarrow.

On the interface naming you flagged: since ExtensionCustomParquetType.ParquetLogicalType() is already public, a fully symmetric pair isn't worth the churn — ExtensionParquetLogicalType is fine to ship as-is.

Approving. Two optional, doc-only nits inline that would help future implementers — neither blocks merge.

Comment thread parquet/pqarrow/schema.go
Comment on lines +135 to +136
type ExtensionParquetLogicalType interface {
ArrowTypeFromParquet(logical schema.LogicalType, storageType arrow.DataType) (arrow.ExtensionType, error)

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.

Optional, doc-only: worth spelling out the return-value contract here, since third-party types implement this against the exported interface:

  • (nil, nil) → "not my logical type"; resolution skips this extension and continues.
  • (nil, err) → recognized the logical family but couldn't construct a valid type; the error is deferred and only surfaced if no other extension matches.
  • non-nil type → wins, taking precedence over a deferred error from an earlier (name-sorted) extension.

The test doubles already follow this — it's just about making the contract explicit on the exported API.

Comment thread arrow/datatype_extension.go Outdated
Comment on lines +94 to +97
// We first sort the types by name to ensure that we return the
// type with the lexicographically smallest name. We sort then filter
// to ensure that there are no side effects from filtering which would
// affect the determinism of the result.

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.

Minor wording: "no side effects from filtering" reads as if the filter is required to be pure, but what this actually guarantees is that iteration runs over a stable, name-sorted snapshot, so the result is deterministic regardless of sync.Map's Range order. Maybe something like:

// Snapshot and sort the registered names before invoking the filter so the
// result is deterministic (lexicographically smallest match), independent of
// sync.Map's unspecified Range order.

@C-Loftus

Copy link
Copy Markdown
Contributor Author

Have added the feedback comments! Thanks for your review!

When we merge, at your convenience, when you produce a new arrow-go release, could you ping me? I will then add the necessary functions to geoarrow-go, bump iceberg-go to use them, and then we should have a full end to end for iceberg geo read and write support

@zeroshade
zeroshade merged commit 51bb272 into apache:main Jul 24, 2026
23 checks passed
zeroshade pushed a commit that referenced this pull request Jul 27, 2026
…r extension types (#1028)

### Rationale for this change

#969 added an interface for a custom arrow type on read for arrow
extension types. This allows a type like geometry to be resolved to the
underlying arrow physical type like byte array.

However, I went to implement this in geoarrow-go today and upon further
investigation I think the interface name is slightly confusing. The
interface `ExtensionParquetLogicalType` doesn't actually include the
`ParquetLogicalType` method but rather it intended to be used to specify
the arrow type from parquet on read. As such I have renamed
`ExtensionParquetLogicalType` to something more distinct.

I figure it makes sense to solidify this before creating a new arrow-go
release and adding it to iceberg-go whereupon it will be much harder to
change.

I changed the interface name to indicate that it is one side of the
read/write path for extension types. I think this is a bit more clear
but if I am misunderstanding and it might be used in both read and
write, then maybe it doesn't make sense.

### What changes are included in this PR?

Comments and a change in the name of an interface. This interface is not
yet in a published release but is on main. Since its only been a few
days, I think it is reasonable to change this.

### Are these changes tested?

Yes

### Are there any user-facing changes?

Yes. Change in interface name. But no changes in behavior.
dwilson1988 pushed a commit to geoarrow/geoarrow-go that referenced this pull request Jul 28, 2026
In apache/arrow-go#1028 /
apache/arrow-go#969 I added logic for reading
extension types within the arrow-go Parquet reader. This allows us to
resolve reads against geo extension types and preserve the proper
metadata.

The gist is that an extension type must implement the
`ArrowTypeFromParquet` function (defined
[here](https://github.com/apache/arrow-go/blob/1b1f82f5848cb84226e9bc502bb8ae764014add2/parquet/pqarrow/schema.go#L144))
which tells the reader how to resolve the extension type given the
Parquet Logical type and underlying storage.

This implements that function so that the parquet reader works and
preserves the proper crs / edge algorithm metadata. It also adds a few
round trip tests.

I have bumped to the latest arrow-go version. Once a new semantic
version is released that isn't just the HEAD commit, we can bump that in
a follow up. Once everything is stable and aligned on a common release,
I can bump the versions used by iceberg-go. However, I figured no reason
to wait on that to review this PR.
@C-Loftus
C-Loftus deleted the geoReadSupport branch July 28, 2026 20:24
dwilson1988 pushed a commit to geoarrow/geoarrow-go that referenced this pull request Sep 23, 2026
Bumps the arrow version to
https://github.com/apache/arrow-go/releases/tag/v18.8.0 via `go get
github.com/apache/arrow-go/[email protected]`

This should bring in a variety of logical type resolution behavior
needed for end to end read / write support for geometry from upstream
libraries like iceberg-go. iceberg-go should eventually be bumped to
have the same arrow-go dependency as well so this should keep everything
in sync.

Some of the geo-related PRs this will bring in include the following
apache/arrow-go#960
apache/arrow-go#969
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.

2 participants