Skip to content

API, Core, Parquet: Model the file type as its own nested type - #17821

Draft
RussellSpitzer wants to merge 9 commits into
apache:mainfrom
RussellSpitzer:custom_file_type
Draft

API, Core, Parquet: Model the file type as its own nested type#17821
RussellSpitzer wants to merge 9 commits into
apache:mainfrom
RussellSpitzer:custom_file_type

Conversation

@RussellSpitzer

Copy link
Copy Markdown
Member

An alternative implementation of the file logical type from #17808 which treats File as a new non-primitive special type. This is a little similar to Variant in that all visitors now have special handling for File type and you can't write a "bad" visitor which treats a File like a struct when it shouldn'd.

  • API, CORE, PARQUET: Implicit struct file type #17808 (design A): Types.FileType extends StructType, typeId() == STRUCT.
    Visitors see a struct and behave correctly for free; the few places that must
    not expand or rewrite a file carry isFileType() guards.
  • This PR (design B): Types.FileType is a new Type with it's own typeId. Vistors either fall back to struct behavior with FileType.asStruct or have custom logic file()

AI Disclosure

  • Model: Claude Opus 5
  • Platform/Tool: Cursor
  • Human Oversight: partially reviewed
  • Prompt Summary: Implement the file logical type as a standalone NestedType
    with its own TypeID and per-visitor file() hooks, as an alternative to the
    StructType-subclass approach in API, CORE, PARQUET: Implicit struct file type #17808, and measure the difference in files
    touched, lines changed, engine breakage, and latent switch-statement risk.

Persist the type as "file" and expand it to a closed nested struct whose field IDs are derived from the enclosing field.

Generated-by: Cursor Grok 4.6
ReassignDoc rebuilt every struct it visited, so reassigning docs turned a
file column into a plain struct that no longer serializes as "file" or
honors the format version gate. Return the file type unchanged there and
in ReassignIds, matching the other assigners.

The new two-argument GetID overload ignored the reservation request, so
an implementation that did not override it could hand out IDs inside a
file's derived block and produce duplicate field IDs with no error. Fail
when the reservation cannot be honored.

ReassignConflictingIds moved a field only when its own ID conflicted, so
a file column kept an ID whose derived block overlapped IDs already in
use. Move the column when any of its reserved IDs is unavailable.

Also consolidate the helper that rebuilds a file type from a newly
assigned ID into TypeUtil.assignedType, and drop the test prefix from the
schema evolution tests added for this type.

Generated-by: Cursor Claude Opus 5
Derived ID validation in the schema parser was only covered for struct
fields and list elements. Add the map key and map value cases, along with
a round trip for a file used as a map key.

Add Parquet conversions for a required file column and for a file used as
a list element and as a map value, plus a data round trip for a file
inside a list.

Record that reassigning a file column tracks only the enclosing ID,
because the nested IDs are derived from it, and split the combined rename
and delete test into one test per operation.

Generated-by: Cursor Claude Opus 5
The file type had its own constant because the map was keyed by type ID
and the file type reports STRUCT, so a STRUCT key would have gated every
struct. Key the map by class instead, which identifies a logical type
even when two of them share a type ID, and drop the separate constant so
all minimum versions are declared in one place.

Make the file type final so the class key is exact.

Generated-by: Cursor Claude Opus 5
Passing zero reserved IDs used the argument as a sentinel for "do not
reserve", which hid the fact that the overload exists only for types
whose nested field IDs are derived. Branch on the type so the plain
overload is used for everything else.

Generated-by: Cursor Claude Opus 5
Tests for name resolution, Java serialization, format version gating,
readability, projection, doc reassignment, accessors, and expression
binding now live beside the code they exercise, so a change to those
utilities surfaces the file type expectations. TestFileType keeps the
type contract and the reserved ID block, which no existing class owns.

Add coverage for selecting and filtering a file subfield. Drop tests that
only re-exercised generic behavior: rejecting defaults applies to every
nested type, and the list round trip is already covered by the list
schema conversion plus the file round trip.

Generated-by: Cursor
FileType.fieldId() returned the ID of the field that holds the type, not
an ID of the type itself, which read as though it mirrored
NestedField.fieldId(). Rename it to enclosingId() to match the name the
parser already used for the same value.

Report the short type name when a file and a struct are not
interchangeable instead of formatting a whole struct into the error.

Generated-by: Cursor
Reshape Types.FileType as a Type.NestedType sibling of StructType with its
own TypeID.FILE, and add file() hooks to the schema visitor bases so that
visitors opt in to file handling instead of inheriting struct behavior.

Generated-by: Cursor (Claude Opus 4.6)
…iews

Adding TypeID.FILE left the file type falling through switch defaults and
failing unguarded asStructType() calls. Cover the reachable cases:

- StructProjection threw when only some nested fields of a file were projected
- JavaHash fell back to identity hashing instead of hashing nested fields
- Comparators threw instead of comparing nested fields
- IndexByName named list and map file elements with an extra element segment
- SingleValueParser could not read or write a file default
- PartitionData did not reject a file alongside other nested types
- InternalRecordWrapper returned no wrapper for a file
- the Avro read and write path threw on a file column

Add TypeUtil.asStructType so the places that store and read a file as a group
of its nested fields share one struct view.

Generated-by: Cursor (Claude Opus 5)
@github-actions github-actions Bot added the data label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant