Skip to content

fix(parquet/pqarrow): Change interface name for arrow type on read for extension types - #1028

Merged
zeroshade merged 4 commits into
apache:mainfrom
C-Loftus:tweakNameForExtensionTypeRead
Jul 27, 2026
Merged

zeroshade merged 4 commits into
apache:mainfrom
C-Loftus:tweakNameForExtensionTypeRead

Conversation

@C-Loftus

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

Copy link
Copy Markdown
Contributor

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.

@C-Loftus
C-Loftus requested a review from zeroshade as a code owner July 27, 2026 14:51
Comment thread parquet/pqarrow/schema.go

// ExtensionCustomParquetType is an interface that Arrow ExtensionTypes may implement
// to specify the target LogicalType to use when converting to Parquet.
// to specify the target LogicalType to use when converting to Parquet on write.

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.

Changed to on write since it makes it clearer that it is one side of the read/write path for arrow <-> parquet but worth aligning if there are any cases in which this would be used beyond writing

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

It's safe to change since we haven't released this, so it's fine. I think this is a good idea, thanks! I was actually considering this but wasn't strong enough to warrant blocking the original PR.

@C-Loftus
C-Loftus marked this pull request as draft July 27, 2026 16:29
@zeroshade

Copy link
Copy Markdown
Member

@C-Loftus why the change to draft?

@C-Loftus
C-Loftus marked this pull request as ready for review July 27, 2026 16:33

@C-Loftus C-Loftus left a comment

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.

Made a few extra comment changes. I think these help for clarity. Sorry for switching back to draft after review, figured it would be good to finalize all related comments rather than go back and forth multiple times in separate PRs.

Comment thread parquet/pqarrow/schema.go
// map to the extension type. It should return (nil, err) if the logical type is
// recognized but cannot be converted into a valid extension type. If a
// non-nil extension type is returned, that type is used and any previous
// conversion errors from other extension types are ignored.

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.

While I am making edits on comments, I removed this here and moved it to arrowExtensionFromParquetLogicalType since the comment on ignoring errors is moreso on control flow internal to iceberg-go's extension type resolution process and not the specifically this method.

Comment thread parquet/pqarrow/schema.go
Comment on lines +134 to +138
// ExtensionType when converting a Parquet schema to an Arrow schema on read.
// The receiver is the registered extension type being asked whether it can
// represent the Parquet logical type with the given storage type; callers must
// use the returned extension type because it may be a distinct instance carrying
// per-column parameters derived from the Parquet logical type.

@C-Loftus C-Loftus Jul 27, 2026 •

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 added this comment here since I realized that it might be confusing to a user adding read support for an extension type why an extension type needs itself to return a new extension type struct and it can't just use the existing one after passing it in and seeing no error.

I used the phrase per-column parameters derived from the Parquet logical type. rather than “metadata” because the values are part of the Parquet LogicalType object passed to ArrowTypeFromParquet, such as CRS or geography algorithm fields. “Metadata” could be confused with Arrow field metadata or ARROW:extension:metadata, which this hook does not receive directly.

@C-Loftus
C-Loftus requested a review from zeroshade July 27, 2026 16:46
@zeroshade
zeroshade merged commit 1b1f82f into apache:main Jul 27, 2026
23 checks passed
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.
zeroshade pushed a commit that referenced this pull request Aug 5, 2026
)

## Rationale

Since #1028, the reader reconstructs an extension type directly from a
Parquet logical type (via `ArrowTypeFromParquet`), so the *inferred*
field can now be an extension type rather than the bare storage type it
used to be. `applyOriginalStorageMetadata` still assumed the inferred
type was plain storage when reconciling against the stored
`ARROW:schema`, so when the two extension instances differed it fell
into the "wrap the storage type" branch, found an extension instead of
the storage type, and raised a spurious storage-type mismatch.

This surfaces with GeoArrow WKB: an `authority_code` CRS (e.g. the
default `OGC:CRS84`) round-trips through Parquet's opaque CRS string and
comes back tagged `srid`, so the inferred `WKBType` differs from the one
stored in `ARROW:schema`. Reading any such file — even though the stored
schema is authoritative and correct — failed with:

```
invalid: mismatch storage type 'extension_type<storage=binary>' for extension type 'extension_type<storage=binary>'
```

## Fix

In `applyOriginalStorageMetadata`'s extension branch, when the inferred
type is already an extension of the same name as the origin's, adopt the
origin's (authoritative) parameters instead of requiring the inferred
type to be the bare storage type.

## Testing

Existing `pqarrow` extension/geospatial/store-schema tests pass;
verified end-to-end that a GeoArrow WKB file with default-CRS
(`authority_code`) columns and a stored `ARROW:schema` now reads back
correctly.
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