Repository navigation
feat(parquet/pqarrow): Read support for extension types / geo - #969
Conversation
| case schema.GeometryLogicalType, | ||
| schema.GeographyLogicalType: | ||
| return arrowExtensionFromParquetLogicalType(logical, arrow.BinaryTypes.Binary) |
There was a problem hiding this comment.
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)?)
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
| case schema.GeometryLogicalType, | ||
| schema.GeographyLogicalType: | ||
| return arrowExtensionFromParquetLogicalType(logical, arrow.BinaryTypes.Binary) |
There was a problem hiding this comment.
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
|
Believe I have addressed feedback by adding the round trip test and ensuring |
zeroshade
left a comment
There was a problem hiding this comment.
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:
- Resolution over the registry is non-deterministic (
sync.Map-backed enumeration). - 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".
| type ExtensionParquetLogicalType interface { | ||
| ArrowTypeFromParquet(logical schema.LogicalType, storageType arrow.DataType) (arrow.ExtensionType, error) | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Ok believe I have addressed feedback. Thanks for the review!
|
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for the thorough revision — this addresses both of my blocking concerns.
- Resolution is now deterministic via the name-sorted
FindRegisteredExtensionType, andTestFindRegisteredExtensionTyperegisters 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, andTestFromParquetGeospatialRegisteredExtensionContinuesAfterConverterErrorproves 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.
| type ExtensionParquetLogicalType interface { | ||
| ArrowTypeFromParquet(logical schema.LogicalType, storageType arrow.DataType) (arrow.ExtensionType, error) |
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
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.
|
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 |
…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.
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.
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
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.
The read path will try to iterate through all the extension types, see if there are any matches where the type implements
ArrowTypeFromParquetand 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.